aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-04-02 15:37:31 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-04-02 15:37:31 +0100
commit69c4a64a428965c4d08ac8706d9c28c5473a8f8c (patch)
tree5dbe2df7ee8a8f02820ad79ef4607c641fc1056f /src/lua
parent432b714a952fea7f60fc1218960172b95169257f (diff)
downloadrspamd-69c4a64a428965c4d08ac8706d9c28c5473a8f8c.tar.gz
rspamd-69c4a64a428965c4d08ac8706d9c28c5473a8f8c.zip
[Minor] Lua_text: Add a hack to use several distinct fake texts
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_text.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/lua/lua_text.c b/src/lua/lua_text.c
index c90c2e6bf..dde7e2c23 100644
--- a/src/lua/lua_text.c
+++ b/src/lua/lua_text.c
@@ -288,19 +288,26 @@ lua_check_text_or_string (lua_State * L, gint pos)
return ud ? (struct rspamd_lua_text *) ud : NULL;
}
else if (pos_type == LUA_TSTRING) {
- /* Fake static lua_text */
- static struct rspamd_lua_text fake_text;
+ /*
+ * Fake static lua_text, we allow to use this function multiple times
+ * by having a small array of static structures.
+ */
+ static int cur_txt_idx = 0;
+ static struct rspamd_lua_text fake_text[4];
gsize len;
+ int sel_idx;
+
+ sel_idx = cur_txt_idx++ % G_N_ELEMENTS (fake_text);
+ fake_text[sel_idx].start = lua_tolstring (L, pos, &len);
- fake_text.start = lua_tolstring (L, pos, &len);
if (len >= G_MAXUINT) {
return NULL;
}
- fake_text.len = len;
- fake_text.flags = RSPAMD_TEXT_FLAG_FAKE;
+ fake_text[sel_idx].len = len;
+ fake_text[sel_idx].flags = RSPAMD_TEXT_FLAG_FAKE;
- return &fake_text;
+ return &fake_text[sel_idx];
}
return NULL;