aboutsummaryrefslogtreecommitdiffstats
path: root/util-src/crand.c
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-12-03 15:42:55 +0100
committerKim Alvefur <zash@zash.se>2017-12-03 15:42:55 +0100
commit442fb34ca00bddf98cabd90f1175ff134b190c8a (patch)
tree3eeb5e6a7675b2aea5152323993d13b37a06c3a6 /util-src/crand.c
parent09000b3a82fbf035276fe8415c9f89b32e2ed567 (diff)
downloadprosody-442fb34ca00bddf98cabd90f1175ff134b190c8a.tar.gz
prosody-442fb34ca00bddf98cabd90f1175ff134b190c8a.zip
util.crand: Return early if a zero bytes are requested
Diffstat (limited to 'util-src/crand.c')
-rw-r--r--util-src/crand.c6
1 files changed, 5 insertions, 1 deletions
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