From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 99664 invoked by alias); 7 Jun 2018 08:03:03 -0000 Mailing-List: contact cygwin-cvs-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cygwin-cvs-owner@cygwin.com Received: (qmail 99567 invoked by uid 9078); 7 Jun 2018 08:03:02 -0000 Date: Thu, 07 Jun 2018 08:03:00 -0000 Message-ID: <20180607080302.99565.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: Clarify some code in environ.cc X-Act-Checkin: newlib-cygwin X-Git-Author: Ken Brown X-Git-Refname: refs/heads/master X-Git-Oldrev: a7c23d109f2e7d7fed5e1453b47ad6b384a726aa X-Git-Newrev: 1ecbb8d7b796b980db120d81f625d206c6a728da X-SW-Source: 2018-q2/txt/msg00015.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=1ecbb8d7b796b980db120d81f625d206c6a728da commit 1ecbb8d7b796b980db120d81f625d206c6a728da Author: Ken Brown Date: Wed Jun 6 11:45:54 2018 -0400 Cygwin: Clarify some code in environ.cc Diff: --- 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 4322534..b452d21 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 *)); 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);