Skip to content

Commit

Permalink
Merge pull request #165 from PJK/pedantic
Browse files Browse the repository at this point in the history
Add _CBOR_UNUSED for MSVC, fix a few warnings
  • Loading branch information
PJK committed Oct 25, 2020
2 parents 92d6797 + b1a5ca3 commit 8bfd548
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/cbor/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ static const uint8_t cbor_patch_version = CBOR_PATCH_VERSION;

#ifdef __GNUC__
#define _CBOR_UNUSED(x) __attribute__((__unused__)) x
#elif defined(_MSC_VER)
#define _CBOR_UNUSED(x) __pragma(warning(suppress : 4100 4101)) x
#else
#define _CBOR_UNUSED(x) x
#endif
Expand Down
28 changes: 14 additions & 14 deletions src/cbor/internal/encoders.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ size_t _cbor_encode_uint16(uint16_t value, unsigned char *buffer,
#ifdef IS_BIG_ENDIAN
memcpy(buffer + 1, &value, 2);
#else
buffer[1] = value >> 8;
buffer[2] = value;
buffer[1] = (unsigned char)(value >> 8);
buffer[2] = (unsigned char)value;
#endif

return 3;
Expand All @@ -50,10 +50,10 @@ size_t _cbor_encode_uint32(uint32_t value, unsigned char *buffer,
#ifdef IS_BIG_ENDIAN
memcpy(buffer + 1, &value, 4);
#else
buffer[1] = value >> 24;
buffer[2] = value >> 16;
buffer[3] = value >> 8;
buffer[4] = value;
buffer[1] = (unsigned char)(value >> 24);
buffer[2] = (unsigned char)(value >> 16);
buffer[3] = (unsigned char)(value >> 8);
buffer[4] = (unsigned char)value;
#endif

return 5;
Expand All @@ -69,14 +69,14 @@ size_t _cbor_encode_uint64(uint64_t value, unsigned char *buffer,
#ifdef IS_BIG_ENDIAN
memcpy(buffer + 1, &value, 8);
#else
buffer[1] = value >> 56;
buffer[2] = value >> 48;
buffer[3] = value >> 40;
buffer[4] = value >> 32;
buffer[5] = value >> 24;
buffer[6] = value >> 16;
buffer[7] = value >> 8;
buffer[8] = value;
buffer[1] = (unsigned char)(value >> 56);
buffer[2] = (unsigned char)(value >> 48);
buffer[3] = (unsigned char)(value >> 40);
buffer[4] = (unsigned char)(value >> 32);
buffer[5] = (unsigned char)(value >> 24);
buffer[6] = (unsigned char)(value >> 16);
buffer[7] = (unsigned char)(value >> 8);
buffer[8] = (unsigned char)value;
#endif

return 9;
Expand Down
2 changes: 1 addition & 1 deletion src/cbor/internal/loaders.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ float _cbor_decode_half(unsigned char *halfp) {
return (float)(half & 0x8000 ? -val : val);
}

double _cbor_load_half(cbor_data source) {
float _cbor_load_half(cbor_data source) {
/* Discard const */
return _cbor_decode_half((unsigned char *)source);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cbor/internal/loaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ uint32_t _cbor_load_uint32(const unsigned char *source);

uint64_t _cbor_load_uint64(const unsigned char *source);

double _cbor_load_half(cbor_data source);
float _cbor_load_half(cbor_data source);

float _cbor_load_float(cbor_data source);

Expand Down

0 comments on commit 8bfd548

Please sign in to comment.