aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/bison/src/uniqstr.c
diff options
context:
space:
mode:
authorthegeorg <thegeorg@yandex-team.com>2024-06-29 11:45:54 +0300
committerthegeorg <thegeorg@yandex-team.com>2024-06-29 11:54:41 +0300
commit9158d9115725ca7f4ada745ec55eddd5747bc61e (patch)
treef262cd6d7a98bb367943a4918b6963a7800f3937 /contrib/tools/bison/src/uniqstr.c
parent632b3cedb8e12fbbb0bcd1bdbf7ec5686725b7e9 (diff)
downloadydb-9158d9115725ca7f4ada745ec55eddd5747bc61e.tar.gz
Update contrib/tools/bison to 3.2.4
78e59a97f3fde03511ddb9969cd1daabbaf998bd
Diffstat (limited to 'contrib/tools/bison/src/uniqstr.c')
-rw-r--r--contrib/tools/bison/src/uniqstr.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/contrib/tools/bison/src/uniqstr.c b/contrib/tools/bison/src/uniqstr.c
index bfe1d17218..b4f6e9463d 100644
--- a/contrib/tools/bison/src/uniqstr.c
+++ b/contrib/tools/bison/src/uniqstr.c
@@ -56,19 +56,36 @@ uniqstr_new (char const *str)
}
uniqstr
-uniqstr_vsprintf (char const *format, ...)
+uniqstr_concat (int nargs, ...)
{
va_list args;
- size_t length;
- va_start (args, format);
- length = vsnprintf (NULL, 0, format, args);
+
+ va_start (args, nargs);
+ size_t reslen = 0;
+ for (int i = 0; i < nargs; i++)
+ reslen += strlen (va_arg (args, char const *));
va_end (args);
- char res[length + 1];
- va_start (args, format);
- vsprintf (res, format, args);
+ char *str = xmalloc (reslen + 1);
+ char *p = str;
+
+ va_start (args, nargs);
+ for (int i = 0; i < nargs; i++)
+ {
+ char const *arg = va_arg (args, char const *);
+ size_t arglen = strlen (arg);
+ memcpy (p, arg, arglen);
+ p += arglen;
+ }
va_end (args);
- return uniqstr_new (res);
+
+ *p = '\0';
+ uniqstr res = hash_insert (uniqstrs_table, str);
+ if (!res)
+ xalloc_die ();
+ if (res != str)
+ free (str);
+ return res;
}
/*------------------------------.