diff options
| author | Furkan Sahin <furkan-dev@proton.me> | 2019-06-05 18:26:12 +0200 |
|---|---|---|
| committer | Furkan Sahin <furkan-dev@proton.me> | 2019-06-05 18:26:12 +0200 |
| commit | 96c9854720ed4c76492df781c60748f815840221 (patch) | |
| tree | bc58e4b6615053bdabececbb959b595d011e520d | |
| parent | 715aec13ecc1f649f1c08f483c6e66cb7db130c2 (diff) | |
check for empty string before calling strtoul() and check errno
Note: since strtoul() has no real error return code (both 0 and
ULONG_MAX may be returned on both success and failure), set errno=0
before calling strtoul().
| -rw-r--r-- | swaybar/input.c | 5 | ||||
| -rw-r--r-- | swaynag/swaynag.c | 5 |
2 files changed, 6 insertions, 4 deletions
diff --git a/swaybar/input.c b/swaybar/input.c index 8a83f38f..8b83eab4 100644 --- a/swaybar/input.c +++ b/swaybar/input.c @@ -70,10 +70,11 @@ void update_cursor(struct swaybar_seat *seat) { const char *cursor_theme = getenv("XCURSOR_THEME"); unsigned cursor_size = 24; const char *env_cursor_size = getenv("XCURSOR_SIZE"); - if (env_cursor_size) { + if (env_cursor_size && strlen(env_cursor_size) > 0) { + errno = 0; char *end; unsigned size = strtoul(env_cursor_size, &end, 10); - if (!*end) { + if (!*end && errno == 0) { cursor_size = size; } } diff --git a/swaynag/swaynag.c b/swaynag/swaynag.c index 87199a74..caa10ccd 100644 --- a/swaynag/swaynag.c +++ b/swaynag/swaynag.c @@ -132,10 +132,11 @@ static void update_cursor(struct swaynag *swaynag) { const char *cursor_theme = getenv("XCURSOR_THEME"); unsigned cursor_size = 24; const char *env_cursor_size = getenv("XCURSOR_SIZE"); - if (env_cursor_size) { + if (env_cursor_size && strlen(env_cursor_size) > 0) { + errno = 0; char *end; unsigned size = strtoul(env_cursor_size, &end, 10); - if (!*end) { + if (!*end && errno == 0) { cursor_size = size; } } |
