From: Petteri Aimonen Date: Wed, 18 Apr 2012 17:15:36 +0000 (+0300) Subject: Fixing compiler warnings, mostly related to unused parameters. X-Git-Tag: 3.99.1~14^2~500 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=commitdiff_plain;h=d1ca88d20ec1b205752546a40ef520a392d0002f;hp=9fbe9a5de30c3326bd7015e91c5ba634df49ee25;p=apps%2Flow-level-can-service.git Fixing compiler warnings, mostly related to unused parameters. Thanks to David Hotham for the patch. Fixes issue 8. --- diff --git a/pb.h b/pb.h index ea94efc..502958b 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 1e2fea0..fd23488 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 804c1a6..1817373 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)); }