From 37d44620a5890ff77a70b540b0b9ece780c9e490 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Tue, 25 Sep 2001 23:56:49 +0000 Subject: [PATCH] idl_check for back-bdb --- servers/slapd/back-bdb/idl.c | 51 +++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/servers/slapd/back-bdb/idl.c b/servers/slapd/back-bdb/idl.c index 45505e5928..e2cce0de7b 100644 --- a/servers/slapd/back-bdb/idl.c +++ b/servers/slapd/back-bdb/idl.c @@ -18,13 +18,31 @@ #define IDL_CMP(x,y) ( x < y ? -1 : ( x > y ? 1 : 0 ) ) -#undef IDL_DEBUG -#ifdef IDL_DEBUG -void idl_dump( ID *ids ) +#ifndef IDL_DEBUG + /* enable basic checks for now */ +#define IDL_DEBUG 1 +#endif + +#if IDL_DEBUG > 0 +static void idl_check( ID *ids ) +{ + if( BDB_IDL_IS_RANGE( ids ) ) { + assert( ids[1] <= ids[2] ); + } else { + ID i; + for( i=1; i < ids[0]; i++ ) { + assert( ids[i+1] > ids[i] ); + } + } +} + +#if IDL_DEBUG > 1 +static void idl_dump( ID *ids ) { if( BDB_IDL_IS_RANGE( ids ) ) { Debug( LDAP_DEBUG_ANY, - "IDL: range %ld - %ld\n", (long) ids[0], 0, 0 ); + "IDL: range %ld - %ld\n", + (long) ids[1], (long) idl[2], 0 ); } else { ID i; @@ -39,11 +57,18 @@ void idl_dump( ID *ids ) Debug( LDAP_DEBUG_ANY, "\n", 0, 0, 0 ); } + + idl_check( ids ); } -#endif +#endif /* IDL_DEBUG > 1 */ +#endif /* IDL_DEBUG > 0 */ unsigned bdb_idl_search( ID *ids, ID id ) { +#if IDL_DEBUG > 0 + idl_check( ids ); +#endif + #undef IDL_BINARY_SEARCH #ifdef IDL_BINARY_SEARCH /* @@ -95,9 +120,11 @@ static int idl_insert( ID *ids, ID id ) { unsigned x = bdb_idl_search( ids, id ); -#ifdef IDL_DEBUG +#if IDL_DEBUG > 1 Debug( LDAP_DEBUG_ANY, "insert: %04lx at %d\n", id, x, 0 ); idl_dump( ids ); +#elif IDL_DEBUG > 0 + idl_check( ids ); #endif assert( x > 0 ); @@ -129,8 +156,10 @@ static int idl_insert( ID *ids, ID id ) ids[x] = id; } -#ifdef IDL_DEBUG +#if IDL_DEBUG > 1 idl_dump( ids ); +#elif IDL_DEBUG > 0 + idl_check( ids ); #endif return 0; @@ -140,9 +169,11 @@ static int idl_delete( ID *ids, ID id ) { unsigned x = bdb_idl_search( ids, id ); -#ifdef IDL_DEBUG +#if IDL_DEBUG > 1 Debug( LDAP_DEBUG_ANY, "delete: %04lx at %d\n", id, x, 0 ); idl_dump( ids ); +#elif IDL_DEBUG > 0 + idl_check( ids ); #endif assert( x > 0 ); @@ -165,8 +196,10 @@ static int idl_delete( ID *ids, ID id ) AC_MEMCPY( &ids[x], &ids[x+1], (1+ids[0]-x) * sizeof(ID) ); } -#ifdef IDL_DEBUG +#if IDL_DEBUG > 1 idl_dump( ids ); +#elif IDL_DEBUG > 0 + idl_check( ids ); #endif return 0; -- 2.39.5