aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2019-05-03 11:45:43 -0500
committerRob Landley <rob@landley.net>2019-05-03 11:45:43 -0500
commit121322285aa143a748fb7c725a5e2559a038eefd (patch)
tree9f9d777553da48b3c45a25054f6997b1f92c635a
parentbd7c5c0555477d562bc7a4dab9561017a47b615e (diff)
downloadtoybox-121322285aa143a748fb7c725a5e2559a038eefd.tar.gz
Add a couple comments.
-rw-r--r--lib/env.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/env.c b/lib/env.c
index bc23b753..3e05f4e4 100644
--- a/lib/env.c
+++ b/lib/env.c
@@ -36,6 +36,7 @@ void xsetenv(char *name, char *val)
// If we haven't snapshot initial environment state yet, do so now.
if (!toys.envc) {
+ // envc is size +1 so even if env empty it's nonzero after initialization
while (environ[toys.envc++]);
memcpy(new = xmalloc(((toys.envc|0xff)+1)*sizeof(char *)),
environ, toys.envc*sizeof(char *));
@@ -52,7 +53,7 @@ void xsetenv(char *name, char *val)
if (val) new = xmprintf("%s=%s", name, val);
}
- envc = toys.envc-1;
+ envc = toys.envc-1; // compensate for size +1 above
for (i = 0; environ[i]; i++) {
// Drop old entry, freeing as appropriate. Assumes no duplicates.
if (!memcmp(name, environ[i], len) && environ[i][len]=='=') {