Welcome to little lamb

Code » limb » commit 915439d

Silence some warnings

author Olivier Brunel
2023-03-31 14:32:50 UTC
committer Olivier Brunel
2023-05-20 18:06:34 UTC
parent 5578179c5087e876cf590a91b8da701f9a5bfc17

Silence some warnings

src/liblimb/buffer.h/buffer_puthex.c +1 -1
src/liblimb/bytestr.h/byte_str.c +1 -1
src/liblimb/hlookup.h/hlookup.c +11 -12
src/liblimb/hmac.h/hmac.c +1 -1
src/liblimb/hmap.h/hmap_init.c +1 -1
src/liblimb/obuffer.h/obuffers_putmsg.c +1 -1
src/liblimb/samisc.h/saoff2ptr.c +1 -1
src/liblimb/siovec.h/siovec_memcmp.c +1 -1
src/liblimb/siovec.h/siovec_off.c +1 -1

diff --git a/src/liblimb/buffer.h/buffer_puthex.c b/src/liblimb/buffer.h/buffer_puthex.c
index 6076ac4..5e2266d 100644
--- a/src/liblimb/buffer.h/buffer_puthex.c
+++ b/src/liblimb/buffer.h/buffer_puthex.c
@@ -11,7 +11,7 @@ buffer_puthex(buffer *b, const void *data_, size_t dlen)
     ssize_t w = 0;
     char buf[2];
 
