From d2ee3d52a3b5d9053bcd38004e77d99d2ee93080 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Wed, 15 May 2002 03:05:05 +0000 Subject: [PATCH] Once more, fix idl_intersection. Don't walk past end of arrays. --- servers/slapd/back-ldbm/idl.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/servers/slapd/back-ldbm/idl.c b/servers/slapd/back-ldbm/idl.c index 2fe5d6fd04..60ca3e6594 100644 --- a/servers/slapd/back-ldbm/idl.c +++ b/servers/slapd/back-ldbm/idl.c @@ -1058,6 +1058,9 @@ idl_intersection( if ( ID_BLOCK_ALLIDS( b ) ) { return( idl_dup( a ) ); } + if ( ID_BLOCK_NIDS(a) == 0 || ID_BLOCK_NIDS(b) == 0 ) { + return( NULL ); + } n = idl_dup( idl_min( a, b ) ); @@ -1066,24 +1069,21 @@ idl_intersection( idl_check(b); #endif - for ( ni = 0, ai = 0, bi = 0; ai < ID_BLOCK_NIDS(a); ai++ ) { - if ( ID_BLOCK_ID(a, ai) < ID_BLOCK_ID(b, bi) ) { - continue; - } - for ( ; - bi < ID_BLOCK_NIDS(b) && ID_BLOCK_ID(b, bi) < ID_BLOCK_ID(a, ai); - bi++ ) - { - ; /* NULL */ - } - - if ( bi == ID_BLOCK_NIDS(b) ) { - break; - } - + for ( ni = 0, ai = 0, bi = 0; ; ) { if ( ID_BLOCK_ID(b, bi) == ID_BLOCK_ID(a, ai) ) { ID_BLOCK_ID(n, ni++) = ID_BLOCK_ID(a, ai); + ai++; bi++; + if ( ai >= ID_BLOCK_NIDS(a) || bi >= ID_BLOCK_NIDS(b) ) + break; + } else if ( ID_BLOCK_ID(a, ai) < ID_BLOCK_ID(b, bi) ) { + ai++; + if ( ai >= ID_BLOCK_NIDS(a) ) + break; + } else { + bi++; + if ( bi >= ID_BLOCK_NIDS(b) ) + break; } } -- 2.39.5