mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-20 09:43:03 +00:00
(add_param): Fix bug where NUL was mishandled.
Avoid the use of strchr to avoid future recurrences.
This commit is contained in:
@@ -472,29 +472,27 @@ lloc_default (YYLTYPE const *rhs, int n)
|
|||||||
static void
|
static void
|
||||||
add_param (char const *type, char *decl, location loc)
|
add_param (char const *type, char *decl, location loc)
|
||||||
{
|
{
|
||||||
static char const alphanum[] =
|
static char const alphanum[26 + 26 + 1 + 10] =
|
||||||
"0123456789"
|
|
||||||
"abcdefghijklmnopqrstuvwxyz"
|
"abcdefghijklmnopqrstuvwxyz"
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
"_";
|
"_"
|
||||||
static char const blank[] = " \t";
|
"0123456789";
|
||||||
char const *alpha = alphanum + 10;
|
|
||||||
char const *name_start = NULL;
|
char const *name_start = NULL;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
for (p = decl; *p; p++)
|
for (p = decl; *p; p++)
|
||||||
if ((p == decl || ! strchr (alphanum, p[-1])) && strchr (alpha, p[0]))
|
if ((p == decl
|
||||||
|
|| ! memchr (alphanum, p[-1], sizeof alphanum))
|
||||||
|
&& memchr (alphanum, p[0], sizeof alphanum - 10))
|
||||||
name_start = p;
|
name_start = p;
|
||||||
|
|
||||||
/* Strip the surrounding '{' and '}'. */
|
/* Strip the surrounding '{' and '}', and any blanks just inside
|
||||||
decl++;
|
the braces. */
|
||||||
*--p = '\0';
|
while (*--p == ' ' || *p == '\t')
|
||||||
|
continue;
|
||||||
/* Strip surrounding white spaces. */
|
*p = '\0';
|
||||||
while (strchr (blank, *decl))
|
while (*++decl == ' ' || *decl == '\t')
|
||||||
++decl;
|
continue;
|
||||||
while (strchr (blank, p[-1]))
|
|
||||||
*--p = '\0';
|
|
||||||
|
|
||||||
if (! name_start)
|
if (! name_start)
|
||||||
complain_at (loc, _("missing identifier in parameter declaration"));
|
complain_at (loc, _("missing identifier in parameter declaration"));
|
||||||
@@ -504,7 +502,7 @@ add_param (char const *type, char *decl, location loc)
|
|||||||
size_t name_len;
|
size_t name_len;
|
||||||
|
|
||||||
for (name_len = 1;
|
for (name_len = 1;
|
||||||
name_start[name_len] && strchr (alphanum, name_start[name_len]);
|
memchr (alphanum, name_start[name_len], sizeof alphanum);
|
||||||
name_len++)
|
name_len++)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user