aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-11-02 15:36:36 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-11-02 15:36:36 -0700
commit132bbc90e82bdeef7410ed50c9d6c513bc2d28ba (patch)
tree5ba65f96c190bca82a79e6afccd33a7e3eb7fabc /src
parent608ab508328f76a988d3792174b393dfacb8f99f (diff)
scanf improvements
Diffstat (limited to 'src')
-rw-r--r--src/library.js4
1 files changed, 3 insertions, 1 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++;