Fixing compiler warnings, mostly related to unused parameters.

Thanks to David Hotham for the patch. Fixes issue 8.
This commit is contained in:
Petteri Aimonen
2012-04-18 20:15:36 +03:00
parent 9fbe9a5de3
commit d1ca88d20e
3 changed files with 16 additions and 4 deletions

5
pb.h
View File

@@ -17,6 +17,11 @@
#define pb_packed #define pb_packed
#endif #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. /* List of possible field types. These are used in the autogenerated code.
* Least-significant 4 bits tell the scalar type * Least-significant 4 bits tell the scalar type
* Most-significant 4 bits specify repeated/required/packed etc. * Most-significant 4 bits specify repeated/required/packed etc.

View File

@@ -75,7 +75,7 @@ static bool checkreturn pb_decode_varint32(pb_istream_t *stream, uint32_t *dest)
{ {
uint64_t temp; uint64_t temp;
bool status = pb_decode_varint(stream, &temp); bool status = pb_decode_varint(stream, &temp);
*dest = temp; *dest = (uint32_t)temp;
return status; return status;
} }
@@ -448,6 +448,7 @@ static void endian_copy(void *dest, void *src, size_t destsize, size_t srcsize)
#ifdef __BIG_ENDIAN__ #ifdef __BIG_ENDIAN__
memcpy(dest, (char*)src + (srcsize - destsize), destsize); memcpy(dest, (char*)src + (srcsize - destsize), destsize);
#else #else
UNUSED(srcsize);
memcpy(dest, src, destsize); memcpy(dest, src, destsize);
#endif #endif
} }
@@ -480,6 +481,7 @@ bool checkreturn pb_dec_fixed32(pb_istream_t *stream, const pb_field_t *field, v
} }
return status; return status;
#else #else
UNUSED(field);
return pb_read(stream, (uint8_t*)dest, 4); return pb_read(stream, (uint8_t*)dest, 4);
#endif #endif
} }
@@ -496,6 +498,7 @@ bool checkreturn pb_dec_fixed64(pb_istream_t *stream, const pb_field_t *field, v
} }
return status; return status;
#else #else
UNUSED(field);
return pb_read(stream, (uint8_t*)dest, 8); return pb_read(stream, (uint8_t*)dest, 8);
#endif #endif
} }
@@ -524,7 +527,7 @@ bool checkreturn pb_dec_string(pb_istream_t *stream, const pb_field_t *field, vo
return false; return false;
/* Check length, noting the null terminator */ /* Check length, noting the null terminator */
if (size > field->data_size - 1) if (size + 1 > field->data_size)
return false; return false;
status = pb_read(stream, (uint8_t*)dest, size); status = pb_read(stream, (uint8_t*)dest, size);

View 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, static bool checkreturn encode_array(pb_ostream_t *stream, const pb_field_t *field,
const void *pData, size_t count, pb_encoder_t func) const void *pData, size_t count, pb_encoder_t func)
{ {
int i; size_t i;
const void *p; const void *p;
size_t size; size_t size;
@@ -212,7 +212,7 @@ bool checkreturn pb_encode_varint(pb_ostream_t *stream, uint64_t value)
while (value) while (value)
{ {
buffer[i] = (value & 0x7F) | 0x80; buffer[i] = (uint8_t)((value & 0x7F) | 0x80);
value >>= 7; value >>= 7;
i++; 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) 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); return pb_encode_fixed64(stream, src);
} }
bool checkreturn pb_enc_fixed32(pb_ostream_t *stream, const pb_field_t *field, const void *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); return pb_encode_fixed32(stream, src);
} }
bool checkreturn pb_enc_bytes(pb_ostream_t *stream, const pb_field_t *field, const void *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; pb_bytes_array_t *bytes = (pb_bytes_array_t*)src;
UNUSED(field);
return pb_encode_string(stream, bytes->bytes, bytes->size); 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) 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)); return pb_encode_string(stream, (uint8_t*)src, strlen((char*)src));
} }