mirror of
https://github.com/isc-projects/bind9.git
synced 2026-05-28 04:34:54 -04:00
4829. [bug] isc_heap_delete did not zero the index value when
the heap was created with a callback to do that.
[RT #46709]
This commit is contained in:
parent
5f308740df
commit
65a483106e
5 changed files with 106 additions and 11 deletions
4
CHANGES
4
CHANGES
|
|
@ -1,3 +1,7 @@
|
|||
4829. [bug] isc_heap_delete did not zero the index value when
|
||||
the heap was created with a callback to do that.
|
||||
[RT #46709]
|
||||
|
||||
4828. [bug] Do not use thread-local storage for storing LMDB reader
|
||||
locktable slots. [RT #46556]
|
||||
|
||||
|
|
|
|||
|
|
@ -217,6 +217,8 @@ isc_heap_delete(isc_heap_t *heap, unsigned int idx) {
|
|||
REQUIRE(idx >= 1 && idx <= heap->last);
|
||||
|
||||
heap_check(heap);
|
||||
if (heap->index != NULL)
|
||||
(heap->index)(heap->array[idx], 0);
|
||||
if (idx == heap->last) {
|
||||
heap->array[heap->last] = NULL;
|
||||
heap->last--;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ tp: counter_test
|
|||
tp: errno_test
|
||||
tp: file_test
|
||||
tp: hash_test
|
||||
tp: heap_test
|
||||
tp: ht_test
|
||||
tp: inet_ntop_test
|
||||
tp: lex_test
|
||||
|
|
|
|||
|
|
@ -26,21 +26,22 @@ LIBS = @LIBS@ @ATFLIBS@
|
|||
|
||||
OBJS = isctest.@O@
|
||||
SRCS = isctest.c aes_test.c buffer_test.c counter_test.c \
|
||||
errno_test.c file_test.c hash_test.c ht_test.c \
|
||||
inet_ntop_test.c lex_test.c mem_test.c netaddr_test.c \
|
||||
parse_test.c pool_test.c print_test.c queue_test.c \
|
||||
radix_test.c random_test.c regex_test.c result_test.c \
|
||||
safe_test.c sockaddr_test.c socket_test.c socket_test.c \
|
||||
symtab_test.c task_test.c taskpool_test.c time_test.c
|
||||
errno_test.c file_test.c hash_test.c heap_test.c \
|
||||
ht_test.c inet_ntop_test.c lex_test.c mem_test.c \
|
||||
netaddr_test.c parse_test.c pool_test.c print_test.c \
|
||||
queue_test.c radix_test.c random_test.c regex_test.c \
|
||||
result_test.c safe_test.c sockaddr_test.c \
|
||||
socket_test.c socket_test.c symtab_test.c task_test.c \
|
||||
taskpool_test.c time_test.c
|
||||
|
||||
SUBDIRS =
|
||||
TARGETS = aes_test@EXEEXT@ buffer_test@EXEEXT@ counter_test@EXEEXT@ \
|
||||
errno_test@EXEEXT@ file_test@EXEEXT@ hash_test@EXEEXT@ \
|
||||
ht_test@EXEEXT@ inet_ntop_test@EXEEXT@ lex_test@EXEEXT@ \
|
||||
mem_test@EXEEXT@ netaddr_test@EXEEXT@ parse_test@EXEEXT@ \
|
||||
pool_test@EXEEXT@ print_test@EXEEXT@ queue_test@EXEEXT@ \
|
||||
radix_test@EXEEXT@ random_test@EXEEXT@ regex_test@EXEEXT@ \
|
||||
result_test@EXEEXT@ safe_test@EXEEXT@ \
|
||||
heap_test@EXEEXT@ ht_test@EXEEXT@ inet_ntop_test@EXEEXT@ \
|
||||
lex_test@EXEEXT@ mem_test@EXEEXT@ netaddr_test@EXEEXT@ \
|
||||
parse_test@EXEEXT@ pool_test@EXEEXT@ print_test@EXEEXT@ \
|
||||
queue_test@EXEEXT@ radix_test@EXEEXT@ random_test@EXEEXT@ \
|
||||
regex_test@EXEEXT@ result_test@EXEEXT@ safe_test@EXEEXT@ \
|
||||
sockaddr_test@EXEEXT@ socket_test@EXEEXT@ \
|
||||
socket_test@EXEEXT@ symtab_test@EXEEXT@ task_test@EXEEXT@ \
|
||||
taskpool_test@EXEEXT@ time_test@EXEEXT@
|
||||
|
|
@ -71,6 +72,10 @@ hash_test@EXEEXT@: hash_test.@O@ ${ISCDEPLIBS}
|
|||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
hash_test.@O@ ${ISCLIBS} ${LIBS}
|
||||
|
||||
heap_test@EXEEXT@: heap_test.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
heap_test.@O@ ${ISCLIBS} ${LIBS}
|
||||
|
||||
ht_test@EXEEXT@: ht_test.@O@ ${ISCDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
ht_test.@O@ ${ISCLIBS} ${LIBS}
|
||||
|
|
|
|||
83
lib/isc/tests/heap_test.c
Normal file
83
lib/isc/tests/heap_test.c
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (C) 2011-2017 Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
/* ! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <isc/heap.h>
|
||||
#include <isc/mem.h>
|
||||
|
||||
#include <isc/util.h>
|
||||
|
||||
struct e {
|
||||
unsigned int value;
|
||||
unsigned int index;
|
||||
};
|
||||
|
||||
static isc_boolean_t
|
||||
compare(void *p1, void *p2) {
|
||||
struct e *e1 = p1;
|
||||
struct e *e2 = p2;
|
||||
|
||||
return (ISC_TF(e1->value < e2->value));
|
||||
}
|
||||
|
||||
static void
|
||||
idx(void *p, unsigned int i) {
|
||||
struct e *e = p;
|
||||
|
||||
e->index = i;
|
||||
}
|
||||
|
||||
ATF_TC(isc_heap_delete);
|
||||
ATF_TC_HEAD(isc_heap_delete, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "test isc_heap_delete");
|
||||
}
|
||||
ATF_TC_BODY(isc_heap_delete, tc) {
|
||||
isc_mem_t *mctx = NULL;
|
||||
isc_heap_t *heap = NULL;
|
||||
isc_result_t result;
|
||||
struct e e1 = { 100, 0 };
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = isc_mem_create(0, 0, &mctx);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
|
||||
result = isc_heap_create(mctx, compare, idx, 0, &heap);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE(heap != NULL);
|
||||
|
||||
isc_heap_insert(heap, &e1);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
ATF_REQUIRE_EQ(e1.index, 1);
|
||||
|
||||
isc_heap_delete(heap, e1.index);
|
||||
ATF_CHECK_EQ(e1.index, 0);
|
||||
|
||||
isc_heap_destroy(&heap);
|
||||
ATF_REQUIRE_EQ(heap, NULL);
|
||||
|
||||
isc_mem_detach(&mctx);
|
||||
ATF_REQUIRE_EQ(mctx, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, isc_heap_delete);
|
||||
|
||||
return (atf_no_error());
|
||||
}
|
||||
Loading…
Reference in a new issue