mirror of
https://github.com/nmap/nmap.git
synced 2026-05-13 08:46:45 +00:00
Improve assertions in gh_heap
* Assert index matches any time a node is accessed by index, subsuming the assertion from #2139. * Ensure all removed nodes are invalidated, so double-removes will trigger assertion failure. Added a test for this.
This commit is contained in:
parent
10c4479b2d
commit
1c9e1ddbcb
2 changed files with 11 additions and 9 deletions
|
|
@ -70,7 +70,9 @@
|
|||
|
||||
static gh_hnode_t **hnode_ptr(gh_heap_t *heap, unsigned int index) {
|
||||
assert(index <= heap->count);
|
||||
return &(heap->slots[index]);
|
||||
gh_hnode_t **ptr = &(heap->slots[index]);
|
||||
assert(index == heap->count || (*ptr)->index == index);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
gh_hnode_t *gh_heap_find(gh_heap_t *heap, unsigned int index) {
|
||||
|
|
@ -94,7 +96,6 @@ static int hnode_up(gh_heap_t *heap, gh_hnode_t *hnode)
|
|||
parent_idx = (cur_idx - 1) >> 1;
|
||||
|
||||
parent_ptr = hnode_ptr(heap, parent_idx);
|
||||
assert((*parent_ptr)->index == parent_idx);
|
||||
|
||||
if (heap->cmp_op(*parent_ptr, hnode))
|
||||
break;
|
||||
|
|
@ -235,13 +236,13 @@ int gh_heap_remove(gh_heap_t *heap, gh_hnode_t *hnode)
|
|||
count--;
|
||||
last = *hnode_ptr(heap, count);
|
||||
heap->count = count;
|
||||
if (last == hnode)
|
||||
return 0;
|
||||
|
||||
last->index = cur_idx;
|
||||
*cur_ptr = last;
|
||||
if (!hnode_up(heap, *cur_ptr))
|
||||
hnode_down(heap, *cur_ptr);
|
||||
if (last != hnode)
|
||||
{
|
||||
last->index = cur_idx;
|
||||
*cur_ptr = last;
|
||||
if (!hnode_up(heap, *cur_ptr))
|
||||
hnode_down(heap, *cur_ptr);
|
||||
}
|
||||
|
||||
gh_hnode_invalidate(hnode);
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ static int ghheap_ordering(void *tdata) {
|
|||
gh_hnode_t *current;
|
||||
|
||||
current = gh_heap_pop(&heap);
|
||||
assert(!gh_hnode_is_valid(current));
|
||||
k = node2int(current);
|
||||
|
||||
if (k < n)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue