diff options
author | Phil Jones <philj56@gmail.com> | 2023-04-30 20:08:57 +0100 |
---|---|---|
committer | Phil Jones <philj56@gmail.com> | 2023-04-30 20:08:57 +0100 |
commit | 667075f0920da3c2b353fbce54b6430c195ef031 (patch) | |
tree | 29075728ce1b3662b3cfedce218df4c8b6c29d35 /src/config.c | |
parent | 63f3a9b705066f5929cb3e5d357f5de6aa17a823 (diff) |
Replace `strto[u]l` with `strto[u]ll`.
On 32-bit systems, using `strtoul` was causing negative values for
unsigned options to be treated as valid, as the value was being parsed
as a 32-bit unsigned int, then cast to a 64-bit signed int, which
remained positive.
Diffstat (limited to 'src/config.c')
-rw-r--r-- | src/config.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/config.c b/src/config.c index 2b85028..556199d 100644 --- a/src/config.c +++ b/src/config.c @@ -1027,7 +1027,7 @@ uint32_t parse_uint32(const char *filename, size_t lineno, const char *str, bool { errno = 0; char *endptr; - int64_t ret = strtoul(str, &endptr, 0); + int64_t ret = strtoull(str, &endptr, 0); if (endptr == str || *endptr != '\0') { PARSE_ERROR(filename, lineno, "Failed to parse \"%s\" as unsigned int.\n", str); if (err) { @@ -1046,7 +1046,7 @@ int32_t parse_int32(const char *filename, size_t lineno, const char *str, bool * { errno = 0; char *endptr; - int64_t ret = strtol(str, &endptr, 0); + int64_t ret = strtoll(str, &endptr, 0); if (endptr == str || *endptr != '\0') { PARSE_ERROR(filename, lineno, "Failed to parse \"%s\" as int.\n", str); if (err) { @@ -1065,7 +1065,7 @@ struct uint32_percent parse_uint32_percent(const char *filename, size_t lineno, { errno = 0; char *endptr; - int64_t val = strtoul(str, &endptr, 0); + int64_t val = strtoull(str, &endptr, 0); bool percent = false; if (endptr == str || (*endptr != '\0' && *endptr != '%')) { PARSE_ERROR(filename, lineno, "Failed to parse \"%s\" as unsigned int.\n", str); |