From 9e2925f53990467768cd6e56e9fbbbb6187b9156 Mon Sep 17 00:00:00 2001 From: iff Date: Mon, 28 Aug 2023 19:36:28 +0200 Subject: [PATCH] fix: don't treat 0x prefix as hex identifier --- sway/commands/input/map_from_region.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/sway/commands/input/map_from_region.c b/sway/commands/input/map_from_region.c index de00b7141..4400e111c 100644 --- a/sway/commands/input/map_from_region.c +++ b/sway/commands/input/map_from_region.c @@ -11,11 +11,21 @@ static bool parse_coords(const char *str, double *x, double *y, bool *mm) { *mm = false; char *end; - *x = strtod(str, &end); - if (end[0] != 'x') { - return false; + + // Check for "0x" prefix to avoid strtod treating the string as hex + if (str[0] == '0' && str[1] == 'x') { + if (strlen(str) < 3) { + return false; + } + *x = 0; + end = (char *)str + 2; + } else { + *x = strtod(str, &end); + if (end[0] != 'x') { + return false; + } + ++end; } - ++end; *y = strtod(end, &end); if (end[0] == 'm') {