summaryrefslogtreecommitdiff
path: root/lmathlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-11-07 09:31:58 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-11-07 09:31:58 -0200
commit17ca3b176321fb3a33f4542982e6ff3e82a3d864 (patch)
treeb63d73cb64ab46ed4a7e6542382116141c7eed54 /lmathlib.c
parent50b18f60cb31b361dff6af6cde8389352641d7c1 (diff)
downloadlua-github-17ca3b176321fb3a33f4542982e6ff3e82a3d864.tar.gz
cleaner test for overflow for range of 'math.random'
Diffstat (limited to 'lmathlib.c')
-rw-r--r--lmathlib.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/lmathlib.c b/lmathlib.c
index 212dc696..a643ef73 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lmathlib.c,v 1.111 2014/10/24 11:42:06 roberto Exp roberto $
+** $Id: lmathlib.c,v 1.112 2014/11/02 19:19:04 roberto Exp roberto $
** Standard mathematical library
** See Copyright Notice in lua.h
*/
@@ -258,8 +258,8 @@ static int math_random (lua_State *L) {
}
/* random integer in the interval [low, up] */
luaL_argcheck(L, low <= up, 1, "interval is empty");
- luaL_argcheck(L, (lua_Unsigned)up - low <= (lua_Unsigned)LUA_MAXINTEGER,
- 1, "interval too large");
+ luaL_argcheck(L, low >= 0 || up <= LUA_MAXINTEGER + low, 1,
+ "interval too large");
r *= (double)(up - low) + 1.0;
lua_pushinteger(L, (lua_Integer)r + low);
return 1;