Log empty value if envvar is not defined

If the environment variable is not defined, getenv returns NULL.
Passing a NULL pointer to the "%s" format specifier is undefined
behavior. Even if some implementations output "(null)", an empty
string is nicer.
master
Antonin Décimo 5 years ago committed by Tudor Brindus
parent 2960b2c9b6
commit a1c6052383

@ -138,7 +138,8 @@ static void log_env(void) {
"SWAYSOCK",
};
for (size_t i = 0; i < sizeof(log_vars) / sizeof(char *); ++i) {
sway_log(SWAY_INFO, "%s=%s", log_vars[i], getenv(log_vars[i]));
char *value = getenv(log_vars[i]);
sway_log(SWAY_INFO, "%s=%s", log_vars[i], value != NULL ? value : "");
}
}

Loading…
Cancel
Save