diff options
author | Soeren Balko <Soeren.Balko@gmail.com> | 2013-05-25 12:20:14 +1000 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-05-29 10:59:41 -0700 |
commit | 662da70e4e673b1611ed6587ece4e638bdf2b2ab (patch) | |
tree | e864e84517e10bd8fbad9648a3edcff8fd459db1 /src | |
parent | e7016ba189980e52e8f490853e532ca9c1d4cefe (diff) |
This fixes various strtoll/strtol issues, including tests
Diffstat (limited to 'src')
-rw-r--r-- | src/library.js | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/library.js b/src/library.js index 00852630..e65754ba 100644 --- a/src/library.js +++ b/src/library.js @@ -3918,7 +3918,14 @@ LibraryManager.library = { str++; } } - } + } else if (finalBase==16) { + if ({{{ makeGetValue('str', 0, 'i8') }}} == {{{ charCode('0') }}}) { + if ({{{ makeGetValue('str+1', 0, 'i8') }}} == {{{ charCode('x') }}} || + {{{ makeGetValue('str+1', 0, 'i8') }}} == {{{ charCode('X') }}}) { + str += 2; + } + } + } if (!finalBase) finalBase = 10; // Get digits. @@ -3969,13 +3976,14 @@ LibraryManager.library = { #if USE_TYPED_ARRAYS == 2 _parseInt64__deps: ['isspace', '__setErrNo', '$ERRNO_CODES', function() { Types.preciseI64MathUsed = 1 }], _parseInt64: function(str, endptr, base, min, max, unsign) { - var start = str; + var isNegative = false; // Skip space. while (_isspace({{{ makeGetValue('str', 0, 'i8') }}})) str++; - + // Check for a plus/minus sign. if ({{{ makeGetValue('str', 0, 'i8') }}} == {{{ charCode('-') }}}) { str++; + isNegative = true; } else if ({{{ makeGetValue('str', 0, 'i8') }}} == {{{ charCode('+') }}}) { str++; } @@ -3991,12 +3999,19 @@ LibraryManager.library = { str += 2; } else { finalBase = 8; - str++; ok = true; // we saw an initial zero, perhaps the entire thing is just "0" } } - } + } else if (finalBase==16) { + if ({{{ makeGetValue('str', 0, 'i8') }}} == {{{ charCode('0') }}}) { + if ({{{ makeGetValue('str+1', 0, 'i8') }}} == {{{ charCode('x') }}} || + {{{ makeGetValue('str+1', 0, 'i8') }}} == {{{ charCode('X') }}}) { + str += 2; + } + } + } if (!finalBase) finalBase = 10; + start = str; // Get digits. var chr; @@ -4009,6 +4024,7 @@ LibraryManager.library = { ok = true; } } + if (!ok) { ___setErrNo(ERRNO_CODES.EINVAL); {{{ makeStructuralReturn(['0', '0']) }}}; @@ -4020,7 +4036,8 @@ LibraryManager.library = { } try { - i64Math.fromString(Pointer_stringify(start, str - start), finalBase, min, max, unsign); + var numberString = isNegative ? '-'+Pointer_stringify(start, str - start) : Pointer_stringify(start, str - start); + i64Math.fromString(numberString, finalBase, min, max, unsign); } catch(e) { ___setErrNo(ERRNO_CODES.ERANGE); // not quite correct } |