]> git.proxmox.com Git - wasi-libc.git/commitdiff
Ensure that `environ` is always initialized.
authorDan Gohman <sunfish@mozilla.com>
Tue, 7 May 2019 16:24:10 +0000 (09:24 -0700)
committerDan Gohman <sunfish@mozilla.com>
Tue, 7 May 2019 18:35:48 +0000 (11:35 -0700)
Initialize `environ` even if there are no environment variables, so that
it alwasy points to a NULL-terminated array even if that array just
contains the NULL. This fixes src/functional/env.c.

libc-bottom-half/crt/crt1.c

index 526dd462f3814c3ad2c3ec70505e659e00938420..ab20aab7968d8d2b0ca9a5363d01c44dd8116cc8 100644 (file)
@@ -44,11 +44,6 @@ static __wasi_errno_t populate_environ(void) {
     if (err != __WASI_ESUCCESS) {
         return err;
     }
-    /* If there's no environment pairs, make sure environ is null and return. */
-    if (environ_count == 0) {
-        __environ = NULL;
-        return __WASI_ESUCCESS;
-    }
 
     /* Allocate memory for the array of pointers, plus one terminating null pointer. */
     __environ = malloc(sizeof(char *) * (environ_count + 1));