aboutsummaryrefslogtreecommitdiffstats
path: root/util-src/crand.c
diff options
context:
space:
mode:
Diffstat (limited to 'util-src/crand.c')
-rw-r--r--util-src/crand.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/util-src/crand.c b/util-src/crand.c
index d15fc090..ab2f4ad1 100644
--- a/util-src/crand.c
+++ b/util-src/crand.c
@@ -58,9 +58,19 @@ int getrandom(void *buf, size_t buflen, unsigned int flags) {
#error util.crand compiled without a random source
#endif
+#ifndef SMALLBUFSIZ
+#define SMALLBUFSIZ 32
+#endif
+
int Lrandom(lua_State *L) {
+ char smallbuf[SMALLBUFSIZ];
+ char *buf = &smallbuf[0];
const size_t len = luaL_checkinteger(L, 1);
- void *buf = lua_newuserdata(L, len);
+
+ if(len > SMALLBUFSIZ) {
+ buf = lua_newuserdata(L, len);
+ }
+
#if defined(WITH_GETRANDOM)
/*