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) static spdylay_map_entry* erase_recur(spdylay_map_entry *entry, key_type key)
{ {
if(key < entry->key) { if(entry != NULL) {
entry->left = erase_recur(entry->left, key); if(key < entry->key) {
} else if(key > entry->key) { entry->left = erase_recur(entry->left, key);
entry->right = erase_recur(entry->right, key); } else if(key > entry->key) {
} else { entry->right = erase_recur(entry->right, key);
entry = erase_rotate_recur(entry); } else {
entry = erase_rotate_recur(entry);
}
} }
return entry; return entry;
} }

View File

@ -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);
} }