1
0
mirror of https://github.com/moparisthebest/spdylay synced 2024-12-21 23:28:52 -05:00

Fixed bug that causes segmentation fault when erasing key which does not exist in map.

This commit is contained in:
Tatsuhiro Tsujikawa 2012-01-26 00:21:31 +09:00
parent 43c0ef8151
commit 1ce2598758
2 changed files with 11 additions and 7 deletions

View File

@ -164,12 +164,14 @@ static spdylay_map_entry* erase_rotate_recur(spdylay_map_entry *entry)
static spdylay_map_entry* erase_recur(spdylay_map_entry *entry, key_type key)
{
if(key < entry->key) {
entry->left = erase_recur(entry->left, key);
} else if(key > entry->key) {
entry->right = erase_recur(entry->right, key);
} else {
entry = erase_rotate_recur(entry);
if(entry != NULL) {
if(key < entry->key) {
entry->left = erase_recur(entry->left, key);
} else if(key > entry->key) {
entry->right = erase_recur(entry->right, key);
} else {
entry = erase_rotate_recur(entry);
}
}
return entry;
}

View File

@ -47,9 +47,11 @@ void test_spdylay_map()
spdylay_map_erase(&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("shrubbery", spdylay_map_find(&map, 4)) == 0);
spdylay_map_free(&map);
}