| 1 | This patch is from upstream and shouldn't be needed in the next release.
|
| 2 | https://github.com/philj56/tofi/commit/667075f0920da3c2b353fbce54b6430c195ef031.patch
|
| 3 |
|
| 4 | From 667075f0920da3c2b353fbce54b6430c195ef031 Mon Sep 17 00:00:00 2001
|
| 5 | From: Phil Jones <[email protected]>
|
| 6 | Date: Sun, 30 Apr 2023 20:08:57 +0100
|
| 7 | Subject: [PATCH] Replace `strto[u]l` with `strto[u]ll`.
|
| 8 |
|
| 9 | On 32-bit systems, using `strtoul` was causing negative values for
|
| 10 | unsigned options to be treated as valid, as the value was being parsed
|
| 11 | as a 32-bit unsigned int, then cast to a 64-bit signed int, which
|
| 12 | remained positive.
|
| 13 | ---
|
| 14 | src/color.c | 8 ++++----
|
| 15 | src/config.c | 6 +++---
|
| 16 | 2 files changed, 7 insertions(+), 7 deletions(-)
|
| 17 |
|
| 18 | diff --git a/src/color.c b/src/color.c
|
| 19 | index 4b6b356..b1d5e90 100644
|
| 20 | |
| 21 | |
| 22 | @@ -22,7 +22,7 @@ struct color hex_to_color(const char *hex)
|
| 23 | hex[2], hex[2],
|
| 24 | '\0'};
|
| 25 | char *endptr;
|
| 26 | - tmp = strtol(str, &endptr, 16);
|
| 27 | + tmp = strtoll(str, &endptr, 16);
|
| 28 | if (errno || *endptr != '\0' || tmp < 0) {
|
| 29 | return (struct color) { -1, -1, -1, -1 };
|
| 30 | }
|
| 31 | @@ -37,14 +37,14 @@ struct color hex_to_color(const char *hex)
|
| 32 | hex[3], hex[3],
|
| 33 | '\0'};
|
| 34 | char *endptr;
|
| 35 | - tmp = strtol(str, &endptr, 16);
|
| 36 | + tmp = strtoll(str, &endptr, 16);
|
| 37 | if (errno || *endptr != '\0' || tmp < 0) {
|
| 38 | return (struct color) { -1, -1, -1, -1 };
|
| 39 | }
|
| 40 | val = tmp;
|
| 41 | } else if (len == 6) {
|
| 42 | char *endptr;
|
| 43 | - tmp = strtol(hex, &endptr, 16);
|
| 44 | + tmp = strtoll(hex, &endptr, 16);
|
| 45 | if (errno || *endptr != '\0' || tmp < 0) {
|
| 46 | return (struct color) { -1, -1, -1, -1 };
|
| 47 | }
|
| 48 | @@ -53,7 +53,7 @@ struct color hex_to_color(const char *hex)
|
| 49 | val |= 0xFFu;
|
| 50 | } else if (len == 8) {
|
| 51 | char *endptr;
|
| 52 | - tmp = strtol(hex, &endptr, 16);
|
| 53 | + tmp = strtoll(hex, &endptr, 16);
|
| 54 | if (errno || *endptr != '\0' || tmp < 0) {
|
| 55 | return (struct color) { -1, -1, -1, -1 };
|
| 56 | }
|
| 57 | diff --git a/src/config.c b/src/config.c
|
| 58 | index 2b85028..556199d 100644
|
| 59 | |
| 60 | |
| 61 | @@ -1027,7 +1027,7 @@ uint32_t parse_uint32(const char *filename, size_t lineno, const char *str, bool
|
| 62 | {
|
| 63 | errno = 0;
|
| 64 | char *endptr;
|
| 65 | - int64_t ret = strtoul(str, &endptr, 0);
|
| 66 | + int64_t ret = strtoull(str, &endptr, 0);
|
| 67 | if (endptr == str || *endptr != '\0') {
|
| 68 | PARSE_ERROR(filename, lineno, "Failed to parse \"%s\" as unsigned int.\n", str);
|
| 69 | if (err) {
|
| 70 | @@ -1046,7 +1046,7 @@ int32_t parse_int32(const char *filename, size_t lineno, const char *str, bool *
|
| 71 | {
|
| 72 | errno = 0;
|
| 73 | char *endptr;
|
| 74 | - int64_t ret = strtol(str, &endptr, 0);
|
| 75 | + int64_t ret = strtoll(str, &endptr, 0);
|
| 76 | if (endptr == str || *endptr != '\0') {
|
| 77 | PARSE_ERROR(filename, lineno, "Failed to parse \"%s\" as int.\n", str);
|
| 78 | if (err) {
|
| 79 | @@ -1065,7 +1065,7 @@ struct uint32_percent parse_uint32_percent(const char *filename, size_t lineno,
|
| 80 | {
|
| 81 | errno = 0;
|
| 82 | char *endptr;
|
| 83 | - int64_t val = strtoul(str, &endptr, 0);
|
| 84 | + int64_t val = strtoull(str, &endptr, 0);
|
| 85 | bool percent = false;
|
| 86 | if (endptr == str || (*endptr != '\0' && *endptr != '%')) {
|
| 87 | PARSE_ERROR(filename, lineno, "Failed to parse \"%s\" as unsigned int.\n", str);
|