diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-12-14 16:34:35 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-12-14 16:34:35 +0000 |
commit | 65477c306436ca302709f32d15b975fbf4dc21eb (patch) | |
tree | 0bb197386c1738c624cd1da6384bf44a4cea1402 /src | |
parent | 35479797646a4a1e5c4b0bfcb9a87d7e3b39dbcd (diff) | |
download | rspamd-65477c306436ca302709f32d15b975fbf4dc21eb.tar.gz rspamd-65477c306436ca302709f32d15b975fbf4dc21eb.zip |
[Project] Try to do strings concatenation in C
Diffstat (limited to 'src')
-rw-r--r-- | src/libstat/backends/redis_backend.cxx | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/libstat/backends/redis_backend.cxx b/src/libstat/backends/redis_backend.cxx index 5e222c6cb..7bebeb1ed 100644 --- a/src/libstat/backends/redis_backend.cxx +++ b/src/libstat/backends/redis_backend.cxx @@ -646,11 +646,12 @@ void rspamd_redis_close(gpointer p) * Serialise stat tokens to message pack */ static char * -rspamd_redis_serialize_tokens(struct rspamd_task *task, GPtrArray *tokens, gsize *ser_len) +rspamd_redis_serialize_tokens(struct rspamd_task *task, const gchar *prefix, GPtrArray *tokens, gsize *ser_len) { /* Each token is int64_t that requires 10 bytes (2 int32_t) + 4 bytes array len + 1 byte array magic */ char max_int64_str[] = "18446744073709551615"; - auto req_len = tokens->len * sizeof(max_int64_str) + 5; + auto prefix_len = strlen(prefix); + auto req_len = tokens->len * (sizeof(max_int64_str) + prefix_len + 1) + 5; rspamd_token_t *tok; auto *buf = (gchar *) rspamd_mempool_alloc(task->task_pool, req_len); @@ -667,8 +668,8 @@ rspamd_redis_serialize_tokens(struct rspamd_task *task, GPtrArray *tokens, gsize int i; PTR_ARRAY_FOREACH(tokens, i, tok) { - char numbuf[sizeof(max_int64_str)]; - auto r = rspamd_snprintf(numbuf, sizeof(numbuf), "%uL", tok->data); + char *numbuf = (char *) g_alloca(sizeof(max_int64_str) + prefix_len + 1); + auto r = rspamd_snprintf(numbuf, sizeof(numbuf), "%s_%uL", tok->data); *p++ = (gchar) ((r & 0xff) | 0xa0); memcpy(p, &numbuf, r); |