[Top][All Lists]

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

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

From: Akim Demaille
Subject: Re: [PATCH 2/3] maint: simplify parse-gram.y
Date: Sun, 6 May 2012 08:58:00 +0200

Hi Jim!

This is perfect, push whenever you want.

Le 5 mai 2012 à 15:26, Jim Meyering a écrit :

> +      size_t name_len = strspn (name_start, alphanum);
> +      char *name = xmemdup (name_start, name_len + 1);
>       name[name_len] = '\0';

For my education, you prefer memdup to strndup because of
of the inner strnlen of the latter, right?  It makes plenty
of sense, but this split memdup + '=0' is not nice looking.
It would be cleaner to have say xmemdup0 which would add
this 0.

Actually, I just grepped xmemdup in gnulib to see if there
are many such memdup + '=0', and here is what I found:

char *
xmemdup0 (void const *p, size_t s)
  char *result = xcharalloc (s + 1);
  memcpy (result, p, s);
  result[s] = 0;
  return result;

:)  So please, make it

      char *name = xmemdup0 (name_start, strspn (name_start, alphanum));
      muscle_pair_list_grow (type, decl, name);
      free (name);

(I think this is the last time I will bug you with this patch :)
but looking at the surrounding code, I see that we do not support
\n in %parse-param, which is not nice, I will make another patch
on top of yours).

reply via email to

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