Skip to content

Commit

Permalink
[Minor] Avoid 0 size mallocs
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Sep 7, 2023
1 parent 7ee372d commit df23899
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/libserver/re_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit df23899

Please sign in to comment.