aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-11-16 20:51:15 -0800
committerAlon Zakai <alonzakai@gmail.com>2011-11-16 20:51:15 -0800
commite2c5a4daa5af7c9130d616ebc68b23ec465fa1f9 (patch)
treec3a33ba16bd2664a2162081f926319ea53912da0
parentbcf1a4f0e90b93a7771058fda56e4be1046af38a (diff)
do not fail on malloc(0)
-rw-r--r--src/library.js4
-rw-r--r--tests/runner.py4
2 files changed, 6 insertions, 2 deletions
diff --git a/src/library.js b/src/library.js
index 8127ece4..8c3740b3 100644
--- a/src/library.js
+++ b/src/library.js
@@ -3143,7 +3143,9 @@ LibraryManager.library = {
// stdlib.h
// ==========================================================================
- malloc: Runtime.staticAlloc,
+ malloc: function(bytes) {
+ return Runtime.staticAlloc(bytes || 1); // accept 0 as an input because libc implementations tend to
+ },
_Znwj: 'malloc',
_Znaj: 'malloc',
_Znam: 'malloc',
diff --git a/tests/runner.py b/tests/runner.py
index 159f7d7b..d2be039e 100644
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -1795,11 +1795,13 @@ if 'benchmark' not in str(sys.argv):
printf("*%lu*\\n", strtoul("0", NULL, 0));
printf("*%lu*\\n", strtoul("-10", NULL, 0));
+ printf("*malloc(0)!=0:%d*\\n", malloc(0) != 0); // We should not fail horribly
+
return 0;
}
'''
- self.do_run(src, '*1,2,3,5,5,6*\n*stdin==0:0*\n*%*\n*5*\n*66.0*\n*10*\n*0*\n*-10*\n*18*\n*10*\n*0*\n*4294967286*\n*cleaned*')
+ self.do_run(src, '*1,2,3,5,5,6*\n*stdin==0:0*\n*%*\n*5*\n*66.0*\n*10*\n*0*\n*-10*\n*18*\n*10*\n*0*\n*4294967286*\n*malloc(0)!=0:1*\n*cleaned*')
def test_time(self):
# XXX Not sure what the right output is here. Looks like the test started failing with daylight savings changes. Modified it to pass again.