I received a bug report from Massimo Campostrini in Pisa. There are a pair
authorChristopher R. Hertel <crh@samba.org>
Wed, 21 Oct 1998 19:00:44 +0000 (19:00 +0000)
committerChristopher R. Hertel <crh@samba.org>
Wed, 21 Oct 1998 19:00:44 +0000 (19:00 +0000)
of "front-end" functions with the same bug each.

Fixed.

source/ubiqx/ubi_BinTree.c
source/ubiqx/ubi_BinTree.h

index 62d17d52555bad96af6f94db9d51af4db27fa65a..4e96c1d0ac8204824d547c930ea8a6e9301056b4 100644 (file)
  *
  * -------------------------------------------------------------------------- **
  *
- * Log: ubi_BinTree.c,v 
+ * Log: ubi_BinTree.c,v
+ * Revision 4.7  1998/10/21 06:14:42  crh
+ * Fixed bugs in FirstOf() and LastOf() reported by Massimo Campostrini.
+ * See function comments.
+ *
+ * Revision 4.6  1998/07/25 17:02:10  crh
+ * Added the ubi_trNewTree() macro.
+ *
  * Revision 4.5  1998/06/04 21:29:27  crh
  * Upper-cased defined constants (eg UBI_BINTREE_H) in some header files.
  * This is more "standard", and is what people expect.  Weird, eh?
  */
 
 static char ModuleID[] = "ubi_BinTree\n\
-\tRevision: 4.\n\
-\tDate: 1998/06/04 21:29:27 \n\
-\tAuthor: crh \n";
+\tRevision: 4.7\n\
+\tDate: 1998/10/21 06:14:42\n\
+\tAuthor: crh\n";
 
 /* ========================================================================== **
  * Internal (private) functions.
@@ -899,11 +906,15 @@ ubi_btNodePtr ubi_btFirstOf( ubi_btRootPtr RootPtr,
    *          matching <FindMe>.
    *  Notes:  Node *p MUST be in the set of nodes with keys matching
    *          <FindMe>.  If not, this function will return NULL.
+   *
+   *          4.7: Bug found & fixed by Massimo Campostrini,
+   *               Istituto Nazionale di Fisica Nucleare, Sezione di Pisa.
+   *
    * ------------------------------------------------------------------------ **
    */
   {
   /* If our starting point is invalid, return NULL. */
-  if( !p || ubi_trAbNormal( (*(RootPtr->cmp))( MatchMe, p ) != ubi_trEQUAL ) )
+  if( !p || (ubi_trEQUAL != ubi_trAbNormal( (*(RootPtr->cmp))( MatchMe, p ) )) )
     return( NULL );
   return( Border( RootPtr, MatchMe, p, ubi_trLEFT ) );
   } /* ubi_btFirstOf */
@@ -924,11 +935,15 @@ ubi_btNodePtr ubi_btLastOf( ubi_btRootPtr RootPtr,
    *          matching <FindMe>.
    *  Notes:  Node *p MUST be in the set of nodes with keys matching
    *          <FindMe>.  If not, this function will return NULL.
+   *
+   *          4.7: Bug found & fixed by Massimo Campostrini,
+   *               Istituto Nazionale di Fisica Nucleare, Sezione di Pisa.
+   *
    * ------------------------------------------------------------------------ **
    */
   {
   /* If our starting point is invalid, return NULL. */
-  if( !p || ubi_trAbNormal( (*(RootPtr->cmp))( MatchMe, p ) != ubi_trEQUAL ) )
+  if( !p || (ubi_trEQUAL != ubi_trAbNormal( (*(RootPtr->cmp))( MatchMe, p ) )) )
     return( NULL );
   return( Border( RootPtr, MatchMe, p, ubi_trRIGHT ) );
   } /* ubi_btLastOf */
index 9b7cda4bf23a9ba5243194e3117d1d08e4063ce1..53758246572ce5cbc28891af0dec9b18302e2c28 100644 (file)
  *
  * -------------------------------------------------------------------------- **
  *
- * Log: ubi_BinTree.h,v 
+ * Log: ubi_BinTree.h,v
+ * Revision 4.7  1998/10/21 06:15:07  crh
+ * Fixed bugs in FirstOf() and LastOf() reported by Massimo Campostrini.
+ * See function comments.
+ *
+ * Revision 4.6  1998/07/25 17:02:10  crh
+ * Added the ubi_trNewTree() macro.
+ *
  * Revision 4.5  1998/06/04 21:29:27  crh
  * Upper-cased defined constants (eg UBI_BINTREE_H) in some header files.
  * This is more "standard", and is what people expect.  Weird, eh?
@@ -245,15 +252,28 @@ typedef enum {
         ((ubi_trOVERWRITE & ((A)->flags))?(ubi_trTRUE):(ubi_trFALSE))
 
 /* -------------------------------------------------------------------------- **
- * A quickie for consistency.
- *  ubi_trCount() - Given a pointer to a tree root, this macro returns the
- *                  number of nodes currently in the tree.
+ * Additional Macros...
+ *
+ *  ubi_trCount()   - Given a pointer to a tree root, this macro returns the
+ *                    number of nodes currently in the tree.
+ *
+ *  ubi_trNewTree() - This macro makes it easy to declare and initialize a
+ *                    tree header in one step.  The line
+ *
+ *                      static ubi_trNewTree( MyTree, cmpfn, ubi_trDUPKEY );
+ *
+ *                    is equivalent to
+ *
+ *                      static ubi_trRoot MyTree[1]
+ *                        = {{ NULL, cmpfn, 0, ubi_trDUPKEY }};
  *
  * -------------------------------------------------------------------------- **
  */
 
 #define ubi_trCount( R ) (((ubi_trRootPtr)(R))->count)
 
+#define ubi_trNewTree( N, C, F ) ubi_trRoot (N)[1] = {{ NULL, (C), 0, (F) }}
+
 /* -------------------------------------------------------------------------- **
  * Typedefs...
  * 
@@ -620,6 +640,10 @@ ubi_btNodePtr ubi_btFirstOf( ubi_btRootPtr RootPtr,
    *          matching <FindMe>.
    *  Notes:  Node *p MUST be in the set of nodes with keys matching
    *          <FindMe>.  If not, this function will return NULL.
+   *
+   *          4.7: Bug found & fixed by Massimo Campostrini,
+   *               Istituto Nazionale di Fisica Nucleare, Sezione di Pisa.
+   *
    * ------------------------------------------------------------------------ **
    */
 
@@ -639,6 +663,10 @@ ubi_btNodePtr ubi_btLastOf( ubi_btRootPtr RootPtr,
    *          matching <FindMe>.
    *  Notes:  Node *p MUST be in the set of nodes with keys matching
    *          <FindMe>.  If not, this function will return NULL.
+   *
+   *          4.7: Bug found & fixed by Massimo Campostrini,
+   *               Istituto Nazionale di Fisica Nucleare, Sezione di Pisa.
+   *
    * ------------------------------------------------------------------------ **
    */