]> git.sur5r.net Git - openldap/commitdiff
Once more, fix idl_intersection. Don't walk past end of arrays.
authorHoward Chu <hyc@openldap.org>
Wed, 15 May 2002 03:05:05 +0000 (03:05 +0000)
committerHoward Chu <hyc@openldap.org>
Wed, 15 May 2002 03:05:05 +0000 (03:05 +0000)
servers/slapd/back-ldbm/idl.c

index 2fe5d6fd04b0dfd5d6cff253961decfbed5a7862..60ca3e65946d383f7e63d8cc1c5a8d85bec41eda 100644 (file)
@@ -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;
                }
        }