Skip to content

Commit a8a5dbc

Browse files
authored
Ensure __environ is initialized even when it's empty. (#125)
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.
1 parent afbf94c commit a8a5dbc

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

libc-bottom-half/sources/__environ.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
#include <wasi/libc.h>
55
#include <wasi/libc-internal.h>
66

7-
char **__environ = NULL;
7+
static char *empty_environ[1] = { NULL };
8+
char **__environ = empty_environ;
89
extern __typeof(__environ) _environ __attribute__((weak, alias("__environ")));
910
extern __typeof(__environ) environ __attribute__((weak, alias("__environ")));
1011

0 commit comments

Comments
 (0)