commit 2a8231d: [Minor] Fix return values in Lua API

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Sep 27 10:56:07 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-09-27 11:49:47 +0100
URL: https://github.com/rspamd/rspamd/commit/2a8231db5d2bb2590f419df73c5a529d39ff1a22 (HEAD -> master)

[Minor] Fix return values in Lua API

---
 src/lua/lua_regexp.c | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/src/lua/lua_regexp.c b/src/lua/lua_regexp.c
index a677f7195..7277f192f 100644
--- a/src/lua/lua_regexp.c
+++ b/src/lua/lua_regexp.c
@@ -588,12 +588,14 @@ lua_regexp_search (lua_State *L)
 			if (capture) {
 				g_array_free (captures, TRUE);
 			}
-
-			return 1;
+		}
+		else {
+			lua_pushnil (L);
 		}
 	}
-
-	lua_pushnil (L);
+	else {
+		return luaL_error (L, "invalid arguments");
+	}
 
 	return 1;
 }
@@ -644,11 +646,14 @@ lua_regexp_match (lua_State *L)
 			else {
 				lua_pushboolean (L, FALSE);
 			}
-			return 1;
+		}
+		else {
+			lua_pushboolean (L, FALSE);
 		}
 	}
-
-	lua_pushnil (L);
+	else {
+		return luaL_error (L, "invalid arguments");
+	}
 
 	return 1;
 }
@@ -689,13 +694,13 @@ lua_regexp_matchn (lua_State *L)
 		}
 
 		max_matches = lua_tointeger (L, 3);
+		matches = 0;
 
 		if (lua_gettop (L) == 4) {
 			raw = lua_toboolean (L, 4);
 		}
 
 		if (data && len > 0) {
-			matches = 0;
 
 			if (re->match_limit > 0) {
 				len = MIN (len, re->match_limit);
@@ -714,14 +719,14 @@ lua_regexp_matchn (lua_State *L)
 					break;
 				}
 			}
-
-			lua_pushinteger (L, matches);
-
-			return 1;
 		}
+
+		lua_pushinteger (L, matches);
+	}
+	else {
+		return luaL_error (L, "invalid arguments");
 	}
 
-	lua_pushnil (L);
 
 	return 1;
 }
@@ -825,6 +830,9 @@ lua_regexp_split (lua_State *L)
 			return 1;
 		}
 	}
+	else {
+		return luaL_error (L, "invalid arguments");
+	}
 
 	lua_pushnil (L);
 	return 1;


More information about the Commits mailing list