+2850. [bug] If isc_heap_insert() failed due to memory shortage
+ the heap would have corrupted entries.
+
2849. [bug] Don't treat errors from the xml2 library as fatal.
[RT #20945]
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: heap.c,v 1.37 2007/10/19 17:15:53 explorer Exp $ */
+/* $Id: heap.c,v 1.38 2010/02/04 23:22:05 jinmei Exp $ */
/*! \file
* Heap implementation of priority queues adapted from the following:
isc_result_t
isc_heap_insert(isc_heap_t *heap, void *elt) {
- unsigned int i;
+ unsigned int new_last;
REQUIRE(VALID_HEAP(heap));
- i = ++heap->last;
- if (heap->last >= heap->size && !resize(heap))
+ new_last = heap->last + 1;
+ RUNTIME_CHECK(new_last > 0); /* overflow check */
+ if (new_last >= heap->size && !resize(heap))
return (ISC_R_NOMEMORY);
+ heap->last = new_last;
- float_up(heap, i, elt);
+ float_up(heap, new_last, elt);
return (ISC_R_SUCCESS);
}