fix overflow in rng()

This commit is contained in:
alexlamsl 2017-04-02 04:52:22 +08:00
parent 0136737c90
commit 2987a4beb7

View File

@ -288,7 +288,7 @@ var loops = 0;
var funcs = 0; var funcs = 0;
function rng(max) { function rng(max) {
var r = randomBytes(2).readUInt16LE(0) / 0xFFFF; var r = randomBytes(2).readUInt16LE(0) / 65536;
return Math.floor(max * r); return Math.floor(max * r);
} }
@ -563,7 +563,7 @@ function _createSimpleBinaryExpr(recurmax, noComma) {
// intentionally generate more hardcore ops // intentionally generate more hardcore ops
if (--recurmax < 0) return createValue(); if (--recurmax < 0) return createValue();
var r = rng(30); var r = rng(30);
if (r === 0) return '(c = c + 1, ' + _createSimpleBinaryExpr(recurmax, noComma) + ')' if (r === 0) return '(c = c + 1, ' + _createSimpleBinaryExpr(recurmax, noComma) + ')';
var s = _createSimpleBinaryExpr(recurmax, noComma) + createBinaryOp(noComma) + _createSimpleBinaryExpr(recurmax, noComma); var s = _createSimpleBinaryExpr(recurmax, noComma) + createBinaryOp(noComma) + _createSimpleBinaryExpr(recurmax, noComma);
if (r === 1) { if (r === 1) {
// try to get a generated name reachable from current scope. default to just `a` // try to get a generated name reachable from current scope. default to just `a`