From 121322285aa143a748fb7c725a5e2559a038eefd Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 3 May 2019 11:45:43 -0500 Subject: Add a couple comments. --- lib/env.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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]=='=') { -- cgit v1.2.3