[PATCH 1/5] Cygwin: Clarify some code in environ.cc

Corinna Vinschen corinna-cygwin@cygwin.com
Tue Jun 5 09:41:00 GMT 2018


On Jun  4 15:36, Ken Brown wrote:
> ---
>  winsup/cygwin/environ.cc | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc
> index 43225341c..b452d21a5 100644
> --- a/winsup/cygwin/environ.cc
> +++ b/winsup/cygwin/environ.cc
> @@ -545,6 +545,7 @@ _getenv_r (struct _reent *, const char *name)
>    return findenv_func (name, &offset);
>  }
>  
> +/* Return size of environment block, including terminating NULL. */
>  static int __stdcall
>  envsize (const char * const *in_envp)
>  {
> @@ -582,11 +583,16 @@ _addenv (const char *name, const char *value, int overwrite)
>    else
>      {				/* Create new slot. */
>        int sz = envsize (cur_environ ());
> +
> +      /* Allocate space for two new slots even though only one is needed.
> +	 According to the commit message for commit ebd645e
> +	 (2001-10-03), this is done to "work around problems with some
> +	 buggy applications." */
>        int allocsz = sz + (2 * sizeof (char *));

Given the age, I wonder if we shouldn't expect applications to behave
finally.  We could remove this for testing.

>        offset = (sz - 1) / sizeof (char *);
>  
> -      /* Allocate space for additional element plus terminating NULL. */
> +      /* Allocate space for additional element. */
>        if (cur_environ () == lastenviron)
>  	lastenviron = __cygwin_environ = (char **) realloc (cur_environ (),
>  							    allocsz);
> -- 
> 2.17.0

LGTM, otherwise.

Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20180605/3d747a42/attachment.sig>


More information about the Cygwin-patches mailing list