From 25337767bfb8d8d40c142e4acc6bc11116b15266 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 27 Feb 2017 15:24:28 +1100 Subject: extension.new: Swap to switch/case based argument checking --- src/openssl.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/openssl.c b/src/openssl.c index 900b909..9ea9469 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -4989,9 +4989,13 @@ static int xe_new(lua_State *L) { lua_settop(L, 3); ud = prepsimple(L, X509_EXT_CLASS); - if (!lua_isnil(L, 3)) { + switch (lua_type(L, 3)) { + case LUA_TNONE: + case LUA_TNIL: + break; + case LUA_TSTRING: { size_t len; - const char *cdata = luaL_checklstring(L, 3, &len); + const char *cdata = lua_tolstring(L, 3, &len); _Bool crit; if (xe_new_isder(value, &crit)) { @@ -5015,6 +5019,10 @@ static int xe_new(lua_State *L) { ctx = &cbuf; X509V3_set_nconf(ctx, conf); + break; + } + default: + return luaL_argerror(L, 3, "invalid extra parameter (expected string or nil)"); } /* -- cgit v1.2.3-59-g8ed1b