aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPranjal Kole <pranjal.kole7@gmail.com>2022-01-29 12:01:00 +0000
committerPranjal Kole <pranjal.kole7@gmail.com>2022-01-29 12:22:06 +0000
commitd9cd1749e0027dcb0f8e6bb755f69b99a1318e85 (patch)
tree672ccd07b3573fcad20dd91b2b8ca8c3e582fbd0
parentwayland: use getenv() according to spec (diff)
wayland: use strtol() to parse xcursor_size
sscanf is not very robust. For example, $ XCURSOR_SIZE="36asdf" foot works without any errors, and xcursor_size is parsed as 36.
-rw-r--r--wayland.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/wayland.c b/wayland.c
index e9f7d063..725841e2 100644
--- a/wayland.c
+++ b/wayland.c
@@ -1635,15 +1635,21 @@ wayl_reload_xcursor_theme(struct seat *seat, int new_scale)
{
const char *env_cursor_size = getenv("XCURSOR_SIZE");
if (env_cursor_size != NULL) {
- unsigned size;
- if (sscanf(env_cursor_size, "%u", &size) == 1)
+ errno = 0;
+ char *end;
+ int size = (int)strtol(env_cursor_size, &end, 10);
+
+ if (errno == 0 && *end == '\0' && size > 0)
xcursor_size = size;
+ else
+ LOG_WARN("XCURSOR_SIZE '%s' is invalid, defaulting to 24",
+ env_cursor_size);
}
}
const char *xcursor_theme = getenv("XCURSOR_THEME");
- LOG_INFO("cursor theme: %s, size: %u, scale: %d",
+ LOG_INFO("cursor theme: %s, size: %d, scale: %d",
xcursor_theme, xcursor_size, new_scale);
seat->pointer.theme = wl_cursor_theme_load(