budb: fix signedness of hash address logging
[openafs.git] / src / budb / db_hash.c
index e519326..445a1a1 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
@@ -9,18 +9,13 @@
 
 #include <afsconfig.h>
 #include <afs/param.h>
+#include <afs/stds.h>
 
+#include <roken.h>
 
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#else
-#include <netinet/in.h>
-#endif
-#include <string.h>
-#include <sys/types.h>
-#include <afs/stds.h>
 #include <ubik.h>
 #include <afs/bubasics.h>
+
 #include "budb_errs.h"
 #include "database.h"
 #include "budb_internal.h"
@@ -79,7 +74,7 @@ ht_ResetT(struct memoryHTBlock ***blocksP, int *sizeP, int length)
 }
 
 /* ht_Reset
- *     reinitialize a memory hash table. 
+ *     reinitialize a memory hash table.
  *     Calls ht_ResetT to invalidate the two block arrays.
  */
 
@@ -177,11 +172,10 @@ ht_AllocTable(struct ubik_trans *ut, struct memoryHashTable *mht)
     len = nb * nHTBuckets;     /* new hash table length */
 
     mht->size = nb * sizeof(struct memoryHTBlock *);
-    b = mht->blocks = (struct memoryHTBlock **)malloc(mht->size);
-    memset(b, 0, mht->size);
+    b = mht->blocks = calloc(1, mht->size);
 
     for (i = 0; i < nb; i++) {
-       b[i] = (struct memoryHTBlock *)malloc(sizeof(struct memoryHTBlock));
+       b[i] = malloc(sizeof(struct memoryHTBlock));
        code = AllocBlock(ut, (struct block *)&b[i]->b, &b[i]->a);
        if (code)
            return code;
@@ -247,8 +241,8 @@ ht_FreeTable(struct ubik_trans *ut, struct memoryHashTable *mht)
 }
 
 afs_int32
