fixed edge-case when padding was not there and zero-terminator got overridden

This commit is contained in:
Richard Thier 2024-10-10 16:32:07 +02:00
parent 14052a8421
commit 21351fd2b4

View File

@ -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) {