aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-01-31 11:06:14 -0800
committerAlon Zakai <alonzakai@gmail.com>2014-01-31 11:06:14 -0800
commitc326a24f775f4fda03c6a59f62759c5c7dfa4baa (patch)
tree08991ea26773ae054d99ec9d500dcd2d4996478c
parent5c35062c0096625f4d7004e243164de79388bedd (diff)
make sure rand() returns values only up to RAND_MAX; #18551.10.1
-rw-r--r--src/library.js2
-rw-r--r--src/struct_info.json4
-rw-r--r--tests/test_core.py36
-rw-r--r--tools/shared.py2
4 files changed, 23 insertions, 21 deletions
diff --git a/src/library.js b/src/library.js
index 632df975..d9e1942f 100644
--- a/src/library.js
+++ b/src/library.js
@@ -3458,7 +3458,7 @@ LibraryManager.library = {
rand_r: function(seedp) {
seedp = seedp|0;
var val = 0;
- val = (Math_imul({{{ makeGetValueAsm('seedp', 0, 'i32') }}}, 31010991)|0) + 0x676e6177 | 0;
+ val = ((Math_imul({{{ makeGetValueAsm('seedp', 0, 'i32') }}}, 31010991)|0) + 0x676e6177 ) & {{{ cDefine('RAND_MAX') }}};
{{{ makeSetValueAsm('seedp', 0, 'val', 'i32') }}};
return val|0;
},
diff --git a/src/struct_info.json b/src/struct_info.json
index 32261c0a..2aeffc9c 100644
--- a/src/struct_info.json
+++ b/src/struct_info.json
@@ -141,7 +141,9 @@
},
{
"file": "libc/stdlib.h",
- "defines": [],
+ "defines": [
+ "RAND_MAX"
+ ],
"structs": {
// NOTE: The hash sign at the end of this name is a hint to the processor that it mustn't prefix "struct " to the name to reference this struct.
// It will be stripped away when writing the compiled JSON file. You can just refer to it as C_STRUCTS.div_t when using it in the JS code.
diff --git a/tests/test_core.py b/tests/test_core.py
index 90453ae2..4d915e71 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -3565,26 +3565,26 @@ int main()
return 0;
}
'''
- expected = '''-73943336
--1417355489
--782256216
--810259121
+ expected = '''2073540312
+730128159
+1365227432
+1337224527
792390264
--194827905
--1163489464
--164637777
--936909288
--667866145
--73943336
--1417355489
--782256216
--810259121
+1952655743
+983994184
+1982845871
+1210574360
+1479617503
+2073540312
+730128159
+1365227432
+1337224527
792390264
--194827905
--1163489464
--164637777
--936909288
--667866145
+1952655743
+983994184
+1982845871
+1210574360
+1479617503
'''
self.do_run(src, expected)
diff --git a/tools/shared.py b/tools/shared.py
index bd1d1bee..3b0b92a3 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -345,7 +345,7 @@ def find_temp_directory():
# we re-check sanity when the settings are changed)
# We also re-check sanity and clear the cache when the version changes
-EMSCRIPTEN_VERSION = '1.10.0'
+EMSCRIPTEN_VERSION = '1.10.1'
def generate_sanity():
return EMSCRIPTEN_VERSION + '|' + get_llvm_target() + '|' + LLVM_ROOT + '|' + get_clang_version()