From b441573bdee27c0c90375650f92cc43ee3581af2 Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Sat, 10 Aug 2019 16:13:26 +0300 Subject: [PATCH] Enable #x-1_2_3 syntax and get rid of -0x123 --- c/read.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/c/read.h b/c/read.h index d583172..d366685 100644 --- a/c/read.h +++ b/c/read.h @@ -85,7 +85,6 @@ static int read_digits(char *token, char **out_end, unsigned int radix, int isnumtok_base(char *tok, value_t *pval, int base) { char *end; - int64_t i64; uint64_t ui64; double d; @@ -130,12 +129,14 @@ int isnumtok_base(char *tok, value_t *pval, int base) *pval = mk_double(D_NINF); return 1; } - errno = 0; - i64 = strtoll(tok, &end, base); - if (errno) + if (!read_digits(tok + 1, &end, base, &ui64)) { return 0; + } + if (ui64 >= 0x8000000000000000ULL) { + lerror(ArgError, "Number too negative"); + } if (pval) - *pval = return_from_int64(i64); + *pval = return_from_int64(-(int64_t)ui64); return (*end == '\0'); } if (tok[0] == '_') {