diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-11-15 18:12:16 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-11-15 18:12:16 -0500 |
| commit | 38ea5c4753e13b04e7c41c89bf0b58b5d47cc86d (patch) | |
| tree | 1cb738a8742e975f1f1904529731669610256571 /src/stdlib/bigint.c | |
| parent | af1bd79fd91d1a1efde3cf084643f065c61d330a (diff) | |
Bugfix for int parsing
Diffstat (limited to 'src/stdlib/bigint.c')
| -rw-r--r-- | src/stdlib/bigint.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/stdlib/bigint.c b/src/stdlib/bigint.c index be01a001..46957c2d 100644 --- a/src/stdlib/bigint.c +++ b/src/stdlib/bigint.c @@ -415,25 +415,28 @@ OptionalInt_t Int$parse(Text_t text, Text_t *remainder) { mpz_t i; int result; if (strncmp(str, "0x", 2) == 0) { - const char *end = str + 2 + strspn(str + 2, "0123456789abcdefABCDEF"); + str += 2; + const char *end = str + strspn(str, "0123456789abcdefABCDEF"); if (remainder) *remainder = Text$from_str(end); else if (*end != '\0') return NONE_INT; - result = mpz_init_set_str(i, str + 2, 16); + result = mpz_init_set_str(i, String(string_slice(str, (size_t)(end - str))), 16); } else if (strncmp(str, "0o", 2) == 0) { - const char *end = str + 2 + strspn(str + 2, "01234567"); + str += 2; + const char *end = str + strspn(str, "01234567"); if (remainder) *remainder = Text$from_str(end); else if (*end != '\0') return NONE_INT; - result = mpz_init_set_str(i, str + 2, 8); + result = mpz_init_set_str(i, String(string_slice(str, (size_t)(end - str))), 8); } else if (strncmp(str, "0b", 2) == 0) { - const char *end = str + 2 + strspn(str + 2, "01"); + str += 2; + const char *end = str + strspn(str, "01"); if (remainder) *remainder = Text$from_str(end); else if (*end != '\0') return NONE_INT; - result = mpz_init_set_str(i, str + 2, 2); + result = mpz_init_set_str(i, String(string_slice(str, (size_t)(end - str))), 2); } else { const char *end = str + strspn(str, "0123456789"); if (remainder) *remainder = Text$from_str(end); else if (*end != '\0') return NONE_INT; - result = mpz_init_set_str(i, str, 10); + result = mpz_init_set_str(i, String(string_slice(str, (size_t)(end - str))), 10); } if (result != 0) { if (remainder) *remainder = text; |
