From 36ff81d81a339a5b0dbd6e80d0996e1cebfbeb91 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 3 Dec 2017 15:42:55 +0100 Subject: util.crand: Return early if a zero bytes are requested --- util-src/crand.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'util-src') diff --git a/util-src/crand.c b/util-src/crand.c index 20871f3e..160ac1f6 100644 --- a/util-src/crand.c +++ b/util-src/crand.c @@ -73,11 +73,15 @@ int Lrandom(lua_State *L) { const size_t len = l; luaL_argcheck(L, l >= 0, 1, "must be > 0"); + if(len == 0) { + lua_pushliteral(L, ""); + return 1; + } + if(len > SMALLBUFSIZ) { buf = lua_newuserdata(L, len); } - #if defined(WITH_GETRANDOM) /* * This acts like a read from /dev/urandom with the exception that it -- cgit v1.2.3