Closed Bug 21494 Opened 25 years ago Closed 25 years ago

DBM Compiler Warnings Fixed

Categories

(Core Graveyard :: Tracking, defect, P3)

x86
All

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: kiel, Assigned: mcafee)

References

()

Details

(Keywords: verifyme)

Here is a patch to fix the warnings generated when building files in this
directory.  Review and criticism and flames requested; I figured this might be an
ok way to start to help out.

Index: mozilla/dbm/src/h_bigkey.c
===================================================================
RCS file: /cvsroot/mozilla/dbm/src/h_bigkey.c,v
retrieving revision 3.5
diff -u -r3.5 h_bigkey.c
--- h_bigkey.c  1999/07/15 00:17:17     3.5
+++ h_bigkey.c  1999/12/11 08:38:05
@@ -429,7 +429,7 @@
                }

        val->size = collect_data(hashp, bufp, (int)len, set_current);
-       if (val->size == -1)
+       if (val->size + 1 == 0) // unsigned ints are not really negative
                return (-1);
        if (save_p->addr != save_addr) {
                /* We are pretty short on buffers. */
@@ -515,7 +515,7 @@
        int set)
 {
        key->size = collect_key(hashp, bufp, 0, val, set);
-       if (key->size == -1)
+       if (key->size + 1 == 0) // same compile warning about comparing signed
and unsigned
                return (-1);
        key->data = (uint8 *)hashp->tmp_key;
        return (0);
Index: mozilla/dbm/src/h_page.c
===================================================================
RCS file: /cvsroot/mozilla/dbm/src/h_page.c,v
retrieving revision 3.7
diff -u -r3.7 h_page.c
--- h_page.c    1999/07/15 00:58:11     3.7
+++ h_page.c    1999/12/11 08:38:07
@@ -709,7 +709,7 @@
        if (!rsize)
                bp[0] = 0;      /* We hit the EOF, so initialize a new page */
        else
-               if (rsize != size) {
+               if ((unsigned)rsize != size) {
                        errno = EFTYPE;
                        return (-1);
                }
@@ -750,7 +750,7 @@
                         * the maximum number of entries
                         * in the array
                         */
-                               if(max > (size / sizeof(uint16)))
+                               if((unsigned)max > (size / sizeof(uint16)))
                                        return(DATABASE_CORRUPTED_ERROR);

                                /* do the byte order swap
@@ -845,7 +845,7 @@
              * the maximum number of entries
              * in the array
              */
-            if(max > (size / sizeof(uint16)))
+            if((unsigned)max > (size / sizeof(uint16)))
                 return(DATABASE_CORRUPTED_ERROR);

                        for (i = 0; i <= max; i++)
@@ -862,7 +862,7 @@
            ((wsize = write(fd, p, size)) == -1))
                /* Errno is set */
                return (-1);
-       if (wsize != size) {
+       if ((unsigned)wsize != size) {
                errno = EFTYPE;
                return (-1);
        }
@@ -957,7 +957,7 @@

        /* Look through all the free maps to find the first free block */
        first_page = hashp->LAST_FREED >>(hashp->BSHIFT + BYTE_SHIFT);
-       for ( i = first_page; i <= free_page; i++ ) {
+       for ( i = first_page; i <= (unsigned)free_page; i++ ) {
                if (!(freep = (uint32 *)hashp->mapp[i]) &&
                    !(freep = fetch_bitmap(hashp, i)))
                        return (0);
@@ -966,7 +966,7 @@
                else
                        in_use_bits = (hashp->BSIZE << BYTE_SHIFT) - 1;

-               if (i == first_page) {
+               if (i == (unsigned)first_page) {
                        bit = hashp->LAST_FREED &
                            ((hashp->BSIZE << BYTE_SHIFT) - 1);
                        j = bit / BITS_PER_MAP;
@@ -1075,7 +1075,7 @@
                hashp->LAST_FREED = bit - 1;

        /* Calculate the split number for this page */
-       for (i = 0; (i < splitnum) && (bit > hashp->SPARES[i]); i++) {}
+       for (i = 0; (i < (unsigned)splitnum) && (bit > hashp->SPARES[i]); i++) {}
        offset = (i ? bit - hashp->SPARES[i - 1] : bit);
        if (offset >= SPLITMASK)
                return (0);     /* Out of overflow pages */
@@ -1110,7 +1110,7 @@
        ndx = (((uint16)addr) >> SPLITSHIFT);
        bit_address =
            (ndx ? hashp->SPARES[ndx - 1] : 0) + (addr & SPLITMASK) - 1;
-        if (bit_address < hashp->LAST_FREED)
+        if (bit_address < (unsigned)hashp->LAST_FREED)
                hashp->LAST_FREED = bit_address;
        free_page = (bit_address >> (hashp->BSHIFT + BYTE_SHIFT));
        free_bit = bit_address & ((hashp->BSIZE << BYTE_SHIFT) - 1);
@@ -1202,7 +1202,7 @@
 static uint32 *
 fetch_bitmap(HTAB *hashp, uint32 ndx)
 {
-       if (ndx >= hashp->nmaps)
+       if (ndx >= (unsigned)hashp->nmaps)
                return (NULL);
        if ((hashp->mapp[ndx] = (uint32 *)malloc((size_t)hashp->BSIZE)) == NULL)
                return (NULL);
Index: mozilla/dbm/src/hash.c
===================================================================
RCS file: /cvsroot/mozilla/dbm/src/hash.c,v
retrieving revision 3.8
diff -u -r3.8 hash.c
--- hash.c      1999/07/15 00:17:18     3.8
+++ hash.c      1999/12/11 08:38:09
@@ -232,7 +232,7 @@
                if (hashp->VERSION != HASHVERSION &&
                    hashp->VERSION != OLDHASHVERSION)
                        RETURN_ERROR(EFTYPE, error1);
-               if (hashp->hash(CHARKEY, sizeof(CHARKEY)) != hashp->H_CHARKEY)
+               if (hashp->hash(CHARKEY, sizeof(CHARKEY)) != (unsigned)hashp->
H_CHARKEY)
                        RETURN_ERROR(EFTYPE, error1);
                if (hashp->NKEYS < 0) {
                    /*
@@ -789,7 +789,7 @@

                if (bp[1] >= REAL_KEY) {
                        /* Real key/data pair */
-                       if (size == off - *bp &&
+                       if (size == (unsigned)(off - *bp) &&
                            memcmp(kp, rbufp->page + *bp, size) == 0)
                                goto found;
                        off = bp[1];
@@ -933,7 +933,7 @@
        for (bp = NULL; !bp || !bp[0]; ) {
                if (!(bufp = hashp->cpage)) {
                        for (bucket = hashp->cbucket;
-                           bucket <= hashp->MAX_BUCKET;
+                           bucket <= (unsigned)hashp->MAX_BUCKET;
                            bucket++, hashp->cndx = 1) {
                                bufp = __get_buf(hashp, bucket, NULL, 0);
                                if (!bufp)
@@ -1037,7 +1037,7 @@
                hashp->OVFL_POINT = spare_ndx;
        }

-       if (new_bucket > hashp->HIGH_MASK) {
+       if (new_bucket > (unsigned)hashp->HIGH_MASK) {
                /* Starting a new doubling */
                hashp->LOW_MASK = hashp->HIGH_MASK;
                hashp->HIGH_MASK = new_bucket | hashp->LOW_MASK;
@@ -1073,7 +1073,7 @@

        n = hashp->hash(k, len);
        bucket = n & hashp->HIGH_MASK;
-       if (bucket > hashp->MAX_BUCKET)
+       if (bucket > (unsigned)hashp->MAX_BUCKET)
                bucket = bucket & hashp->LOW_MASK;
        return (bucket);
 }
Sorry, that was really ugly.  I missed one as well.  The patch is in the url.
Assignee: chofmann → mcafee
kiel,
yes, this is a great way to help out!  thanks for the
contribution.  There are some extra steps that will help
to speed the evaluation and check in of your contributions.
You can "look up" the "owner(s)" of any source module/file
on our LXR query tool, and assign the patch bug report directly
to them.

In this case the steps are
goto http:lxr.mozilla.org
click on project seamokey
enter filename "h_bigkey.c"
click on the returned link
ask for cvs log or cvs blame to see the code owners...

assign the bug directly to someone familiar with the code.

in this case looks like mcafee might be able to help out.

GREAT WORK!  thanks for the contribution.

chris h.

http://cvs-mirror.mozilla.org/webtools/bonsai/cvslog.cgi?file=mozilla/dbm/src/h_
bigkey.c
Target Milestone: M13
I'll look at this after m12
Target Milestone: M13 → M15
cls, do we care about dbm?  This is going away, right?

Patch does some funny math that makes the code
hard to read, not sure I'm willing to trade readability
for warnings on FreeBSD-only.
Well, dbm was actually gone....for about a week.  Warren & fur said that it
would be needed for the netcache so I added it back to the build.

I see those warnings under linux using gcc 2.95.2 as well.  The patch fixes them
for me and the logic looks right but I'm waiting for the rest of my tree to
build before giving it the r=.
OS: FreeBSD → All
r=cls
Status: NEW → RESOLVED
Closed: 25 years ago
Resolution: --- → FIXED
checked in.
QA no need to verify
Adding verifyme keyword.
Keywords: verifyme
Marking Verified per mcafee comment.
Status: RESOLVED → VERIFIED
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.