From 21351fd2b4b29493c5e79d5cac77044a39499084 Mon Sep 17 00:00:00 2001 From: Richard Thier Date: Thu, 10 Oct 2024 16:32:07 +0200 Subject: [PATCH] fixed edge-case when padding was not there and zero-terminator got overridden --- simap.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/simap.h b/simap.h index 9ccd852..9107abd 100644 --- a/simap.h +++ b/simap.h @@ -140,6 +140,8 @@ static inline unsigned int get_size_padding(unsigned int size, unsigned int alig static inline uint32_t simap_elem_storage_size(const char *key) { uint32_t keysize = strlen(key); uint32_t padding = get_size_padding(keysize, 8); + /* XXX: The exactly 8byte keys need a zero terminator too (would be overridden without this) */ + padding += (keysize == 8) ? 8 : 0; return keysize + sizeof(simap_ptr64) + @@ -193,6 +195,7 @@ static inline void *simap_force_add_internal(simap_instance *map, const char *ke char *rem_str = (char *)(start_str + 1); strcpy(rem_str, key + 8); } + /* XXX: The "padding" gets automagically added by the movement of the arena here(by junk bytes)! */ /* Update previous with linkage */ if(previ != (uint32_t)-1) {