From 354842fbc148e26677d99693793bf5f89f18a085 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 2 Jul 2018 23:38:48 -0700 Subject: Update TinyCBOR to 1b233087a6e6b6be297e69bfcce5ed36f338c91d MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From the fork at https://github.com/thiagomacieira/tinycbor Change-Id: I117816bf0f5e469b8d34fffd153dc88683051208 Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Edward Welbourne --- src/3rdparty/tinycbor/src/cbor.h | 29 ++++++++++++++++++++------- src/3rdparty/tinycbor/src/cborencoder.c | 3 ++- src/3rdparty/tinycbor/src/cborinternal_p.h | 4 ++-- src/3rdparty/tinycbor/src/cborparser.c | 24 +++++++++++++--------- src/3rdparty/tinycbor/src/compilersupport_p.h | 7 ++++--- 5 files changed, 44 insertions(+), 23 deletions(-) (limited to 'src/3rdparty/tinycbor') diff --git a/src/3rdparty/tinycbor/src/cbor.h b/src/3rdparty/tinycbor/src/cbor.h index d7dee0f55b..5c7ba74e39 100644 --- a/src/3rdparty/tinycbor/src/cbor.h +++ b/src/3rdparty/tinycbor/src/cbor.h @@ -234,6 +234,7 @@ typedef struct CborEncoder CborEncoder; static const size_t CborIndefiniteLength = SIZE_MAX; +#ifndef CBOR_NO_ENCODER_API CBOR_API void cbor_encoder_init(CborEncoder *encoder, uint8_t *buffer, size_t size, int flags); CBOR_API void cbor_encoder_init_writer(CborEncoder *encoder, CborEncoderWriteFunction writer, void *); CBOR_API CborError cbor_encode_uint(CborEncoder *encoder, uint64_t value); @@ -280,6 +281,7 @@ CBOR_INLINE_API size_t cbor_encoder_get_extra_bytes_needed(const CborEncoder *en { return encoder->end ? 0 : (size_t)encoder->data.bytes_needed; } +#endif /* CBOR_NO_ENCODER_API */ /* Parser API */ @@ -344,7 +346,8 @@ struct CborValue }; typedef struct CborValue CborValue; -CBOR_API CborError cbor_parser_init(const uint8_t *buffer, size_t size, int flags, CborParser *parser, CborValue *it); +#ifndef CBOR_NO_PARSER_API +CBOR_API CborError cbor_parser_init(const uint8_t *buffer, size_t size, uint32_t flags, CborParser *parser, CborValue *it); CBOR_API CborError cbor_parser_init_reader(const struct CborParserOperations *ops, CborParser *parser, CborValue *it, void *token); CBOR_API CborError cbor_value_validate_basic(const CborValue *it); @@ -464,10 +467,11 @@ CBOR_INLINE_API bool cbor_value_is_text_string(const CborValue *value) CBOR_INLINE_API CborError cbor_value_get_string_length(const CborValue *value, size_t *length) { + uint64_t v; assert(cbor_value_is_byte_string(value) || cbor_value_is_text_string(value)); if (!cbor_value_is_length_known(value)) return CborErrorUnknownLength; - uint64_t v = _cbor_value_extract_int64_helper(value); + v = _cbor_value_extract_int64_helper(value); *length = (size_t)v; if (*length != v) return CborErrorDataTooLarge; @@ -560,10 +564,11 @@ CBOR_INLINE_API bool cbor_value_is_map(const CborValue *value) CBOR_INLINE_API CborError cbor_value_get_array_length(const CborValue *value, size_t *length) { + uint64_t v; assert(cbor_value_is_array(value)); if (!cbor_value_is_length_known(value)) return CborErrorUnknownLength; - uint64_t v = _cbor_value_extract_int64_helper(value); + v = _cbor_value_extract_int64_helper(value); *length = (size_t)v; if (*length != v) return CborErrorDataTooLarge; @@ -572,10 +577,11 @@ CBOR_INLINE_API CborError cbor_value_get_array_length(const CborValue *value, si CBOR_INLINE_API CborError cbor_value_get_map_length(const CborValue *value, size_t *length) { + uint64_t v; assert(cbor_value_is_map(value)); if (!cbor_value_is_length_known(value)) return CborErrorUnknownLength; - uint64_t v = _cbor_value_extract_int64_helper(value); + v = _cbor_value_extract_int64_helper(value); *length = (size_t)v; if (*length != v) return CborErrorDataTooLarge; @@ -601,9 +607,10 @@ CBOR_INLINE_API bool cbor_value_is_float(const CborValue *value) { return value->type == CborFloatType; } CBOR_INLINE_API CborError cbor_value_get_float(const CborValue *value, float *result) { + uint32_t data; assert(cbor_value_is_float(value)); assert(value->flags & CborIteratorFlag_IntegerValueTooLarge); - uint32_t data = (uint32_t)_cbor_value_decode_int64_internal(value); + data = (uint32_t)_cbor_value_decode_int64_internal(value); memcpy(result, &data, sizeof(*result)); return CborNoError; } @@ -612,14 +619,16 @@ CBOR_INLINE_API bool cbor_value_is_double(const CborValue *value) { return value->type == CborDoubleType; } CBOR_INLINE_API CborError cbor_value_get_double(const CborValue *value, double *result) { + uint64_t data; assert(cbor_value_is_double(value)); assert(value->flags & CborIteratorFlag_IntegerValueTooLarge); - uint64_t data = _cbor_value_decode_int64_internal(value); + data = _cbor_value_decode_int64_internal(value); memcpy(result, &data, sizeof(*result)); return CborNoError; } /* Validation API */ +#ifndef CBOR_NO_VALIDATION_API enum CborValidationFlags { /* Bit mapping: @@ -662,9 +671,11 @@ enum CborValidationFlags { CborValidateBasic = 0 }; -CBOR_API CborError cbor_value_validate(const CborValue *it, int flags); +CBOR_API CborError cbor_value_validate(const CborValue *it, uint32_t flags); +#endif /* CBOR_NO_VALIDATION_API */ /* Human-readable (dump) API */ +#ifndef CBOR_NO_PRETTY_API enum CborPrettyFlags { CborPrettyNumericEncodingIndicators = 0x01, @@ -699,6 +710,10 @@ CBOR_INLINE_API CborError cbor_value_to_pretty(FILE *out, const CborValue *value } #endif /* __STDC_HOSTED__ check */ +#endif /* CBOR_NO_PRETTY_API */ + +#endif /* CBOR_NO_PARSER_API */ + #ifdef __cplusplus } #endif diff --git a/src/3rdparty/tinycbor/src/cborencoder.c b/src/3rdparty/tinycbor/src/cborencoder.c index 423591ff65..52a4025be1 100644 --- a/src/3rdparty/tinycbor/src/cborencoder.c +++ b/src/3rdparty/tinycbor/src/cborencoder.c @@ -415,11 +415,12 @@ CborError cbor_encode_simple_value(CborEncoder *encoder, uint8_t value) */ CborError cbor_encode_floating_point(CborEncoder *encoder, CborType fpType, const void *value) { + unsigned size; uint8_t buf[1 + sizeof(uint64_t)]; cbor_assert(fpType == CborHalfFloatType || fpType == CborFloatType || fpType == CborDoubleType); buf[0] = fpType; - unsigned size = 2U << (fpType - CborHalfFloatType); + size = 2U << (fpType - CborHalfFloatType); if (size == 8) put64(buf + 1, *(const uint64_t*)value); else if (size == 4) diff --git a/src/3rdparty/tinycbor/src/cborinternal_p.h b/src/3rdparty/tinycbor/src/cborinternal_p.h index 9546e44d61..8d77f28466 100644 --- a/src/3rdparty/tinycbor/src/cborinternal_p.h +++ b/src/3rdparty/tinycbor/src/cborinternal_p.h @@ -92,8 +92,8 @@ enum { static inline void copy_current_position(CborValue *dst, const CborValue *src) { - // This "if" is here for pedantry only: the two branches should perform - // the same memory operation. + /* This "if" is here for pedantry only: the two branches should perform + * the same memory operation. */ if (src->parser->flags & CborParserFlag_ExternalSource) dst->source.token = src->source.token; else diff --git a/src/3rdparty/tinycbor/src/cborparser.c b/src/3rdparty/tinycbor/src/cborparser.c index 65b0b4b5c8..971230ea61 100644 --- a/src/3rdparty/tinycbor/src/cborparser.c +++ b/src/3rdparty/tinycbor/src/cborparser.c @@ -340,7 +340,7 @@ uint64_t _cbor_value_decode_int64_internal(const CborValue *value) * threads iterating at the same time, but the object can be copied so multiple * threads can iterate. */ -CborError cbor_parser_init(const uint8_t *buffer, size_t size, int flags, CborParser *parser, CborValue *it) +CborError cbor_parser_init(const uint8_t *buffer, size_t size, uint32_t flags, CborParser *parser, CborValue *it) { memset(parser, 0, sizeof(*parser)); parser->source.end = buffer + size; @@ -471,6 +471,9 @@ CborError cbor_value_advance_fixed(CborValue *it) static CborError advance_recursive(CborValue *it, int nestingLevel) { + CborError err; + CborValue recursed; + if (is_fixed_type(it->type)) return advance_internal(it); @@ -483,8 +486,6 @@ static CborError advance_recursive(CborValue *it, int nestingLevel) if (nestingLevel == 0) return CborErrorNestingTooDeep; - CborError err; - CborValue recursed; err = cbor_value_enter_container(it, &recursed); if (err) return err; @@ -810,8 +811,9 @@ CborError cbor_value_leave_container(CborValue *it, const CborValue *recursed) */ CborError cbor_value_get_int64_checked(const CborValue *value, int64_t *result) { + uint64_t v; cbor_assert(cbor_value_is_integer(value)); - uint64_t v = _cbor_value_extract_int64_helper(value); + v = _cbor_value_extract_int64_helper(value); /* Check before converting, as the standard says (C11 6.3.1.3 paragraph 3): * "[if] the new type is signed and the value cannot be represented in it; either the @@ -849,8 +851,9 @@ CborError cbor_value_get_int64_checked(const CborValue *value, int64_t *result) */ CborError cbor_value_get_int_checked(const CborValue *value, int *result) { + uint64_t v; cbor_assert(cbor_value_is_integer(value)); - uint64_t v = _cbor_value_extract_int64_helper(value); + v = _cbor_value_extract_int64_helper(value); /* Check before converting, as the standard says (C11 6.3.1.3 paragraph 3): * "[if] the new type is signed and the value cannot be represented in it; either the @@ -1177,13 +1180,12 @@ static uintptr_t iterate_memcpy(char *dest, const uint8_t *src, size_t len) static CborError iterate_string_chunks(const CborValue *value, char *buffer, size_t *buflen, bool *result, CborValue *next, IterateFunction func) { - cbor_assert(cbor_value_is_byte_string(value) || cbor_value_is_text_string(value)); - CborError err; CborValue tmp; size_t total = 0; const void *ptr; + cbor_assert(cbor_value_is_byte_string(value) || cbor_value_is_text_string(value)); if (!next) next = &tmp; *next = *value; @@ -1320,6 +1322,7 @@ CborError _cbor_value_copy_string(const CborValue *value, void *buffer, */ CborError cbor_value_text_string_equals(const CborValue *value, const char *string, bool *result) { + size_t len; CborValue copy = *value; CborError err = cbor_value_skip_tag(©); if (err) @@ -1329,7 +1332,7 @@ CborError cbor_value_text_string_equals(const CborValue *value, const char *stri return CborNoError; } - size_t len = strlen(string); + len = strlen(string); return iterate_string_chunks(©, CONST_CAST(char *, string), &len, result, NULL, iterate_memcmp); } @@ -1407,9 +1410,10 @@ CborError cbor_value_text_string_equals(const CborValue *value, const char *stri */ CborError cbor_value_map_find_value(const CborValue *map, const char *string, CborValue *element) { - cbor_assert(cbor_value_is_map(map)); + CborError err; size_t len = strlen(string); - CborError err = cbor_value_enter_container(map, element); + cbor_assert(cbor_value_is_map(map)); + err = cbor_value_enter_container(map, element); if (err) goto error; diff --git a/src/3rdparty/tinycbor/src/compilersupport_p.h b/src/3rdparty/tinycbor/src/compilersupport_p.h index d9c8c1f82e..dc4c4cfd8a 100644 --- a/src/3rdparty/tinycbor/src/compilersupport_p.h +++ b/src/3rdparty/tinycbor/src/compilersupport_p.h @@ -213,10 +213,11 @@ static inline unsigned short encode_half(double val) return _cvtss_sh((float)val, 3); #else uint64_t v; + int sign, exp, mant; memcpy(&v, &val, sizeof(v)); - int sign = v >> 63 << 15; - int exp = (v >> 52) & 0x7ff; - int mant = v << 12 >> 12 >> (53-11); /* keep only the 11 most significant bits of the mantissa */ + sign = v >> 63 << 15; + exp = (v >> 52) & 0x7ff; + mant = v << 12 >> 12 >> (53-11); /* keep only the 11 most significant bits of the mantissa */ exp -= 1023; if (exp == 1024) { /* infinity or NaN */ -- cgit v1.2.3