aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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]=='=') {