util.crand: Return early if a zero bytes are requested
authorKim Alvefur <zash@zash.se>
Sun, 03 Dec 2017 15:42:55 +0100
changeset 8454 770f79a9635c
parent 8453 3a9a3d90c44c
child 8455 4796fdcb7146
util.crand: Return early if a zero bytes are requested
util-src/crand.c
--- a/util-src/crand.c	Sun Dec 03 15:37:17 2017 +0100
+++ b/util-src/crand.c	Sun Dec 03 15:42:55 2017 +0100
@@ -73,11 +73,15 @@
 	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