commit df23899: [Minor] Avoid 0 size mallocs
Vsevolod Stakhov
vsevolod at rspamd.com
Thu Sep 7 15:07:03 UTC 2023
Author: Vsevolod Stakhov
Date: 2023-09-07 16:00:56 +0100
URL: https://github.com/rspamd/rspamd/commit/df2389900f12cd82d1246490339ef99e62ba13a1 (HEAD -> master)
[Minor] Avoid 0 size mallocs
---
src/libserver/re_cache.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c
index 171c3d31e..6dd06711b 100644
--- a/src/libserver/re_cache.c
+++ b/src/libserver/re_cache.c
@@ -954,17 +954,20 @@ rspamd_re_cache_process_selector(struct rspamd_task *task,
lua_rawgeti(L, -1, i + 1);
txt = lua_check_text_or_string(L, -1);
- if (txt) {
+ if (txt && txt->len > 0) {
sel_data = txt->start;
slen = txt->len;
+ (*svec)[i] = g_malloc(slen);
+ memcpy((*svec)[i], sel_data, slen);
}
else {
+ /* A hack to avoid malloc(0) */
sel_data = "";
slen = 0;
+ (*svec)[i] = g_malloc(1);
+ memcpy((*svec)[i], sel_data, 1);
}
- (*svec)[i] = g_malloc(slen);
- memcpy((*svec)[i], sel_data, slen);
(*lenvec)[i] = slen;
lua_pop(L, 1);
}
More information about the Commits
mailing list