summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pb.h5
-rw-r--r--pb_decode.c7
-rw-r--r--pb_encode.c8
3 files changed, 16 insertions, 4 deletions
diff --git a/pb.h b/pb.h
index ea94efc5..502958be 100644
--- a/pb.h
+++ b/pb.h
@@ -17,6 +17,11 @@
#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.
diff --git a/pb_decode.c b/pb_decode.c
index 1e2fea0a..fd234884 100644
--- a/pb_decode.c
+++ b/pb_decode.c
@@ -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);
diff --git a/pb_encode.c b/pb_encode.c
index 804c1a6a..18173735 100644
--- a/pb_encode.c
+++ b/pb_encode.c
@@ -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));
}