diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-01-31 11:06:14 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-01-31 11:06:14 -0800 |
commit | c326a24f775f4fda03c6a59f62759c5c7dfa4baa (patch) | |
tree | 08991ea26773ae054d99ec9d500dcd2d4996478c /src | |
parent | 5c35062c0096625f4d7004e243164de79388bedd (diff) |
make sure rand() returns values only up to RAND_MAX; #18551.10.1
Diffstat (limited to 'src')
-rw-r--r-- | src/library.js | 2 | ||||
-rw-r--r-- | src/struct_info.json | 4 |
2 files changed, 4 insertions, 2 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. |