]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix a nasty 64-bit-uncleanness bug in OSet spotted by Julian -- for fast
authorNicholas Nethercote <njn@valgrind.org>
Sat, 24 Dec 2005 03:10:56 +0000 (03:10 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Sat, 24 Dec 2005 03:10:56 +0000 (03:10 +0000)
comparisons it was only considering the bottom 32-bits of the key.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@5427

cachegrind/cg_main.c
coregrind/m_oset.c
include/pub_tool_oset.h

index 81cabb52d842ce0bd694c4ba97bde7bbaff7a91f..7d5f6667135841457ccbceeb28e164385f6b67b0 100644 (file)
@@ -92,9 +92,9 @@ struct _LineCC {
 };
 
 // First compare file, then fn, then line.
-static Int cmp_CodeLoc_LineCC(void *vloc, void *vcc)
+static Word cmp_CodeLoc_LineCC(void *vloc, void *vcc)
 {
-   Int res;
+   Word res;
    CodeLoc* a = (CodeLoc*)vloc;
    CodeLoc* b = &(((LineCC*)vcc)->loc);
 
@@ -162,7 +162,7 @@ static Int  no_debugs           = 0;
 /*--- String table operations                              ---*/
 /*------------------------------------------------------------*/
 
-static Int stringCmp( void* key, void* elem )
+static Word stringCmp( void* key, void* elem )
 {
    return VG_(strcmp)(*(Char**)key, *(Char**)elem);
 }
index 810890f4d51c4e843a1452556430bf34d8d4f59f..7117ea1376dd415104a7ae923255dc863e38ef18 100644 (file)
@@ -171,13 +171,13 @@ void* fast_key_of_node(AvlNode* n)
 }
 
 // Compare the first word of each element.  Inlining is *crucial*.
-static inline Int fast_cmp(void* k, AvlNode* n)
+static inline Word fast_cmp(void* k, AvlNode* n)
 {
-   return ( *(Int*)k - *(Int*)elem_of_node(n) );
+   return ( *(Word*)k - *(Word*)elem_of_node(n) );
 }
 
 // Compare a key and an element.  Inlining is *crucial*.
-static inline Int slow_cmp(AvlTree* t, void* k, AvlNode* n)
+static inline Word slow_cmp(AvlTree* t, void* k, AvlNode* n)
 {
    return t->cmp(k, elem_of_node(n));
 }
@@ -349,7 +349,7 @@ void VG_(OSet_FreeNode)(AvlTree* t, void* e)
 /*--- Insertion                                                    ---*/
 /*--------------------------------------------------------------------*/
 
-static inline Int cmp_key_root(AvlTree* t, AvlNode* n)
+static inline Word cmp_key_root(AvlTree* t, AvlNode* n)
 {
    return t->cmp
           ? slow_cmp(t, slow_key_of_node(t, n), t->root)
@@ -360,7 +360,7 @@ static inline Int cmp_key_root(AvlTree* t, AvlNode* n)
 // Returns True if the depth of the tree has grown.
 static Bool avl_insert(AvlTree* t, AvlNode* n)
 {
-   Int cmpres = cmp_key_root(t, n);
+   Word cmpres = cmp_key_root(t, n);
 
    if (cmpres < 0) {
       // Insert into the left subtree.
@@ -464,7 +464,7 @@ void VG_(OSet_Insert)(AvlTree* t, void* e)
 // Find the *node* in t matching k, or NULL if not found.
 static AvlNode* avl_lookup(AvlTree* t, void* k)
 {
-   Int      cmpres;
+   Word     cmpres;
    AvlNode* curr = t->root;
 
    if (t->cmp) {
@@ -481,10 +481,10 @@ static AvlNode* avl_lookup(AvlTree* t, void* k)
       // elem_of_node because it saves about 10% on lookup time.  This
       // shouldn't be very dangerous because each node will have been
       // checked on insertion.
-      Int kk = *(Int*)k;
+      Word kk = *(Word*)k;
       while (True) {
          if (curr == NULL) return NULL;
-         cmpres = kk - *(Int*)elem_of_node_no_check(curr);
+         cmpres = kk - *(Word*)elem_of_node_no_check(curr);
          if (cmpres < 0) curr = curr->left;  else
          if (cmpres > 0) curr = curr->right; else
          return curr;
@@ -533,7 +533,7 @@ static Bool avl_removeroot(AvlTree* t);
 static Bool avl_remove(AvlTree* t, AvlNode* n)
 {
    Bool ch;
-   Int  cmpres = cmp_key_root(t, n);
+   Word cmpres = cmp_key_root(t, n);
 
    if (cmpres < 0) {
       AvlTree left_subtree;
@@ -616,7 +616,7 @@ static Bool avl_remove(AvlTree* t, AvlNode* n)
 // Returns True if the depth of the tree has shrunk.
 static Bool avl_removeroot(AvlTree* t)
 {
-   Int ch;
+   Bool     ch;
    AvlNode* n;
 
    if (!t->root->left) {
index 05c8a6f569d57ed891b9b9e65629834c2ddea4dc..23b17739a79e14e77801f34bce0b71309f8a1d1a 100644 (file)
@@ -65,7 +65,7 @@
 typedef struct _OSet     OSet;
 typedef struct _OSetNode OSetNode;
 
-typedef Int   (*OSetCmp_t)         ( void* key, void* elem );
+typedef Word  (*OSetCmp_t)         ( void* key, void* elem );
 typedef void* (*OSetAlloc_t)       ( SizeT szB );
 typedef void  (*OSetFree_t)        ( void* p );
 typedef void  (*OSetNodeDestroy_t) ( void* elem );