Skip to content

Commit

Permalink
fix sscanf handling of ends of %s
Browse files Browse the repository at this point in the history
  • Loading branch information
kripken committed Apr 17, 2012
1 parent b701567 commit 396cb4f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -2294,7 +2294,7 @@ 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' && (next != ' '.charCodeAt(0) && next != '\t'.charCodeAt(0) && next != '\n'.charCodeAt(0))) &&
(formatIndex >= format.length || next !== format[formatIndex].charCodeAt(0))) { // Stop when we read something that is coming up
buffer.push(String.fromCharCode(next));
next = get();
Expand Down
12 changes: 10 additions & 2 deletions tests/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3747,12 +3747,20 @@ def test_sscanf(self):
sscanf("-3.03", "%f", &a);
printf("%.4f\n", a);
char buffy[100];
sscanf("cheez some thing moar 123\nyet more\n", "cheez %s", buffy);
printf("|%s|\n", buffy);
sscanf("cheez something\nmoar 123\nyet more\n", "cheez %s", buffy);
printf("|%s|\n", buffy);
sscanf("cheez somethingmoar\tyet more\n", "cheez %s", buffy);
printf("|%s|\n", buffy);
return 0;
}
'''
self.do_run(src, 'en-us : 2\nen-r : 99\nen : 3\n1.234567, 0.000000\n-3.0300')
self.do_run(src, 'en-us : 2\nen-r : 99\nen : 3\n1.234567, 0.000000\n-3.0300\n|some|\n|something|\n|somethingmoar|')

# Part 2: doubles
def test_sscanf_2(self):
# doubles
if Settings.USE_TYPED_ARRAYS == 2:
for ftype in ['float', 'double']:
src = r'''
Expand Down

0 comments on commit 396cb4f

Please sign in to comment.