Fixed bug that causes segmentation fault when erasing key which does not exist in map.
This commit is contained in:
parent
43c0ef8151
commit
1ce2598758
|
@ -164,6 +164,7 @@ static spdylay_map_entry* erase_rotate_recur(spdylay_map_entry *entry)
|
||||||
|
|
||||||
static spdylay_map_entry* erase_recur(spdylay_map_entry *entry, key_type key)
|
static spdylay_map_entry* erase_recur(spdylay_map_entry *entry, key_type key)
|
||||||
{
|
{
|
||||||
|
if(entry != NULL) {
|
||||||
if(key < entry->key) {
|
if(key < entry->key) {
|
||||||
entry->left = erase_recur(entry->left, key);
|
entry->left = erase_recur(entry->left, key);
|
||||||
} else if(key > entry->key) {
|
} else if(key > entry->key) {
|
||||||
|
@ -171,6 +172,7 @@ static spdylay_map_entry* erase_recur(spdylay_map_entry *entry, key_type key)
|
||||||
} else {
|
} else {
|
||||||
entry = erase_rotate_recur(entry);
|
entry = erase_rotate_recur(entry);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,9 +47,11 @@ void test_spdylay_map()
|
||||||
spdylay_map_erase(&map, 1);
|
spdylay_map_erase(&map, 1);
|
||||||
CU_ASSERT(NULL == spdylay_map_find(&map, 1));
|
CU_ASSERT(NULL == spdylay_map_find(&map, 1));
|
||||||
|
|
||||||
|
spdylay_map_erase(&map, 1);
|
||||||
|
CU_ASSERT(NULL == spdylay_map_find(&map, 1));
|
||||||
|
|
||||||
CU_ASSERT(strcmp("bar", spdylay_map_find(&map, 2)) == 0);
|
CU_ASSERT(strcmp("bar", spdylay_map_find(&map, 2)) == 0);
|
||||||
CU_ASSERT(strcmp("shrubbery", spdylay_map_find(&map, 4)) == 0);
|
CU_ASSERT(strcmp("shrubbery", spdylay_map_find(&map, 4)) == 0);
|
||||||
|
|
||||||
spdylay_map_free(&map);
|
spdylay_map_free(&map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue