Hi, This syncs lib/libcbor from our v0.5.0+patches to the released v0.7.0
AFAIK the changes are mostly inconsequential to the current uses in-tree (there is a stack exhaustion fix that is worth having), but being at an actual release rather than a frankenpatch will make future updates a bit easier. Major bump because of one API removal. ok? Index: Makefile =================================================================== RCS file: /cvs/src/lib/libcbor/Makefile,v retrieving revision 1.2 diff -u -p -r1.2 Makefile --- Makefile 15 Nov 2019 03:19:39 -0000 1.2 +++ Makefile 30 Jul 2020 04:31:37 -0000 @@ -10,6 +10,7 @@ SRCS= cbor.c WARNINGS=yes CDIAGFLAGS+= -Wall -Wextra -Wno-unused-parameter +CDIAGFLAGS+= -Wno-missing-field-initializers #CDIAGFLAGS+= -Werror # cbor/ Index: README.openbsd =================================================================== RCS file: /cvs/src/lib/libcbor/README.openbsd,v retrieving revision 1.1 diff -u -p -r1.1 README.openbsd --- README.openbsd 14 Nov 2019 21:11:34 -0000 1.1 +++ README.openbsd 30 Jul 2020 04:31:37 -0000 @@ -1,4 +1,4 @@ -This is an import of https://github.com/pjk/libcbor v0.5.0 +This is an import of https://github.com/pjk/libcbor v0.7.0 Apart from README.md and LICENSE.md, only the src/ directory has been imported. Index: shlib_version =================================================================== RCS file: /cvs/src/lib/libcbor/shlib_version,v retrieving revision 1.3 diff -u -p -r1.3 shlib_version --- shlib_version 28 Nov 2019 21:18:16 -0000 1.3 +++ shlib_version 30 Jul 2020 04:31:37 -0000 @@ -1,2 +1,2 @@ -major=0 -minor=6 +major=1 +minor=0 Index: src/allocators.c =================================================================== RCS file: /cvs/src/lib/libcbor/src/allocators.c,v retrieving revision 1.2 diff -u -p -r1.2 allocators.c --- src/allocators.c 28 Nov 2019 02:58:39 -0000 1.2 +++ src/allocators.c 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor.c =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor.c,v retrieving revision 1.2 diff -u -p -r1.2 cbor.c --- src/cbor.c 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor.c 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. @@ -323,8 +323,7 @@ static void _cbor_nested_describe(cbor_i fprintf(out, "%*s[CBOR_TYPE_FLOAT_CTRL] ", indent, " "); if (cbor_float_ctrl_is_ctrl(item)) { if (cbor_is_bool(item)) - fprintf(out, "Bool: %s\n", - cbor_ctrl_is_bool(item) ? "true" : "false"); + fprintf(out, "Bool: %s\n", cbor_get_bool(item) ? "true" : "false"); else if (cbor_is_undef(item)) fprintf(out, "Undefined\n"); else if (cbor_is_null(item)) Index: src/cbor.h =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor.h,v retrieving revision 1.2 diff -u -p -r1.2 cbor.h --- src/cbor.h 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor.h 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/arrays.c =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/arrays.c,v retrieving revision 1.2 diff -u -p -r1.2 arrays.c --- src/cbor/arrays.c 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/arrays.c 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/arrays.h =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/arrays.h,v retrieving revision 1.2 diff -u -p -r1.2 arrays.h --- src/cbor/arrays.h 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/arrays.h 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/bytestrings.c =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/bytestrings.c,v retrieving revision 1.2 diff -u -p -r1.2 bytestrings.c --- src/cbor/bytestrings.c 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/bytestrings.c 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/bytestrings.h =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/bytestrings.h,v retrieving revision 1.2 diff -u -p -r1.2 bytestrings.h --- src/cbor/bytestrings.h 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/bytestrings.h 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/callbacks.c =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/callbacks.c,v retrieving revision 1.2 diff -u -p -r1.2 callbacks.c --- src/cbor/callbacks.c 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/callbacks.c 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/callbacks.h =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/callbacks.h,v retrieving revision 1.2 diff -u -p -r1.2 callbacks.h --- src/cbor/callbacks.h 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/callbacks.h 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/common.c =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/common.c,v retrieving revision 1.2 diff -u -p -r1.2 common.c --- src/cbor/common.c 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/common.c 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/common.h =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/common.h,v retrieving revision 1.2 diff -u -p -r1.2 common.h --- src/cbor/common.h 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/common.h 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/configuration.h =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/configuration.h,v retrieving revision 1.1 diff -u -p -r1.1 configuration.h --- src/cbor/configuration.h 14 Nov 2019 21:11:35 -0000 1.1 +++ src/cbor/configuration.h 30 Jul 2020 04:31:37 -0000 @@ -2,11 +2,12 @@ #define LIBCBOR_CONFIGURATION_H #define CBOR_MAJOR_VERSION 0 -#define CBOR_MINOR_VERSION 5 +#define CBOR_MINOR_VERSION 7 #define CBOR_PATCH_VERSION 0 #define CBOR_CUSTOM_ALLOC 0 #define CBOR_BUFFER_GROWTH 2 +#define CBOR_MAX_STACK_SIZE 2048 #define CBOR_PRETTY_PRINTER 1 #define CBOR_RESTRICT_SPECIFIER restrict Index: src/cbor/configuration.h.in =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/configuration.h.in,v retrieving revision 1.1 diff -u -p -r1.1 configuration.h.in --- src/cbor/configuration.h.in 14 Nov 2019 21:11:35 -0000 1.1 +++ src/cbor/configuration.h.in 30 Jul 2020 04:31:37 -0000 @@ -7,6 +7,7 @@ #cmakedefine01 CBOR_CUSTOM_ALLOC #define CBOR_BUFFER_GROWTH ${CBOR_BUFFER_GROWTH} +#define CBOR_MAX_STACK_SIZE ${CBOR_MAX_STACK_SIZE} #cmakedefine01 CBOR_PRETTY_PRINTER #define CBOR_RESTRICT_SPECIFIER ${CBOR_RESTRICT_SPECIFIER} Index: src/cbor/data.h =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/data.h,v retrieving revision 1.2 diff -u -p -r1.2 data.h --- src/cbor/data.h 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/data.h 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/encoding.c =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/encoding.c,v retrieving revision 1.2 diff -u -p -r1.2 encoding.c --- src/cbor/encoding.c 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/encoding.c 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. @@ -129,20 +129,20 @@ size_t cbor_encode_half(float value, uns /* Assuming value is normalized */ uint32_t val = ((union _cbor_float_helper){.as_float = value}).as_uint; uint16_t res; - uint8_t exp = (uint8_t)((val & 0x7F800000) >> - 23); /* 0b0111_1111_1000_0000_0000_0000_0000_0000 */ + uint8_t exp = (uint8_t)((val & 0x7F800000u) >> + 23u); /* 0b0111_1111_1000_0000_0000_0000_0000_0000 */ uint32_t mant = - val & 0x7FFFFF; /* 0b0000_0000_0111_1111_1111_1111_1111_1111 */ - if (exp == 0xFF) { /* Infinity or NaNs */ + val & 0x7FFFFFu; /* 0b0000_0000_0111_1111_1111_1111_1111_1111 */ + if (exp == 0xFF) { /* Infinity or NaNs */ if (value != value) { - res = (uint16_t)0x00e700; /* Not IEEE semantics - required by CBOR + res = (uint16_t)0x007e00; /* Not IEEE semantics - required by CBOR [s. 3.9] */ } else { - res = - (uint16_t)((val & 0x80000000) >> 16 | 0x7C00 | (mant ? 1 : 0) << 15); + res = (uint16_t)((val & 0x80000000u) >> 16u | 0x7C00u | + (mant ? 1u : 0u) << 15u); } } else if (exp == 0x00) { /* Zeroes or subnorms */ - res = (uint16_t)((val & 0x80000000) >> 16 | mant >> 13); + res = (uint16_t)((val & 0x80000000u) >> 16u | mant >> 13u); } else { /* Normal numbers */ int8_t logical_exp = (int8_t)(exp - 127); assert(logical_exp == exp - 127); @@ -157,12 +157,12 @@ size_t cbor_encode_half(float value, uns /* Offset the remaining decimal places by shifting the significand, the value is lost. This is an implementation decision that works around the absence of standard half-float in the language. */ - res = (uint16_t)(val & 0x80000000) >> 16 | - (uint16_t)(1 << (24 + logical_exp)); + res = (uint16_t)((val & 0x80000000u) >> 16u) | // Extract sign bit + (uint16_t)(1u << (24u + logical_exp)); } else { - res = (uint16_t)((val & 0x80000000) >> 16 | - ((((uint8_t)logical_exp) + 15) << 10) | - (uint16_t)(mant >> 13)); + res = (uint16_t)((val & 0x80000000u) >> 16u | + ((((uint8_t)logical_exp) + 15u) << 10u) | + (uint16_t)(mant >> 13u)); } } return _cbor_encode_uint16(res, buffer, buffer_size, 0xE0); Index: src/cbor/encoding.h =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/encoding.h,v retrieving revision 1.2 diff -u -p -r1.2 encoding.h --- src/cbor/encoding.h 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/encoding.h 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/floats_ctrls.c =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/floats_ctrls.c,v retrieving revision 1.2 diff -u -p -r1.2 floats_ctrls.c --- src/cbor/floats_ctrls.c 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/floats_ctrls.c 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. @@ -58,6 +58,11 @@ double cbor_float_get_float(const cbor_i return NAN; /* Compiler complaints */ } +bool cbor_get_bool(const cbor_item_t *item) { + assert(cbor_is_bool(item)); + return item->metadata.float_ctrl_metadata.ctrl == CBOR_CTRL_TRUE; +} + void cbor_set_float2(cbor_item_t *item, float value) { assert(cbor_is_float(item)); assert(cbor_float_get_width(item) == CBOR_FLOAT_16); @@ -82,9 +87,10 @@ void cbor_set_ctrl(cbor_item_t *item, ui item->metadata.float_ctrl_metadata.ctrl = value; } -bool cbor_ctrl_is_bool(const cbor_item_t *item) { +void cbor_set_bool(cbor_item_t *item, bool value) { assert(cbor_is_bool(item)); - return item->metadata.float_ctrl_metadata.ctrl == CBOR_CTRL_TRUE; + item->metadata.float_ctrl_metadata.ctrl = + value ? CBOR_CTRL_TRUE : CBOR_CTRL_FALSE; } cbor_item_t *cbor_new_ctrl() { Index: src/cbor/floats_ctrls.h =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/floats_ctrls.h,v retrieving revision 1.2 diff -u -p -r1.2 floats_ctrls.h --- src/cbor/floats_ctrls.h 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/floats_ctrls.h 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. @@ -70,6 +70,13 @@ double cbor_float_get_float8(const cbor_ */ double cbor_float_get_float(const cbor_item_t *item); +/** Get value from a boolean ctrl item + * + * @param item[borrow] A ctrl item + * @return boolean value + */ +bool cbor_get_bool(const cbor_item_t *item); + /** Constructs a new ctrl item * * The width cannot be changed once the item is created @@ -134,6 +141,13 @@ cbor_item_t *cbor_build_bool(bool value) */ void cbor_set_ctrl(cbor_item_t *item, uint8_t value); +/** Assign a boolean value to a boolean ctrl item + * + * @param item[borrow] A ctrl item + * @param value The simple value to assign. + */ +void cbor_set_bool(cbor_item_t *item, bool value); + /** Assigns a float value * * @param item[borrow] A half precision float @@ -161,13 +175,6 @@ void cbor_set_float8(cbor_item_t *item, * @return the simple value */ uint8_t cbor_ctrl_value(const cbor_item_t *item); - -/** Is this ctrl item a boolean? - * - * @param item[borrow] A ctrl item - * @return Is this ctrl item a boolean? - */ -bool cbor_ctrl_is_bool(const cbor_item_t *item); /** Constructs a new float * Index: src/cbor/ints.c =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/ints.c,v retrieving revision 1.2 diff -u -p -r1.2 ints.c --- src/cbor/ints.c 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/ints.c 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/ints.h =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/ints.h,v retrieving revision 1.2 diff -u -p -r1.2 ints.h --- src/cbor/ints.h 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/ints.h 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/maps.c =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/maps.c,v retrieving revision 1.2 diff -u -p -r1.2 maps.c --- src/cbor/maps.c 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/maps.c 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/maps.h =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/maps.h,v retrieving revision 1.2 diff -u -p -r1.2 maps.h --- src/cbor/maps.h 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/maps.h 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/serialization.c =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/serialization.c,v retrieving revision 1.2 diff -u -p -r1.2 serialization.c --- src/cbor/serialization.c 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/serialization.c 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/serialization.h =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/serialization.h,v retrieving revision 1.2 diff -u -p -r1.2 serialization.h --- src/cbor/serialization.h 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/serialization.h 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/streaming.c =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/streaming.c,v retrieving revision 1.2 diff -u -p -r1.2 streaming.c --- src/cbor/streaming.c 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/streaming.c 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/streaming.h =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/streaming.h,v retrieving revision 1.2 diff -u -p -r1.2 streaming.h --- src/cbor/streaming.h 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/streaming.h 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/strings.c =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/strings.c,v retrieving revision 1.2 diff -u -p -r1.2 strings.c --- src/cbor/strings.c 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/strings.c 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. @@ -91,9 +91,9 @@ bool cbor_string_add_chunk(cbor_item_t * return false; } - size_t new_chunk_capacity = data->chunk_capacity == 0 - ? 1 - : CBOR_BUFFER_GROWTH * (data->chunk_capacity); + size_t new_chunk_capacity = + data->chunk_capacity == 0 ? 1 + : CBOR_BUFFER_GROWTH * (data->chunk_capacity); cbor_item_t **new_chunks_data = _cbor_realloc_multiple( data->chunks, sizeof(cbor_item_t *), new_chunk_capacity); Index: src/cbor/strings.h =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/strings.h,v retrieving revision 1.2 diff -u -p -r1.2 strings.h --- src/cbor/strings.h 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/strings.h 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/tags.c =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/tags.c,v retrieving revision 1.2 diff -u -p -r1.2 tags.c --- src/cbor/tags.c 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/tags.c 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/tags.h =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/tags.h,v retrieving revision 1.2 diff -u -p -r1.2 tags.h --- src/cbor/tags.h 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/tags.h 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/internal/builder_callbacks.c =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/internal/builder_callbacks.c,v retrieving revision 1.2 diff -u -p -r1.2 builder_callbacks.c --- src/cbor/internal/builder_callbacks.c 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/internal/builder_callbacks.c 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. @@ -87,8 +87,7 @@ void _cbor_builder_append(cbor_item_t *i } } -// TODO: refactor this to take the parameter name, this is way too magical -#define CHECK_RES \ +#define CHECK_RES(ctx, res) \ do { \ if (res == NULL) { \ ctx->creation_failed = true; \ @@ -96,10 +95,18 @@ void _cbor_builder_append(cbor_item_t *i } \ } while (0) +#define PUSH_CTX_STACK(ctx, res, subitems) \ + do { \ + if (_cbor_stack_push(ctx->stack, res, subitems) == NULL) { \ + cbor_decref(&res); \ + ctx->creation_failed = true; \ + } \ + } while (0) + void cbor_builder_uint8_callback(void *context, uint8_t value) { struct _cbor_decoder_context *ctx = context; cbor_item_t *res = cbor_new_int8(); - CHECK_RES; + CHECK_RES(ctx, res); cbor_mark_uint(res); cbor_set_uint8(res, value); _cbor_builder_append(res, ctx); @@ -108,7 +115,7 @@ void cbor_builder_uint8_callback(void *c void cbor_builder_uint16_callback(void *context, uint16_t value) { struct _cbor_decoder_context *ctx = context; cbor_item_t *res = cbor_new_int16(); - CHECK_RES; + CHECK_RES(ctx, res); cbor_mark_uint(res); cbor_set_uint16(res, value); _cbor_builder_append(res, ctx); @@ -117,7 +124,7 @@ void cbor_builder_uint16_callback(void * void cbor_builder_uint32_callback(void *context, uint32_t value) { struct _cbor_decoder_context *ctx = context; cbor_item_t *res = cbor_new_int32(); - CHECK_RES; + CHECK_RES(ctx, res); cbor_mark_uint(res); cbor_set_uint32(res, value); _cbor_builder_append(res, ctx); @@ -126,7 +133,7 @@ void cbor_builder_uint32_callback(void * void cbor_builder_uint64_callback(void *context, uint64_t value) { struct _cbor_decoder_context *ctx = context; cbor_item_t *res = cbor_new_int64(); - CHECK_RES; + CHECK_RES(ctx, res); cbor_mark_uint(res); cbor_set_uint64(res, value); _cbor_builder_append(res, ctx); @@ -135,7 +142,7 @@ void cbor_builder_uint64_callback(void * void cbor_builder_negint8_callback(void *context, uint8_t value) { struct _cbor_decoder_context *ctx = context; cbor_item_t *res = cbor_new_int8(); - CHECK_RES; + CHECK_RES(ctx, res); cbor_mark_negint(res); cbor_set_uint8(res, value); _cbor_builder_append(res, ctx); @@ -152,7 +159,7 @@ void cbor_builder_negint16_callback(void void cbor_builder_negint32_callback(void *context, uint32_t value) { struct _cbor_decoder_context *ctx = context; cbor_item_t *res = cbor_new_int32(); - CHECK_RES; + CHECK_RES(ctx, res); cbor_mark_negint(res); cbor_set_uint32(res, value); _cbor_builder_append(res, ctx); @@ -161,7 +168,7 @@ void cbor_builder_negint32_callback(void void cbor_builder_negint64_callback(void *context, uint64_t value) { struct _cbor_decoder_context *ctx = context; cbor_item_t *res = cbor_new_int64(); - CHECK_RES; + CHECK_RES(ctx, res); cbor_mark_negint(res); cbor_set_uint64(res, value); _cbor_builder_append(res, ctx); @@ -202,8 +209,8 @@ void cbor_builder_byte_string_callback(v void cbor_builder_byte_string_start_callback(void *context) { struct _cbor_decoder_context *ctx = context; cbor_item_t *res = cbor_new_indefinite_bytestring(); - CHECK_RES; - _cbor_stack_push(ctx->stack, res, 0); + CHECK_RES(ctx, res); + PUSH_CTX_STACK(ctx, res, 0); } void cbor_builder_string_callback(void *context, cbor_data data, @@ -228,6 +235,11 @@ void cbor_builder_string_callback(void * memcpy(new_handle, data, length); cbor_item_t *res = cbor_new_definite_string(); + if (res == NULL) { + _CBOR_FREE(new_handle); + ctx->creation_failed = true; + return; + } cbor_string_set_handle(res, new_handle, length); res->metadata.string_metadata.codepoint_count = codepoint_count; @@ -247,16 +259,16 @@ void cbor_builder_string_callback(void * void cbor_builder_string_start_callback(void *context) { struct _cbor_decoder_context *ctx = context; cbor_item_t *res = cbor_new_indefinite_string(); - CHECK_RES; - _cbor_stack_push(ctx->stack, res, 0); + CHECK_RES(ctx, res); + PUSH_CTX_STACK(ctx, res, 0); } void cbor_builder_array_start_callback(void *context, size_t size) { struct _cbor_decoder_context *ctx = context; cbor_item_t *res = cbor_new_definite_array(size); - CHECK_RES; + CHECK_RES(ctx, res); if (size > 0) { - _cbor_stack_push(ctx->stack, res, size); + PUSH_CTX_STACK(ctx, res, size); } else { _cbor_builder_append(res, ctx); } @@ -265,23 +277,23 @@ void cbor_builder_array_start_callback(v void cbor_builder_indef_array_start_callback(void *context) { struct _cbor_decoder_context *ctx = context; cbor_item_t *res = cbor_new_indefinite_array(); - CHECK_RES; - _cbor_stack_push(ctx->stack, res, 0); + CHECK_RES(ctx, res); + PUSH_CTX_STACK(ctx, res, 0); } void cbor_builder_indef_map_start_callback(void *context) { struct _cbor_decoder_context *ctx = context; cbor_item_t *res = cbor_new_indefinite_map(); - CHECK_RES; - _cbor_stack_push(ctx->stack, res, 0); + CHECK_RES(ctx, res); + PUSH_CTX_STACK(ctx, res, 0); } void cbor_builder_map_start_callback(void *context, size_t size) { struct _cbor_decoder_context *ctx = context; cbor_item_t *res = cbor_new_definite_map(size); - CHECK_RES; + CHECK_RES(ctx, res); if (size > 0) { - _cbor_stack_push(ctx->stack, res, size * 2); + PUSH_CTX_STACK(ctx, res, size * 2); } else { _cbor_builder_append(res, ctx); } @@ -335,7 +347,7 @@ void cbor_builder_float2_callback(void * void cbor_builder_float4_callback(void *context, float value) { struct _cbor_decoder_context *ctx = context; cbor_item_t *res = cbor_new_float4(); - CHECK_RES; + CHECK_RES(ctx, res); cbor_set_float4(res, value); _cbor_builder_append(res, ctx); } @@ -343,7 +355,7 @@ void cbor_builder_float4_callback(void * void cbor_builder_float8_callback(void *context, double value) { struct _cbor_decoder_context *ctx = context; cbor_item_t *res = cbor_new_float8(); - CHECK_RES; + CHECK_RES(ctx, res); cbor_set_float8(res, value); _cbor_builder_append(res, ctx); } @@ -351,27 +363,27 @@ void cbor_builder_float8_callback(void * void cbor_builder_null_callback(void *context) { struct _cbor_decoder_context *ctx = context; cbor_item_t *res = cbor_new_null(); - CHECK_RES; + CHECK_RES(ctx, res); _cbor_builder_append(res, ctx); } void cbor_builder_undefined_callback(void *context) { struct _cbor_decoder_context *ctx = context; cbor_item_t *res = cbor_new_undef(); - CHECK_RES; + CHECK_RES(ctx, res); _cbor_builder_append(res, ctx); } void cbor_builder_boolean_callback(void *context, bool value) { struct _cbor_decoder_context *ctx = context; cbor_item_t *res = cbor_build_bool(value); - CHECK_RES; + CHECK_RES(ctx, res); _cbor_builder_append(res, ctx); } void cbor_builder_tag_callback(void *context, uint64_t value) { struct _cbor_decoder_context *ctx = context; cbor_item_t *res = cbor_new_tag(value); - CHECK_RES; - _cbor_stack_push(ctx->stack, res, 1); + CHECK_RES(ctx, res); + PUSH_CTX_STACK(ctx, res, 1); } Index: src/cbor/internal/builder_callbacks.h =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/internal/builder_callbacks.h,v retrieving revision 1.2 diff -u -p -r1.2 builder_callbacks.h --- src/cbor/internal/builder_callbacks.h 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/internal/builder_callbacks.h 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/internal/encoders.c =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/internal/encoders.c,v retrieving revision 1.2 diff -u -p -r1.2 encoders.c --- src/cbor/internal/encoders.c 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/internal/encoders.c 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. @@ -67,7 +67,7 @@ size_t _cbor_encode_uint64(uint64_t valu buffer[0] = 0x1B + offset; #ifdef IS_BIG_ENDIAN - memcpy(buffer + 1, &value, 8); + memcpy(buffer + 1, &value, 8); #else buffer[1] = value >> 56; buffer[2] = value >> 48; Index: src/cbor/internal/encoders.h =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/internal/encoders.h,v retrieving revision 1.2 diff -u -p -r1.2 encoders.h --- src/cbor/internal/encoders.h 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/internal/encoders.h 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/internal/loaders.c =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/internal/loaders.c,v retrieving revision 1.2 diff -u -p -r1.2 loaders.c --- src/cbor/internal/loaders.c 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/internal/loaders.c 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/internal/loaders.h =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/internal/loaders.h,v retrieving revision 1.2 diff -u -p -r1.2 loaders.h --- src/cbor/internal/loaders.h 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/internal/loaders.h 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/internal/memory_utils.c =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/internal/memory_utils.c,v retrieving revision 1.2 diff -u -p -r1.2 memory_utils.c --- src/cbor/internal/memory_utils.c 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/internal/memory_utils.c 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/internal/memory_utils.h =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/internal/memory_utils.h,v retrieving revision 1.2 diff -u -p -r1.2 memory_utils.h --- src/cbor/internal/memory_utils.h 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/internal/memory_utils.h 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/internal/stack.c =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/internal/stack.c,v retrieving revision 1.2 diff -u -p -r1.2 stack.c --- src/cbor/internal/stack.c 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/internal/stack.c 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. @@ -21,6 +21,7 @@ void _cbor_stack_pop(struct _cbor_stack struct _cbor_stack_record *_cbor_stack_push(struct _cbor_stack *stack, cbor_item_t *item, size_t subitems) { + if (stack->size == CBOR_MAX_STACK_SIZE) return NULL; struct _cbor_stack_record *new_top = _CBOR_MALLOC(sizeof(struct _cbor_stack_record)); if (new_top == NULL) return NULL; Index: src/cbor/internal/stack.h =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/internal/stack.h,v retrieving revision 1.2 diff -u -p -r1.2 stack.h --- src/cbor/internal/stack.h 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/internal/stack.h 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/internal/unicode.c =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/internal/unicode.c,v retrieving revision 1.2 diff -u -p -r1.2 unicode.c --- src/cbor/internal/unicode.c 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/internal/unicode.c 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. Index: src/cbor/internal/unicode.h =================================================================== RCS file: /cvs/src/lib/libcbor/src/cbor/internal/unicode.h,v retrieving revision 1.2 diff -u -p -r1.2 unicode.h --- src/cbor/internal/unicode.h 28 Nov 2019 02:58:39 -0000 1.2 +++ src/cbor/internal/unicode.h 30 Jul 2020 04:31:37 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2019 Pavel Kalvoda <m...@pavelkalvoda.com> + * Copyright (c) 2014-2020 Pavel Kalvoda <m...@pavelkalvoda.com> * * libcbor is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details.