-ht_GetTableBlock(struct ubik_trans *ut, struct memoryHashTable *mht, 
-                afs_uint32 hash, int old, struct memoryHTBlock **blockP, 
+ht_GetTableBlock(struct ubik_trans *ut, struct memoryHashTable *mht,
+                afs_uint32 hash, int old, struct memoryHTBlock **blockP,
                 int *boP)
 {
     struct hashTable *ht = NULL;
@@ -290,8 +284,7 @@ ht_GetTableBlock(struct ubik_trans *ut, struct memoryHashTable *mht,
 
     if (*blocksP == 0) {
        *sizeP = ht_TableSize(length);
-       *blocksP = (struct memoryHTBlock **)malloc(*sizeP);
-       memset(*blocksP, 0, *sizeP);
+       *blocksP = calloc(1, *sizeP);
     }
     n = *sizeP / sizeof(struct memoryHTBlock *);
     if (bi >= n)
@@ -309,8 +302,7 @@ ht_GetTableBlock(struct ubik_trans *ut, struct memoryHashTable *mht,
                    db_panic("non-zero length, but no table");
            }
            /* else ta is set from last time around loop */
-           b[i] =
-               (struct memoryHTBlock *)malloc(sizeof(struct memoryHTBlock));
+           b[i] = malloc(sizeof(struct memoryHTBlock));
            b[i]->a = ta;
            b[i]->valid = 0;
        }
@@ -382,7 +374,7 @@ ht_MaybeAdjust(struct ubik_trans *ut, struct memoryHashTable *mht)
 }
 
 dbadr
-ht_LookupBucket(struct ubik_trans *ut, struct memoryHashTable *mht, 
+ht_LookupBucket(struct ubik_trans *ut, struct memoryHashTable *mht,
                afs_uint32 hash, int old)
 {
     struct memoryHTBlock *block;
@@ -546,7 +538,7 @@ ht_minHBlocks(struct memoryHashTable *mht)
 }
 
 afs_uint32
-ht_HashEntry(struct memoryHashTable *mht, 
+ht_HashEntry(struct memoryHashTable *mht,
             char *e)                           /* entry's address (in b) */
 {
     int type = ntohl(mht->ht->functionType);
@@ -555,22 +547,22 @@ ht_HashEntry(struct memoryHashTable *mht,
     switch (type) {
     case HT_dumpIden_FUNCTION:
        retval = IdHashFunction(ntohl(((struct dump *)e)->id));
-       LogDebug(5, "HashEntry: dumpid returns %d\n", retval);
+       LogDebug(5, "HashEntry: dumpid returns %u\n", retval);
        break;
 
     case HT_dumpName_FUNCTION:
        retval = StringHashFunction((unsigned char *)((struct dump *)e)->dumpName);
-       LogDebug(5, "HashEntry: dumpname returns %d\n", retval);
+       LogDebug(5, "HashEntry: dumpname returns %u\n", retval);
        break;
 
     case HT_tapeName_FUNCTION:
        retval = StringHashFunction((unsigned char *)((struct tape *)e)->name);
-       LogDebug(5, "HashEntry: tapename returns %d\n", retval);
+       LogDebug(5, "HashEntry: tapename returns %u\n", retval);
        break;
 
     case HT_volName_FUNCTION:
        retval = StringHashFunction((unsigned char *)((struct volInfo *)e)->name);
-       LogDebug(5, "HashEntry: volname returns %d\n", retval);
+       LogDebug(5, "HashEntry: volname returns %u\n", retval);
        break;
 
     default:
@@ -653,8 +645,8 @@ ht_KeyMatch(int type, char *key, char *e)
  */
 
 afs_int32
-ht_LookupEntry(struct ubik_trans *ut, 
-              struct memoryHashTable *mht, 
+ht_LookupEntry(struct ubik_trans *ut,
+              struct memoryHashTable *mht,
               void *key,       /* pointer to lookup key to match */
               dbadr *eaP,      /* db addr of entry found or zero */
               void *e)         /* contents of located entry */
@@ -704,7 +696,7 @@ ht_LookupEntry(struct ubik_trans *ut,
  */
 
 static afs_int32
-ht_HashInList(struct ubik_trans *ut, struct memoryHashTable *mht, 
+ht_HashInList(struct ubik_trans *ut, struct memoryHashTable *mht,
              int *opQuota, struct memoryHTBlock *block, int blockOffset)
 {
     struct hashTable *ht = mht->ht;
@@ -730,7 +722,7 @@ ht_HashInList(struct ubik_trans *ut, struct memoryHashTable *mht,
 
     for (ea = listA; ea; ea = next_ea) {       /*f */
 
-       LogDebug(3, "ht_HashInList: move entry at %d, type %d\n", ea,
+       LogDebug(3, "ht_HashInList: move entry at %u, type %d\n", ea,
                 ntohl(mht->ht->functionType));
 
        if (dbread(ut, ea, e, e_size))
@@ -757,7 +749,7 @@ ht_HashInList(struct ubik_trans *ut, struct memoryHashTable *mht,
 
            /* get the hash value */
            hash = ht_HashEntry(mht, e) % mht->length;
-           LogDebug(4, "ht_HashInList: moved to %d\n", hash);
+           LogDebug(4, "ht_HashInList: moved to %u\n", hash);
 
            /* get the new hash table block */
            code = ht_GetTableBlock(ut, mht, hash, 0 /*old */ , &block, &bo);
@@ -942,7 +934,7 @@ ht_HashIn(struct ubik_trans *ut,
     code = set_word_offset(ut, ea, e, mht->threadOffset, block->b.bucket[bo]);
     if (code)
        return BUDB_IO;
-    LogDebug(5, "Hashin: set %d to %d\n", mht->threadOffset,
+    LogDebug(5, "Hashin: set %d to %u\n", mht->threadOffset,
             block->b.bucket[bo]);
 
     code =
@@ -1063,7 +1055,7 @@ ht_HashOutT(struct ubik_trans *ut, struct memoryHashTable *mht,
 
 afs_int32
 ht_HashOut(struct ubik_trans *ut, struct memoryHashTable *mht, dbadr ea,
-          void *e) 
+          void *e)
 {
     afs_uint32 hash;
     afs_int32 code;
@@ -1115,7 +1107,7 @@ scanHashTableBlock(struct ubik_trans *ut,
     int entrySize;             /* hashed entry size */
 
     char entry[sizeof(struct block)];
-    dbadr entryAddr, nextEntryAddr;
+    dbadr entryAddr;
 
     int i;
 
@@ -1127,19 +1119,17 @@ scanHashTableBlock(struct ubik_trans *ut,
      */
 
     for (i = 0; (i < nHTBuckets) && (index < length); i++, index++) {  /*f */
-       entryAddr = 0;
-       nextEntryAddr = ntohl(htBlockPtr->bucket[i]);
+       entryAddr = ntohl(htBlockPtr->bucket[i]);
 
        /* if this is the old hash table, all entries below the progress mark
         * should have been moved to the new hash table
         */
-       if (old && (index < mhtPtr->progress) && nextEntryAddr)
+       if (old && (index < mhtPtr->progress) && entryAddr)
            return BUDB_INTERNALERROR;
 
        /* now walk down the chain of each bucket */
-       while (nextEntryAddr) { /*w */
+       while (entryAddr) {     /*w */
 
-           entryAddr = nextEntryAddr;
            if (dbread(ut, entryAddr, &entry[0], entrySize))
                return (BUDB_INTERNALERROR);
 
@@ -1147,7 +1137,7 @@ scanHashTableBlock(struct ubik_trans *ut,
                (*operationFn) (entryAddr, &entry[0], rockPtr);
            }
 
-           nextEntryAddr =
+           entryAddr =
                ntohl(*((dbadr *) (entry + mhtPtr->threadOffset)));
        }                       /*w */
 
@@ -1158,8 +1148,8 @@ scanHashTableBlock(struct ubik_trans *ut,
 
 afs_int32
 scanHashTable(struct ubik_trans *ut, struct memoryHashTable *mhtPtr,
-             int (*selectFn) (dbadr, void *, void *), 
-             int (*operationFn) (dbadr, void *, void *), 
+             int (*selectFn) (dbadr, void *, void *),
+             int (*operationFn) (dbadr, void *, void *),
              void *rockPtr)
 {
     struct htBlock hashTableBlock;