diff options
author | Steve Bennett <steveb@workware.net.au> | 2012-09-05 11:01:54 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2012-09-06 07:23:32 +1000 |
commit | 49036996bce7bc28c695455caa5cef84932e7ac4 (patch) | |
tree | 35bcce70a319e3f8aeec85f816b83fe92c85e34e | |
parent | a52d1cc85cf79df744819ff7247d33739c1af0a9 (diff) | |
download | jimtcl-49036996bce7bc28c695455caa5cef84932e7ac4.zip jimtcl-49036996bce7bc28c695455caa5cef84932e7ac4.tar.gz jimtcl-49036996bce7bc28c695455caa5cef84932e7ac4.tar.bz2 |
Fix conversion of numbers >= 2^31
A conversion was being stored in a long rather than a long long
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r-- | jim.c | 4 | ||||
-rw-r--r-- | tests/format.test | 3 |
2 files changed, 5 insertions, 2 deletions
@@ -510,7 +510,7 @@ static long jim_strtol(const char *str, char **endptr) /* Converts a number as per strtoull(..., 0) except leading zeros do *not* * imply octal. Instead, decimal is assumed unless the number begins with 0x, 0o or 0b */ -static unsigned long long jim_strtoull(const char *str, char **endptr) +static jim_wide jim_strtoull(const char *str, char **endptr) { #ifdef HAVE_LONG_LONG int sign; @@ -518,7 +518,7 @@ static unsigned long long jim_strtoull(const char *str, char **endptr) int i = JimNumberBase(str, &base, &sign); if (base != 10) { - long value = strtoull(str + i, endptr, base); + jim_wide value = strtoull(str + i, endptr, base); if (endptr == NULL || *endptr != str + i) { return value * sign; } diff --git a/tests/format.test b/tests/format.test index 28509ca..bb45235 100644 --- a/tests/format.test +++ b/tests/format.test @@ -67,6 +67,9 @@ test format-1.10 {integer formatting} { test format-1.11 {integer formatting} { format "%-#20o %#-20o %#-20o %#-20o" 6 34 16923 -12 -1 } {06 042 041033 01777777777777777777764} +test format-1.12 {no sign extend large 32 bit values} { + format %x 0xa0000000 +} {a0000000} test format-2.1 {string formatting} { format "%s %s %c %s" abcd {This is a very long test string.} 120 x |