From a1c6052383d382d978ca597dc5fb280c0343db60 Mon Sep 17 00:00:00 2001 From: Antonin Décimo Date: Thu, 4 Jun 2020 14:41:22 +0200 Subject: 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. --- sway/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sway/main.c b/sway/main.c index d893654f..57716071 100644 --- a/sway/main.c +++ b/sway/main.c @@ -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 : ""); } } -- cgit v1.2.3-54-g00ecf