Skip to content

Commit e3a200a

Browse files
committed
FIX: to integer! "00" failing on MacOS
resolves: Oldes/Rebol-issues#2504
1 parent 446a1e7 commit e3a200a

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/core/l-types.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ bad_hex: Trap0(RE_INVALID_CHARS);
334334
REBINT num = (REBINT)len;
335335
REBYTE buf[MAX_NUM_LEN+4];
336336
REBYTE *bp;
337-
REBI64 n;
337+
REBI64 n = 0;
338338
REBOOL neg = FALSE;
339339

340340
// Super-fast conversion of zero and one (most common cases):
@@ -369,12 +369,13 @@ bad_hex: Trap0(RE_INVALID_CHARS);
369369
len = (REBCNT)(bp - &buf[0]);
370370
if (neg) len--;
371371
if (len > 19) return 0;
372-
373-
// Convert, check, and return:
374-
errno = 0;
375-
n = CHR_TO_INT(buf);
376-
if (errno != 0) return 0; //overflow
377-
if ((n > 0 && neg) || (n < 0 && !neg)) return 0;
372+
if (len > 0) {
373+
// Convert, check, and return:
374+
errno = 0;
375+
n = CHR_TO_INT(buf);
376+
if (errno != 0) return 0; //overflow
377+
if ((n > 0 && neg) || (n < 0 && !neg)) return 0;
378+
}
378379
SET_INTEGER(value, n);
379380
return cp;
380381
}

src/tests/units/make-test.r3

+4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ Rebol [
9999
--assert all [error? e: try [to integer! "9'223'372'036'854'775'808"] e/id = 'bad-make-arg]
100100
;@@ https://github.com/Oldes/Rebol-issues/issues/2099
101101
--assert 302961000000 = to integer! "3.02961E+11"
102+
;@@ https://github.com/Oldes/Rebol-issues/issues/2504
103+
--assert 0 = to integer! "0"
104+
--assert 0 = to integer! "00"
105+
--assert 0 = to integer! "00000000000"
102106

103107
===end-group===
104108

0 commit comments

Comments
 (0)