On Fri, Sep 18, 2026 at 4:34 PM Tim Murphy <[email protected]> wrote: > > Re build problem with discarding const in tilde_expand(): > > I worked out that removing const upwards is not needed - the behaviour can be > amended. Perhaps alloca would be offer more performance than this but I'm > really just trying to move on. This just uses xstrdup to copy the string > that is being modified for the sake of it being convenient for parsing; > > diff --git a/src/read.c b/src/read.c > index 75e37743..ff125d32 100644 > --- a/src/read.c > +++ b/src/read.c > @@ -3065,20 +3065,31 @@ tilde_expand (const char *name) > else > { > struct passwd *pwent; > - char *userend = strchr (name + 1, '/'); > + char *namecopy = xstrdup(name); > + char *userend = strchr (namecopy + 1, '/'); > + > if (userend != 0) > *userend = '\0'; > - pwent = getpwnam (name + 1); > + pwent = getpwnam (namecopy + 1); > if (pwent != 0) > { > + char *result = 0; > if (userend == 0) > - return xstrdup (pwent->pw_dir); > - > - *userend = '/'; > - return xstrdup (concat (3, pwent->pw_dir, "/", userend + 1)); > + { > + result = xstrdup (pwent->pw_dir); > + } > + else > + { > + *userend = '/'; > + result = xstrdup (concat (3, pwent->pw_dir, "/", userend + 1)); > + } > + free(namecopy); > + return result; > } > else if (userend != 0) > *userend = '/'; > + > + free(namecopy); > } > # endif /* !MK_OS_W32 */ > #endif /* !MK_OS_VMS */
alloca would make the diff smaller and it is used everywhere in make. regards, Dmitry
