more meaningful tests for finding the errors: 8-length special case bug found

This commit is contained in:
Richard Thier 2024-10-10 16:06:08 +02:00
parent 79aa314352
commit 14052a8421
2 changed files with 5 additions and 6 deletions

View File

@ -26,7 +26,7 @@ void test_basics(amap mapdo, void *map) {
assert(NULL != mapdo(map, AMAP_ERASE, NULL, NULL));
/* Check re-adding 3 new things */
assert(NULL != mapdo(map, AMAP_SET, "meaning1", &i));
assert(NULL != mapdo(map, AMAP_SET, "meaningless1", &i));
assert(NULL != mapdo(map, AMAP_SET, "meaning2", &i));
const char *helloworld = "Hello world!";
assert(NULL != mapdo(map, AMAP_SET, "hello", (char *)helloworld)); /* TODO: ugly cast... */
@ -37,7 +37,7 @@ void test_basics(amap mapdo, void *map) {
assert(NULL != (iptr = (int *)mapdo(map, AMAP_GET, "meaning2", NULL)));
assert(*iptr == 42);
assert(iptr == &i);
assert(NULL != (iptr = (int *)mapdo(map, AMAP_GET, "meaning1", NULL)));
assert(NULL != (iptr = (int *)mapdo(map, AMAP_GET, "meaningless1", NULL)));
assert(*iptr == 42);
assert(iptr == &i);
}

View File

@ -173,18 +173,17 @@ static inline void *simap_force_add_internal(simap_instance *map, const char *ke
uint32_t usi = map->usage_end;
uint32_t previ = map->prev_usage_end;
/* Save data ptr */
/* 8byte: Save data ptr */
simap_ptr64 *data = (simap_ptr64 *)((uint8_t *)(map->base) + usi);
data->ptr = ptr;
/* Save link to previous */
/* 8byte: Save link to previous and next */
uint32_t *usprev = (uint32_t *)((uint8_t *)(map->base) + usi +
sizeof(simap_ptr64));
*usprev = previ;
/* and nex */
*(usprev + 1) = (uint32_t) -1;
/* First 8 bytes */
/* 8byte: First 8 char */
simap_c64 *start_str = (simap_c64 *)(usprev + 2);
*start_str = first8;