1
1
mirror of https://github.com/swaywm/sway synced 2024-11-23 13:22:17 +01:00

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.
This commit is contained in:
Antonin Décimo 2020-06-04 14:41:22 +02:00 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 : "");
}
}