diff options
-rw-r--r-- | src/library.js | 4 | ||||
-rw-r--r-- | tests/runner.py | 25 |
2 files changed, 27 insertions, 2 deletions
diff --git a/src/library.js b/src/library.js index 75010afb..de42d1e0 100644 --- a/src/library.js +++ b/src/library.js @@ -2130,6 +2130,7 @@ LibraryManager.library = { var fields = 0; var argIndex = 0; for (var formatIndex = 0; formatIndex < format.length; formatIndex++) { + if (next <= 0) return fields; var next = get(); if (next <= 0) return fields; // End of input. if (format[formatIndex] === '%') { @@ -2153,7 +2154,8 @@ LibraryManager.library = { (type === 'x' && (next >= '0'.charCodeAt(0) && next <= '9'.charCodeAt(0) || next >= 'a'.charCodeAt(0) && next <= 'f'.charCodeAt(0) || next >= 'A'.charCodeAt(0) && next <= 'F'.charCodeAt(0))) || - (type === 's')) { + (type === 's') && + (formatIndex >= format.length || next !== format[formatIndex].charCodeAt(0))) { // Stop when we read something that is coming up buffer.push(String.fromCharCode(next)); next = get(); curr++; diff --git a/tests/runner.py b/tests/runner.py index c33f7565..517f2bcf 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -236,7 +236,7 @@ if 'benchmark' not in str(sys.argv): # If not provided with expected output, then generate it right now, using lli if expected_output is None: expected_output = self.run_llvm_interpreter([filename + '.o']) - print '[autogenerated expected output: %20s]' % (expected_output[0:17].replace('\n', '')+'...') + print '[autogenerated expected output: %20s]' % (expected_output[0:30].replace('\n', '|')+'...') # Run in both JavaScript engines, if optimizing - significant differences there (typed arrays) if js_engines is None: @@ -2349,6 +2349,29 @@ if 'benchmark' not in str(sys.argv): ''' self.do_run(src, re.sub('(^|\n)\s+', '\\1', expected)) + def test_sscanf(self): + src = r''' + #include <stdio.h> + #include <string.h> + + int main () { + #define CHECK(str) \ + { \ + char name[1000]; \ + memset(name, 0, 1000); \ + int prio = 99; \ + sscanf(str, "%s %d", name, &prio); \ + printf("%s : %d\n", name, prio); \ + } + CHECK("en-us 2"); + CHECK("en-r"); + CHECK("en 3"); + + return 0; + } + ''' + self.do_run(src) + def test_langinfo(self): src = open(path_from_root('tests', 'langinfo', 'test.c'), 'r').read() expected = open(path_from_root('tests', 'langinfo', 'output.txt'), 'r').read() |