aboutsummaryrefslogtreecommitdiffstats
path: root/sway/main.c
diff options
context:
space:
mode:
authorLibravatar Antonin Décimo <antonin.decimo@gmail.com>2020-06-04 14:41:22 +0200
committerLibravatar Tudor Brindus <me@tbrindus.ca>2020-07-30 22:02:42 -0400
commita1c6052383d382d978ca597dc5fb280c0343db60 (patch)
treece81e5b63303a0c141cbcd4b96a82fc8e06331bf /sway/main.c
parentcmd/bar/colors: fix dereference of null pointer (diff)
downloadsway-a1c6052383d382d978ca597dc5fb280c0343db60.tar.gz
sway-a1c6052383d382d978ca597dc5fb280c0343db60.tar.zst
sway-a1c6052383d382d978ca597dc5fb280c0343db60.zip
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.
Diffstat (limited to 'sway/main.c')
-rw-r--r--sway/main.c3
1 files changed, 2 insertions, 1 deletions
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) {
138 "SWAYSOCK", 138 "SWAYSOCK",
139 }; 139 };
140 for (size_t i = 0; i < sizeof(log_vars) / sizeof(char *); ++i) { 140 for (size_t i = 0; i < sizeof(log_vars) / sizeof(char *); ++i) {
141 sway_log(SWAY_INFO, "%s=%s", log_vars[i], getenv(log_vars[i])); 141 char *value = getenv(log_vars[i]);
142 sway_log(SWAY_INFO, "%s=%s", log_vars[i], value != NULL ? value : "");
142 } 143 }
143} 144}
144 145