-    for (int i = 0; i < dlen; ++i) {
+    for (size_t i = 0; i < dlen; ++i) {
         ssize_t l;
 
         buf[0] = fmtscan_asc(data[i] >> 4);
diff --git a/src/liblimb/bytestr.h/byte_str.c b/src/liblimb/bytestr.h/byte_str.c
index 4bf9961..51aa4c6 100644
--- a/src/liblimb/bytestr.h/byte_str.c
+++ b/src/liblimb/bytestr.h/byte_str.c
@@ -8,5 +8,5 @@ size_t
 byte_str(const char *haystack, size_t hlen, const char *needle, size_t nlen)
 {
     char *s = memmem(haystack, hlen, needle, nlen);
-    return (s) ? s - haystack : hlen;
+    return (s) ? (size_t) (s - haystack) : hlen;
 }
diff --git a/src/liblimb/hlookup.h/hlookup.c b/src/liblimb/hlookup.h/hlookup.c
index 5602a87..84a16cf 100644
--- a/src/liblimb/hlookup.h/hlookup.c
+++ b/src/liblimb/hlookup.h/hlookup.c
@@ -301,18 +301,17 @@ hlookup(u32 *main, u32 *second, const void *data, size_t dlen)
 
         /* last block: affect all 32 bits of (c) */
         switch(dlen) {
-            /* all the case statements fall through until 0 */
-            case 12: c += ((u32) k[11]) << 24;
-            case 11: c += ((u32) k[10]) << 16;
-            case 10: c += ((u32) k[ 9]) <<  8;
-            case  9: c +=        k[ 8];
-            case  8: b += ((u32) k[ 7]) << 24;
-            case  7: b += ((u32) k[ 6]) << 16;
-            case  6: b += ((u32) k[ 5]) <<  8;
-            case  5: b +=        k[ 4];
-            case  4: a += ((u32) k[ 3]) << 24;
-            case  3: a += ((u32) k[ 2]) << 16;
-            case  2: a += ((u32) k[ 1]) <<  8;
+            case 12: c += ((u32) k[11]) << 24; /* fallthrough */
+            case 11: c += ((u32) k[10]) << 16; /* fallthrough */
+            case 10: c += ((u32) k[ 9]) <<  8; /* fallthrough */
+            case  9: c +=        k[ 8];        /* fallthrough */
+            case  8: b += ((u32) k[ 7]) << 24; /* fallthrough */
+            case  7: b += ((u32) k[ 6]) << 16; /* fallthrough */
+            case  6: b += ((u32) k[ 5]) <<  8; /* fallthrough */
+            case  5: b +=        k[ 4];        /* fallthrough */
+            case  4: a += ((u32) k[ 3]) << 24; /* fallthrough */
+            case  3: a += ((u32) k[ 2]) << 16; /* fallthrough */
+            case  2: a += ((u32) k[ 1]) <<  8; /* fallthrough */
             case  1: a +=        k[ 0];
                 break;
             case 0 :
diff --git a/src/liblimb/hmac.h/hmac.c b/src/liblimb/hmac.h/hmac.c
index 9027c4b..f70576a 100644
--- a/src/liblimb/hmac.h/hmac.c
+++ b/src/liblimb/hmac.h/hmac.c
@@ -24,7 +24,7 @@ hmac(char *out, hasher *h, const void *key, size_t klen, const void *msg, size_t
 
     unsigned char buf[h->blen];
 
-    for (int i = 0; i < h->blen; ++i) {
+    for (size_t i = 0; i < h->blen; ++i) {
         buf[i] = secret[i] ^ 0x36;
         secret[i] ^= 0x5c;
     }
diff --git a/src/liblimb/hmap.h/hmap_init.c b/src/liblimb/hmap.h/hmap_init.c
index fddda9e..34b9636 100644
--- a/src/liblimb/hmap.h/hmap_init.c
+++ b/src/liblimb/hmap.h/hmap_init.c
@@ -13,7 +13,7 @@ hmap_init(size_t dlen, size_t n, hmap *hmap)
 
     /* number of elements (n) must be a power of 2 */
     u32 p = msb64((u64) n) - 1;
-    if (n > 1 << p)
+    if (n > 1U << p)
         n = 1 << (p + 1);
 
     hmap->sa = stralloc_zero;
diff --git a/src/liblimb/obuffer.h/obuffers_putmsg.c b/src/liblimb/obuffer.h/obuffers_putmsg.c
index 6e1f630..eedb636 100644
--- a/src/liblimb/obuffer.h/obuffers_putmsg.c
+++ b/src/liblimb/obuffer.h/obuffers_putmsg.c
@@ -7,7 +7,7 @@ void
 obuffers_putmsg(obuffer *obufs, unsigned int nbufs, u8 level,
                 const char * const *as, unsigned int n)
 {
-    for (int i = 0; i < nbufs; ++i)
+    for (unsigned int i = 0; i < nbufs; ++i)
         if (obufs[i].b && level <= obufs[i].lvl)
             buffer_putmsg(obufs[i].b, as, n);
 }
diff --git a/src/liblimb/samisc.h/saoff2ptr.c b/src/liblimb/samisc.h/saoff2ptr.c
index 1d0e1d0..e0053ec 100644
--- a/src/liblimb/samisc.h/saoff2ptr.c
+++ b/src/liblimb/samisc.h/saoff2ptr.c
@@ -8,7 +8,7 @@ void
 saoff2ptr(stralloc *sa, size_t arroff, size_t n)
 {
     uintptr_t *a = (uintptr_t *) (sa->s + arroff);
-    for (int i = 0; i < n; ++i) {
+    for (size_t i = 0; i < n; ++i) {
         /* add the base, and turn this into a proper pointer */
         *a += (uintptr_t) sa->s;
         ++a;
diff --git a/src/liblimb/siovec.h/siovec_memcmp.c b/src/liblimb/siovec.h/siovec_memcmp.c
index 03512a2..6a3f8d5 100644
--- a/src/liblimb/siovec.h/siovec_memcmp.c
+++ b/src/liblimb/siovec.h/siovec_memcmp.c
@@ -9,7 +9,7 @@ siovec_memcmp(const struct iovec *v, unsigned int n, const char *s, size_t len)
 {
     int r = (n) ? 0 : (len) ? -1 : 0;
 
-    for (int i = 0; len && i < n; ++i) {
+    for (unsigned int i = 0; len && i < n; ++i) {
         if (!v[i].iov_len) continue;
 
         size_t l = v[i].iov_len >= len ? len : v[i].iov_len;
diff --git a/src/liblimb/siovec.h/siovec_off.c b/src/liblimb/siovec.h/siovec_off.c
index f829392..f2cc01a 100644
--- a/src/liblimb/siovec.h/siovec_off.c
+++ b/src/liblimb/siovec.h/siovec_off.c
@@ -7,7 +7,7 @@
 int
 siovec_off(const struct iovec *v, unsigned int n, size_t off)
 {
-    for (int i = 0; i < n; ++i) {
+    for (unsigned int i = 0; i < n; ++i) {
         if (v[i].iov_len > off) return ((char *) v[i].iov_base)[off];
         off -= v[i].iov_len;
     }