diff options
author | Elliott Hughes <enh@google.com> | 2019-05-03 16:21:50 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-05-03 16:21:50 -0700 |
commit | f061551c0e5f75722aebc48c6f2150d093393ccb (patch) | |
tree | 8501523c695f7863026bd9aeeb11e2472b6e5234 | |
parent | acb89d02cf974903e29196b473b9e277570f7318 (diff) | |
parent | 2b9578256a77da725906b04227c1bf30cd2765e7 (diff) | |
download | toybox-temp_b_131756210_stage-aosp-master.tar.gz |
Merge remote-tracking branch 'toybox/master' into HEADtemp_b_131756210_stage-aosp-master
am: 2b9578256a
Change-Id: I8c078e29c7be69545e467a8a2b49a851222b66be
-rw-r--r-- | lib/env.c | 7 | ||||
-rwxr-xr-x | tests/env.test | 2 |
2 files changed, 5 insertions, 4 deletions
@@ -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,17 +53,15 @@ 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]=='=') { if (i>=envc) free(environ[i]); else { - char **delete = environ+i; - // move old entries down, add at end of old data toys.envc = envc--; - for (i=0; new ? i<envc : !!delete[i]; i++) delete[i] = delete[i+1]; + for (; new ? i<envc : !!environ[i]; i++) environ[i] = environ[i+1]; i = envc; } break; diff --git a/tests/env.test b/tests/env.test index 3098731d..4df118dd 100755 --- a/tests/env.test +++ b/tests/env.test @@ -19,3 +19,5 @@ unset WALRUS BANANA LETTERS FILTER testcmd "early fail" '--oops 2> /dev/null ; echo $?' "125\n" "" "" testcmd "why is this allowed" "=BLAH env | grep '^=BLAH\$'" "=BLAH\n" "" "" + +testcmd "replace" "A=foo PATH= `which printenv` A" "foo\n" "" "" |