]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
lua: move LuaPushStringBuffer to the generic util-lua.c
authorVictor Julien <victor@inliniac.net>
Fri, 1 Aug 2014 10:32:38 +0000 (12:32 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 15 Aug 2014 11:58:27 +0000 (13:58 +0200)
src/output-lua-common.c
src/output-lua-common.h
src/util-lua.c
src/util-lua.h

index 4760a95e19d2a94128018b55ec95886a2379c06c..aec17e00020e19bc6b0310a29f7218e2489ee7bb 100644 (file)
@@ -63,23 +63,6 @@ int LuaCallbackError(lua_State *luastate, const char *msg)
     return 2;
 }
 
-int LuaPushStringBuffer(lua_State *luastate, const uint8_t *input, size_t input_len)
-{
-    /* we're using a buffer sized at a multiple of 4 as lua_pushlstring generates
-     * invalid read errors in valgrind otherwise. Adding in a nul to be sure.
-     *
-     * Buffer size = len + 1 (for nul) + whatever makes it a multiple of 4 */
-    size_t buflen = input_len + 1 + ((input_len + 1) % 4);
-    uint8_t buf[buflen];
-    memset(buf, 0x00, buflen);
-    memcpy(buf, input, input_len);
-    buf[input_len] = '\0';
-
-    /* return value through luastate, as a luastring */
-    lua_pushlstring(luastate, (char *)buf, input_len);
-    return 1;
-}
-
 const char *LuaGetStringArgument(lua_State *luastate, int argc)
 {
     /* get argument */
index 2e68634821802576906ef912713ca53ed3983a82..c19045c93d4b6397d1139e0d459e4ae3eba57f7e 100644 (file)
@@ -27,7 +27,6 @@
 #ifdef HAVE_LUA
 
 int LuaCallbackError(lua_State *luastate, const char *msg);
-int LuaPushStringBuffer(lua_State *luastate, const uint8_t *input, size_t input_len);
 const char *LuaGetStringArgument(lua_State *luastate, int argc);
 
 void LogLuaPushTableKeyValueInt(lua_State *luastate, const char *key, int value);
index 446598a5705db102e3e4df79e3af7a93b49ca5ed..b091445ab429511723cbacff158777b87a539b1b 100644 (file)
@@ -234,7 +234,21 @@ void LuaPrintStack(lua_State *state) {
     }
 }
 
-
-
+int LuaPushStringBuffer(lua_State *luastate, const uint8_t *input, size_t input_len)
+{
+    /* we're using a buffer sized at a multiple of 4 as lua_pushlstring generates
+     * invalid read errors in valgrind otherwise. Adding in a nul to be sure.
+     *
+     * Buffer size = len + 1 (for nul) + whatever makes it a multiple of 4 */
+    size_t buflen = input_len + 1 + ((input_len + 1) % 4);
+    uint8_t buf[buflen];
+    memset(buf, 0x00, buflen);
+    memcpy(buf, input, input_len);
+    buf[input_len] = '\0';
+
+    /* return value through luastate, as a luastring */
+    lua_pushlstring(luastate, (char *)buf, input_len);
+    return 1;
+}
 
 #endif /* HAVE_LUA */
index eb7a637e35e7e3d4e248f215607612d3c29b27f4..7ea69915b9e0c62b60192d33aea213ae4bdfa450 100644 (file)
@@ -84,6 +84,8 @@ void LuaStateSetStreamingBuffer(lua_State *luastate, LuaStreamingBuffer *b);
 
 void LuaPrintStack(lua_State *state);
 
+int LuaPushStringBuffer(lua_State *luastate, const uint8_t *input, size_t input_len);
+
 #endif /* HAVE_LUA */
 
 #endif /* __UTIL_LUA_H__ */