On Wed, Oct 14, 2009 at 3:58 AM, Stuart Henderson <[email protected]> wrote:
>  setup_builtin(const char *name, unsigned int type)
>  {
>        ndptr n;
> +       char *name2;
>
> -       n = create_entry(name);
> +       if(prefix_builtins) {
> +               name2 = xalloc(strlen(name)+3+1, NULL);
> +               memcpy(name2, "m4_", 3);
> +               memcpy(name2 + 3, name, strlen(name)+1);
> +       } else
> +               name2 = (char *)name;
> +
> +       n = create_entry(name2);
>        n->builtin_type = type;
>        n->d = xalloc(sizeof(struct macro_definition), NULL);
> -       n->d->defn = xstrdup(name);
> +       n->d->defn = xstrdup(name2);
>        n->d->type = type;
>        n->d->next = NULL;
>  }

Doesn't this leak memory in the -P case?  What about moving the
xstrdup() call into only the !prefix_builtins path?  Then you can also
eliminate the const cast:

    if (prefix_builtins) {
        ...
    }
    else
        name2 = xstrdup(name);

    ...
    n->d->defn = name2;
    ...

Reply via email to