aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Daniel Eklöf <daniel@ekloef.se>2019-06-05 18:26:12 +0200
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-06-05 14:40:29 -0400
commitb4b274cdcea5269fc39ef9c846157d211f79eec9 (patch)
treebc58e4b6615053bdabececbb959b595d011e520d
parentswaybar/nag: use xcursor theme defined by XCURSOR_THEME/SIZE (diff)
downloadsway-b4b274cdcea5269fc39ef9c846157d211f79eec9.tar.gz
sway-b4b274cdcea5269fc39ef9c846157d211f79eec9.tar.zst
sway-b4b274cdcea5269fc39ef9c846157d211f79eec9.zip
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.c5
-rw-r--r--swaynag/swaynag.c5
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) {
70 const char *cursor_theme = getenv("XCURSOR_THEME"); 70 const char *cursor_theme = getenv("XCURSOR_THEME");
71 unsigned cursor_size = 24; 71 unsigned cursor_size = 24;
72 const char *env_cursor_size = getenv("XCURSOR_SIZE"); 72 const char *env_cursor_size = getenv("XCURSOR_SIZE");
73 if (env_cursor_size) { 73 if (env_cursor_size && strlen(env_cursor_size) > 0) {
74 errno = 0;
74 char *end; 75 char *end;
75 unsigned size = strtoul(env_cursor_size, &end, 10); 76 unsigned size = strtoul(env_cursor_size, &end, 10);
76 if (!*end) { 77 if (!*end && errno == 0) {
77 cursor_size = size; 78 cursor_size = size;
78 } 79 }
79 } 80 }
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) {
132 const char *cursor_theme = getenv("XCURSOR_THEME"); 132 const char *cursor_theme = getenv("XCURSOR_THEME");
133 unsigned cursor_size = 24; 133 unsigned cursor_size = 24;
134 const char *env_cursor_size = getenv("XCURSOR_SIZE"); 134 const char *env_cursor_size = getenv("XCURSOR_SIZE");
135 if (env_cursor_size) { 135 if (env_cursor_size && strlen(env_cursor_size) > 0) {
136 errno = 0;
136 char *end; 137 char *end;
137 unsigned size = strtoul(env_cursor_size, &end, 10); 138 unsigned size = strtoul(env_cursor_size, &end, 10);
138 if (!*end) { 139 if (!*end && errno == 0) {
139 cursor_size = size; 140 cursor_size = size;
140 } 141 }
141 } 142 }