mirror of
https://github.com/swaywm/sway.git
synced 2024-11-13 05:54:11 +01:00
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().
This commit is contained in:
parent
900d3287f9
commit
b4b274cdce
@ -70,10 +70,11 @@ void update_cursor(struct swaybar_seat *seat) {
|
|||||||
const char *cursor_theme = getenv("XCURSOR_THEME");
|
const char *cursor_theme = getenv("XCURSOR_THEME");
|
||||||
unsigned cursor_size = 24;
|
unsigned cursor_size = 24;
|
||||||
const char *env_cursor_size = getenv("XCURSOR_SIZE");
|
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;
|
char *end;
|
||||||
unsigned size = strtoul(env_cursor_size, &end, 10);
|
unsigned size = strtoul(env_cursor_size, &end, 10);
|
||||||
if (!*end) {
|
if (!*end && errno == 0) {
|
||||||
cursor_size = size;
|
cursor_size = size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,10 +132,11 @@ static void update_cursor(struct swaynag *swaynag) {
|
|||||||
const char *cursor_theme = getenv("XCURSOR_THEME");
|
const char *cursor_theme = getenv("XCURSOR_THEME");
|
||||||
unsigned cursor_size = 24;
|
unsigned cursor_size = 24;
|
||||||
const char *env_cursor_size = getenv("XCURSOR_SIZE");
|
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;
|
char *end;
|
||||||
unsigned size = strtoul(env_cursor_size, &end, 10);
|
unsigned size = strtoul(env_cursor_size, &end, 10);
|
||||||
if (!*end) {
|
if (!*end && errno == 0) {
|
||||||
cursor_size = size;
|
cursor_size = size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user