Skip to content

Commit ec314c9

Browse files
committed
unix/modos: getenv(): Handle non-existing envvar correctly.
1 parent 16d4236 commit ec314c9

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

unix/modos.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_os_system_obj, mod_os_system);
137137

138138
STATIC mp_obj_t mod_os_getenv(mp_obj_t var_in) {
139139
const char *s = getenv(mp_obj_str_get_str(var_in));
140+
if (s == NULL) {
141+
return mp_const_none;
142+
}
140143
return mp_obj_new_str(s, strlen(s), false);
141144
}
142145
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_os_getenv_obj, mod_os_getenv);

0 commit comments

Comments
 (0)