]> git.proxmox.com Git - wasi-libc.git/commitdiff
Ensure `__environ` is initialized even when it's empty. (#125)
authorDan Gohman <sunfish@mozilla.com>
Mon, 28 Oct 2019 17:34:57 +0000 (10:34 -0700)
committerGitHub <noreply@github.com>
Mon, 28 Oct 2019 17:34:57 +0000 (10:34 -0700)
POSIX requires `environ` to be a pointer to a NULL-terminated array of
pointers, so it itself can't be NULL.

This fixes a regression in src/functional/env.c in wasi-libc-test.

libc-bottom-half/sources/__environ.c

index beaa88dbb115e824aba16153b86c284326e91ef2..3e14ace003d54b23121b89bc0a51c8dae0a0e9bb 100644 (file)
@@ -4,7 +4,8 @@
 #include <wasi/libc.h>
 #include <wasi/libc-internal.h>
 
-char **__environ = NULL;
+static char *empty_environ[1] = { NULL };
+char **__environ = empty_environ;
 extern __typeof(__environ) _environ __attribute__((weak, alias("__environ")));
 extern __typeof(__environ) environ __attribute__((weak, alias("__environ")));