diff options
-rw-r--r-- | src/library.js | 8 | ||||
-rwxr-xr-x | tests/runner.py | 4 |
2 files changed, 9 insertions, 3 deletions
diff --git a/src/library.js b/src/library.js index 0f37e097..52102f63 100644 --- a/src/library.js +++ b/src/library.js @@ -4288,14 +4288,16 @@ LibraryManager.library = { strstr: function(ptr1, ptr2) { var check = 0, start; do { + if (!check) { + start = ptr1; + check = ptr2; + } var curr1 = {{{ makeGetValue('ptr1++', 0, 'i8') }}}; - if (!check) check = start = ptr2; var curr2 = {{{ makeGetValue('check++', 0, 'i8') }}}; if (curr2 == 0) return start; if (curr2 != curr1) { // rewind to one character after start, to find ez in eeez - var diff = check - start - 1; - ptr1 -= diff; + ptr1 = start + 1; check = 0; } } while (curr1); diff --git a/tests/runner.py b/tests/runner.py index 46caef9a..1ad8f3a3 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -4009,6 +4009,9 @@ at function.:blag printf("%d\n", !!strstr("cheezy", "y")); printf("%d\n", !!strstr("cheezy", "z")); printf("%d\n", !!strstr("cheezy", "_")); + + const char *str = "a big string"; + printf("%d\n", strstr(str, "big") - str); return 0; } ''' @@ -4035,6 +4038,7 @@ at function.:blag 1 1 0 +2 ''') def test_sscanf(self): |