aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-08-14 11:47:15 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-08-14 11:47:15 -0700
commit149f063107024f61295ceef6e5905f8123c490b7 (patch)
tree275c75aee12cd0f04c2ffeae3ff40ddd08eac9bd
parent173b8830def7800dc3caec992b7c7b7e2139bb73 (diff)
fix sign checks in strncasecmp and memcmp
-rw-r--r--src/library.js8
-rwxr-xr-xtests/runner.py16
2 files changed, 15 insertions, 9 deletions
diff --git a/src/library.js b/src/library.js
index a20cb03d..cfa29c58 100644
--- a/src/library.js
+++ b/src/library.js
@@ -4243,8 +4243,8 @@ LibraryManager.library = {
strncasecmp: function(px, py, n) {
var i = 0;
while (i < n) {
- var x = _tolower({{{ makeGetValue('px', 'i', 'i8') }}});
- var y = _tolower({{{ makeGetValue('py', 'i', 'i8') }}});
+ var x = _tolower({{{ makeGetValue('px', 'i', 'i8', 0, 1) }}});
+ var y = _tolower({{{ makeGetValue('py', 'i', 'i8', 0, 1) }}});
if (x == y && x == 0) return 0;
if (x == 0) return -1;
if (y == 0) return 1;
@@ -4260,8 +4260,8 @@ LibraryManager.library = {
memcmp: function(p1, p2, num) {
for (var i = 0; i < num; i++) {
- var v1 = {{{ makeGetValue('p1', 'i', 'i8') }}};
- var v2 = {{{ makeGetValue('p2', 'i', 'i8') }}};
+ var v1 = {{{ makeGetValue('p1', 'i', 'i8', 0, 1) }}};
+ var v2 = {{{ makeGetValue('p2', 'i', 'i8', 0, 1) }}};
if (v1 != v2) return v1 > v2 ? 1 : -1;
}
return 0;
diff --git a/tests/runner.py b/tests/runner.py
index c7a53e25..b80509ff 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -1493,13 +1493,19 @@ c5,de,15,8a
#include <string.h>
int main()
{
- char *word = "WORD";
- char *wordEntry = "Â";
- int cmp = strncmp(word, wordEntry, 2);
- printf("Compare value is %d\\n", cmp);
+ #define TEST(func) \
+ { \
+ char *word = "WORD"; \
+ char *wordEntry = "Â"; \
+ int cmp = func(word, wordEntry, 2); \
+ printf("Compare value " #func " is %d\\n", cmp); \
+ }
+ TEST(strncmp);
+ TEST(strncasecmp);
+ TEST(memcmp);
}
'''
- self.do_run(src, 'Compare value is -1\n')
+ self.do_run(src, 'Compare value strncmp is -1\nCompare value strncasecmp is -1\nCompare value memcmp is -1\n')
def test_strndup(self):
src = '''