From: "Ondřej Bílka" <neleai@seznam.cz>
To: libc-alpha@sourceware.org
Subject: Re: [PING][BZ #15894][PATCH] Deduplicate setenv.c
Date: Wed, 30 Oct 2013 15:33:00 -0000 [thread overview]
Message-ID: <20131030153342.GA16867@domone.podge> (raw)
In-Reply-To: <20131023131726.GB6107@domone.podge>
ping
On Wed, Oct 23, 2013 at 03:17:26PM +0200, OndÅej BÃlka wrote:
> ping
> On Tue, Oct 15, 2013 at 11:34:50AM +0200, OndÅej BÃlka wrote:
> > Hi,
> >
> > In setenv.c file a logic of adding element is needlessly duplicated
> > based on if we extend __environ or not. This can be easily fixed in
> > following way:
> >
> > * stdlib/setenv.c: Remove duplicate code.
> >
> > diff --git a/stdlib/setenv.c b/stdlib/setenv.c
> > index 63c995b..e4b5b5e 100644
> > --- a/stdlib/setenv.c
> > +++ b/stdlib/setenv.c
> > @@ -146,82 +146,13 @@ __add_to_environ (name, value, combined, replace)
> > UNLOCK;
> > return -1;
> > }
> > -
> > - /* If the whole entry is given add it. */
> > - if (combined != NULL)
> > - /* We must not add the string to the search tree since it belongs
> > - to the user. */
> > - new_environ[size] = (char *) combined;
> > - else
> > - {
> > - /* See whether the value is already known. */
> > -#ifdef USE_TSEARCH
> > - char *new_value;
> > - int use_alloca = __libc_use_alloca (varlen);
> > - if (__builtin_expect (use_alloca, 1))
> > - new_value = (char *) alloca (varlen);
> > - else
> > - {
> > - new_value = malloc (varlen);
> > - if (new_value == NULL)
> > - {
> > - UNLOCK;
> > - if (last_environ == NULL)
> > - free (new_environ);
> > - return -1;
> > - }
> > - }
> > -# ifdef _LIBC
> > - __mempcpy (__mempcpy (__mempcpy (new_value, name, namelen), "=", 1),
> > - value, vallen);
> > -# else
> > - memcpy (new_value, name, namelen);
> > - new_value[namelen] = '=';
> > - memcpy (&new_value[namelen + 1], value, vallen);
> > -# endif
> > -
> > - new_environ[size] = KNOWN_VALUE (new_value);
> > - if (__builtin_expect (new_environ[size] == NULL, 1))
> > -#endif
> > - {
> > -#ifdef USE_TSEARCH
> > - if (__builtin_expect (! use_alloca, 0))
> > - new_environ[size] = new_value;
> > - else
> > -#endif
> > - {
> > - new_environ[size] = (char *) malloc (varlen);
> > - if (__builtin_expect (new_environ[size] == NULL, 0))
> > - {
> > - UNLOCK;
> > - return -1;
> > - }
> > -
> > -#ifdef USE_TSEARCH
> > - memcpy (new_environ[size], new_value, varlen);
> > -#else
> > - memcpy (new_environ[size], name, namelen);
> > - new_environ[size][namelen] = '=';
> > - memcpy (&new_environ[size][namelen + 1], value, vallen);
> > -#endif
> > - }
> > -
> > - /* And save the value now. We cannot do this when we remove
> > - the string since then we cannot decide whether it is a
> > - user string or not. */
> > - STORE_VALUE (new_environ[size]);
> > - }
> > - }
> > -
> > - if (__environ != last_environ)
> > - memcpy ((char *) new_environ, (char *) __environ,
> > - size * sizeof (char *));
> > -
> > + new_environ[size] = NULL;
> > new_environ[size + 1] = NULL;
> > + ep = new_environ + size;
> >
> > last_environ = __environ = new_environ;
> > }
> > - else if (replace)
> > + if (*ep == NULL || replace)
> > {
> > char *np;
> >
>
> --
>
> pseudo-user on a pseudo-terminal
--
operators on strike due to broken coffee machine
next prev parent reply other threads:[~2013-10-30 15:33 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-15 9:34 [PATCH] " Ondřej Bílka
2013-10-15 12:22 ` [PATCH 2a][BZ #15607] Make setenv thread safe Ondřej Bílka
2013-11-09 9:31 ` Ondřej Bílka
2015-07-11 21:47 ` [PING][PATCH " Ondřej Bílka
2013-10-18 14:47 ` [PATCH] Deduplicate setenv.c Ondřej Bílka
2013-10-23 13:17 ` [PING][BZ #15894][PATCH] " Ondřej Bílka
2013-10-30 15:33 ` Ondřej Bílka [this message]
2013-11-05 14:26 ` [PING^3][BZ " Ondřej Bílka
2013-11-27 13:34 ` [PING^4][BZ " Ondřej Bílka
2013-12-04 11:57 ` [PING^5][BZ " Ondřej Bílka
2014-02-08 0:23 ` [PING^6][BZ " Ondřej Bílka
2014-02-08 14:52 ` Mike Frysinger
2014-02-10 12:59 ` Ondřej Bílka
2014-02-11 10:38 ` Siddhesh Poyarekar
2014-02-11 11:46 ` Ondřej Bílka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20131030153342.GA16867@domone.podge \
--to=neleai@seznam.cz \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).