Fixing compiler warnings, mostly related to unused parameters.
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>
Wed, 18 Apr 2012 17:15:36 +0000 (20:15 +0300)
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>
Wed, 18 Apr 2012 17:15:36 +0000 (20:15 +0300)
Thanks to David Hotham for the patch. Fixes issue 8.

pb.h
pb_decode.c
pb_encode.c

diff --git a/pb.h b/pb.h
index ea94efc..502958b 100644 (file)
--- a/pb.h
+++ b/pb.h
 #define pb_packed
 #endif
 
+/* Handly macro for suppressing unreferenced-parameter compiler warnings.    */
+#ifndef UNUSED
+#define UNUSED(x) (void)(x)
+#endif
+
 /* List of possible field types. These are used in the autogenerated code.
  * Least-significant 4 bits tell the scalar type
  * Most-significant 4 bits specify repeated/required/packed etc.
index 1e2fea0..fd23488 100644 (file)
@@ -75,7 +75,7 @@ static bool checkreturn pb_decode_varint32(pb_istream_t *stream, uint32_t *dest)
 {
     uint64_t temp;
     bool status = pb_decode_varint(stream, &temp);
-    *dest = temp;
+    *dest = (uint32_t)temp;
     return status;
 }
 
@@ -448,6 +448,7 @@ static void endian_copy(void *dest, void *src, size_t destsize, size_t srcsize)
 #ifdef __BIG_ENDIAN__
     memcpy(dest, (char*)src + (srcsize - destsize), destsize);
 #else
+    UNUSED(srcsize);
     memcpy(dest, src, destsize);
 #endif
 }
@@ -480,6 +481,7 @@ bool checkreturn pb_dec_fixed32(pb_istream_t *stream, const pb_field_t *field, v
     }
     return status;
 #else
+    UNUSED(field);
     return pb_read(stream, (uint8_t*)dest, 4);
 #endif
 }
@@ -496,6 +498,7 @@ bool checkreturn pb_dec_fixed64(pb_istream_t *stream, const pb_field_t *field, v
     }
     return status;
 #else
+    UNUSED(field);
     return pb_read(stream, (uint8_t*)dest, 8);
 #endif
 }
@@ -524,7 +527,7 @@ bool checkreturn pb_dec_string(pb_istream_t *stream, const pb_field_t *field, vo
         return false;
     
     /* Check length, noting the null terminator */
-    if (size > field->data_size - 1)
+    if (size + 1 > field->data_size)
         return false;
     
     status = pb_read(stream, (uint8_t*)dest, size);
index 804c1a6..1817373 100644 (file)
@@ -76,7 +76,7 @@ bool checkreturn pb_write(pb_ostream_t *stream, const uint8_t *buf, size_t count
 static bool checkreturn encode_array(pb_ostream_t *stream, const pb_field_t *field,
                          const void *pData, size_t count, pb_encoder_t func)
 {
-    int i;
+    size_t i;
     const void *p;
     size_t size;
     
@@ -212,7 +212,7 @@ bool checkreturn pb_encode_varint(pb_ostream_t *stream, uint64_t value)
     
     while (value)
     {
-        buffer[i] = (value & 0x7F) | 0x80;
+        buffer[i] = (uint8_t)((value & 0x7F) | 0x80);
         value >>= 7;
         i++;
     }
@@ -373,22 +373,26 @@ bool checkreturn pb_enc_svarint(pb_ostream_t *stream, const pb_field_t *field, c
 
 bool checkreturn pb_enc_fixed64(pb_ostream_t *stream, const pb_field_t *field, const void *src)
 {
+    UNUSED(field);
     return pb_encode_fixed64(stream, src);
 }
 
 bool checkreturn pb_enc_fixed32(pb_ostream_t *stream, const pb_field_t *field, const void *src)
 {
+    UNUSED(field);
     return pb_encode_fixed32(stream, src);
 }
 
 bool checkreturn pb_enc_bytes(pb_ostream_t *stream, const pb_field_t *field, const void *src)
 {
     pb_bytes_array_t *bytes = (pb_bytes_array_t*)src;
+    UNUSED(field);
     return pb_encode_string(stream, bytes->bytes, bytes->size);
 }
 
 bool checkreturn pb_enc_string(pb_ostream_t *stream, const pb_field_t *field, const void *src)
 {
+    UNUSED(field);
     return pb_encode_string(stream, (uint8_t*)src, strlen((char*)src));
 }