aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lauxlib.c10
-rw-r--r--lmathlib.c4
-rw-r--r--ltablib.c2
-rw-r--r--manual/manual.of4
4 files changed, 9 insertions, 11 deletions
diff --git a/lauxlib.c b/lauxlib.c
index 64b325d3..555a5976 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1094,8 +1094,8 @@ static void warnfon (void *ud, const char *message, int tocont) {
1094 1094
1095/* 1095/*
1096** A function to compute an unsigned int with some level of 1096** A function to compute an unsigned int with some level of
1097** randomness. Rely on Address Space Layout Randomization (if present), 1097** randomness. Rely on Address Space Layout Randomization (if present)
1098** current time, and clock. 1098** and the current time.
1099*/ 1099*/
1100#if !defined(luai_makeseed) 1100#if !defined(luai_makeseed)
1101 1101
@@ -1115,18 +1115,16 @@ static void warnfon (void *ud, const char *message, int tocont) {
1115 1115
1116 1116
1117static unsigned int luai_makeseed (void) { 1117static unsigned int luai_makeseed (void) {
1118 unsigned int buff[sof(void*) + sof(clock_t) + sof(time_t)]; 1118 unsigned int buff[sof(void*) + sof(time_t)];
1119 unsigned int res; 1119 unsigned int res;
1120 unsigned int *b = buff; 1120 unsigned int *b = buff;
1121 clock_t c = clock();
1122 time_t t = time(NULL); 1121 time_t t = time(NULL);
1123 void *h = buff; 1122 void *h = buff;
1124 addbuff(b, h); /* local variable's address */ 1123 addbuff(b, h); /* local variable's address */
1125 addbuff(b, c); /* clock */
1126 addbuff(b, t); /* time */ 1124 addbuff(b, t); /* time */
1127 res = buff[0]; 1125 res = buff[0];
1128 for (b = buff + 1; b < buff + sof(buff); b++) 1126 for (b = buff + 1; b < buff + sof(buff); b++)
1129 res += *b; 1127 res ^= (res >> 3) + (res << 7) + *b;
1130 return res; 1128 return res;
1131} 1129}
1132 1130
diff --git a/lmathlib.c b/lmathlib.c
index f13cae4a..6d63950c 100644
--- a/lmathlib.c
+++ b/lmathlib.c
@@ -607,8 +607,8 @@ static int math_randomseed (lua_State *L) {
607 RanState *state = (RanState *)lua_touserdata(L, lua_upvalueindex(1)); 607 RanState *state = (RanState *)lua_touserdata(L, lua_upvalueindex(1));
608 lua_Unsigned n1, n2; 608 lua_Unsigned n1, n2;
609 if (lua_isnone(L, 1)) { 609 if (lua_isnone(L, 1)) {
610 n1 = luaL_makeseed(L); 610 n1 = luaL_makeseed(L); /* "random" seed */
611 n2 = I2UInt(state->s[0]); 611 n2 = I2UInt(nextrand(state->s)); /* in case seed is not that random... */
612 } 612 }
613 else { 613 else {
614 n1 = luaL_checkinteger(L, 1); 614 n1 = luaL_checkinteger(L, 1);
diff --git a/ltablib.c b/ltablib.c
index 82584459..44d55ef5 100644
--- a/ltablib.c
+++ b/ltablib.c
@@ -310,7 +310,7 @@ static IdxT partition (lua_State *L, IdxT lo, IdxT up) {
310*/ 310*/
311static IdxT choosePivot (IdxT lo, IdxT up, unsigned int rnd) { 311static IdxT choosePivot (IdxT lo, IdxT up, unsigned int rnd) {
312 IdxT r4 = (up - lo) / 4; /* range/4 */ 312 IdxT r4 = (up - lo) / 4; /* range/4 */
313 IdxT p = rnd % (r4 * 2) + (lo + r4); 313 IdxT p = (rnd ^ lo ^ up) % (r4 * 2) + (lo + r4);
314 lua_assert(lo + r4 <= p && p <= up - r4); 314 lua_assert(lo + r4 <= p && p <= up - r4);
315 return p; 315 return p;
316} 316}
diff --git a/manual/manual.of b/manual/manual.of
index fdae76f2..446517ec 100644
--- a/manual/manual.of
+++ b/manual/manual.of
@@ -5728,8 +5728,8 @@ it does not run it.
5728@apii{0,0,-} 5728@apii{0,0,-}
5729 5729
5730Returns a value with a weak attempt for randomness. 5730Returns a value with a weak attempt for randomness.
5731(It produces that value based on the current date and time, 5731(It produces that value based on the current date and time
5732the current processor time, and the address of an internal variable, 5732and the address of an internal variable,
5733in case the machine has Address Space Layout Randomization.) 5733in case the machine has Address Space Layout Randomization.)
5734 5734
5735} 5735}