bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/3] maint: simplify parse-gram.y


From: Jim Meyering
Subject: Re: [PATCH 2/3] maint: simplify parse-gram.y
Date: Fri, 04 May 2012 19:07:25 +0200

Akim Demaille wrote:
> Hi Jim!
>
> Thanks for the fixes, please install (in the maint branch
> preferably).  Beware that this patch (2/3) already includes
> a parse-gram.c regen part that should be part of 3/3.  Also:
>
> Le 3 mai 2012 à 23:18, Jim Meyering a écrit :
>
>> diff --git a/src/parse-gram.y b/src/parse-gram.y
>> index 2cf436b..916b70d 100644
>> --- a/src/parse-gram.y
>> +++ b/src/parse-gram.y
>> @@ -783,9 +783,7 @@ add_param (param_type type, char *decl, location loc)
>>         name_len++)
>>      continue;
>>
>> -      name = xmalloc (name_len + 1);
>> -      memcpy (name, name_start, name_len);
>> -      name[name_len] = '\0';
>> +      name = xstrdup (name_start);
>>    if (type & param_lex)
>>      muscle_pair_list_grow ("lex_param", decl, name);
>>    if (type & param_parse)

Oh!  Good catch.  I'll fix it to use this:

    name = xmemdup (name_start, name_len);

> This does not seem right: you no longer take name_len
> into account.  The full context is:
>
>  {
>    char *name;
>    size_t name_len;
>
>    for (name_len = 1;
>         memchr (alphanum, name_start[name_len], sizeof alphanum);
>         name_len++)
>      continue;
>
>    name = xmalloc (name_len + 1);
>    memcpy (name, name_start, name_len);
>    name[name_len] = '\0';
>    muscle_pair_list_grow (type, decl, name);
>    free (name);
>  }
>
> Actually, I don't understand why we don't use strspn instead of
> the for-loop.

Good idea.  That will be much more readable.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]