more meaningful tests for finding the errors: 8-length special case bug found
This commit is contained in:
parent
79aa314352
commit
14052a8421
4
main.cpp
4
main.cpp
@ -26,7 +26,7 @@ void test_basics(amap mapdo, void *map) {
|
|||||||
assert(NULL != mapdo(map, AMAP_ERASE, NULL, NULL));
|
assert(NULL != mapdo(map, AMAP_ERASE, NULL, NULL));
|
||||||
|
|
||||||
/* Check re-adding 3 new things */
|
/* 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));
|
assert(NULL != mapdo(map, AMAP_SET, "meaning2", &i));
|
||||||
const char *helloworld = "Hello world!";
|
const char *helloworld = "Hello world!";
|
||||||
assert(NULL != mapdo(map, AMAP_SET, "hello", (char *)helloworld)); /* TODO: ugly cast... */
|
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(NULL != (iptr = (int *)mapdo(map, AMAP_GET, "meaning2", NULL)));
|
||||||
assert(*iptr == 42);
|
assert(*iptr == 42);
|
||||||
assert(iptr == &i);
|
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 == 42);
|
||||||
assert(iptr == &i);
|
assert(iptr == &i);
|
||||||
}
|
}
|
||||||
|
7
simap.h
7
simap.h
@ -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 usi = map->usage_end;
|
||||||
uint32_t previ = map->prev_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);
|
simap_ptr64 *data = (simap_ptr64 *)((uint8_t *)(map->base) + usi);
|
||||||
data->ptr = ptr;
|
data->ptr = ptr;
|
||||||
|
|
||||||
/* Save link to previous */
|
/* 8byte: Save link to previous and next */
|
||||||
uint32_t *usprev = (uint32_t *)((uint8_t *)(map->base) + usi +
|
uint32_t *usprev = (uint32_t *)((uint8_t *)(map->base) + usi +
|
||||||
sizeof(simap_ptr64));
|
sizeof(simap_ptr64));
|
||||||
*usprev = previ;
|
*usprev = previ;
|
||||||
/* and nex */
|
|
||||||
*(usprev + 1) = (uint32_t) -1;
|
*(usprev + 1) = (uint32_t) -1;
|
||||||
|
|
||||||
/* First 8 bytes */
|
/* 8byte: First 8 char */
|
||||||
simap_c64 *start_str = (simap_c64 *)(usprev + 2);
|
simap_c64 *start_str = (simap_c64 *)(usprev + 2);
|
||||||
*start_str = first8;
|
*start_str = first8;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user