diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-07-19 18:11:27 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-07-19 18:12:16 -0700 |
commit | d9d0118d035d5b71edcabd7de7fdb07db0dcffce (patch) | |
tree | 0976be258a6b494d9f4e33f75deb3f242b539a11 /src/library.js | |
parent | e59bfd4f6cd7afe39411e34b65a161b09ccbbedf (diff) |
handle %Nc in sscanf; fixes #1407
Diffstat (limited to 'src/library.js')
-rw-r--r-- | src/library.js | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/src/library.js b/src/library.js index b2823fb6..ed7bfa4d 100644 --- a/src/library.js +++ b/src/library.js @@ -2560,15 +2560,27 @@ LibraryManager.library = { continue; } - // TODO: Support strings like "%5c" etc. - if (format[formatIndex] === '%' && format[formatIndex+1] == 'c') { - var argPtr = {{{ makeGetValue('varargs', 'argIndex', 'void*') }}}; - argIndex += Runtime.getAlignSize('void*', null, true); - fields++; - next = get(); - {{{ makeSetValue('argPtr', 0, 'next', 'i8') }}} - formatIndex += 2; - continue; + if (format[formatIndex] === '%') { + var nextC = format.indexOf('c', formatIndex+1); + if (nextC > 0) { + var maxx = 1; + if (nextC > formatIndex+1) { + var sub = format.substring(formatIndex+1, nextC) + maxx = parseInt(sub); + if (maxx != sub) maxx = 0; + } + if (maxx) { + var argPtr = HEAP32[(varargs + argIndex)>>2]; + argIndex += Runtime.getAlignSize('void*', null, true); + fields++; + for (var i = 0; i < maxx; i++) { + next = get(); + {{{ makeSetValue('argPtr++', 0, 'next', 'i8') }}}; + } + formatIndex += nextC - formatIndex + 1; + continue; + } + } } // remove whitespace |