summaryrefslogtreecommitdiffstats
path: root/lib/libcbor/src
diff options
context:
space:
mode:
authordjm <djm@openbsd.org>2020-08-03 02:34:31 +0000
committerdjm <djm@openbsd.org>2020-08-03 02:34:31 +0000
commitd3425be1b595f829612797540c858ad1f176643f (patch)
treeeee6a023293527d42c6ef171bd3b61a48cda344b /lib/libcbor/src
parentSplit some code that gives clang10 heartburn (diff)
downloadwireguard-openbsd-d3425be1b595f829612797540c858ad1f176643f.tar.xz
wireguard-openbsd-d3425be1b595f829612797540c858ad1f176643f.zip
sync to upstream libcbor v0.7.0; some minor fixes, but a note major
crank due to ABI change.
Diffstat (limited to 'lib/libcbor/src')
-rw-r--r--lib/libcbor/src/allocators.c2
-rw-r--r--lib/libcbor/src/cbor.c5
-rw-r--r--lib/libcbor/src/cbor.h2
-rw-r--r--lib/libcbor/src/cbor/arrays.c2
-rw-r--r--lib/libcbor/src/cbor/arrays.h2
-rw-r--r--lib/libcbor/src/cbor/bytestrings.c2
-rw-r--r--lib/libcbor/src/cbor/bytestrings.h2
-rw-r--r--lib/libcbor/src/cbor/callbacks.c2
-rw-r--r--lib/libcbor/src/cbor/callbacks.h2
-rw-r--r--lib/libcbor/src/cbor/common.c2
-rw-r--r--lib/libcbor/src/cbor/common.h2
-rw-r--r--lib/libcbor/src/cbor/configuration.h3
-rw-r--r--lib/libcbor/src/cbor/configuration.h.in1
-rw-r--r--lib/libcbor/src/cbor/data.h2
-rw-r--r--lib/libcbor/src/cbor/encoding.c28
-rw-r--r--lib/libcbor/src/cbor/encoding.h2
-rw-r--r--lib/libcbor/src/cbor/floats_ctrls.c12
-rw-r--r--lib/libcbor/src/cbor/floats_ctrls.h23
-rw-r--r--lib/libcbor/src/cbor/internal/builder_callbacks.c70
-rw-r--r--lib/libcbor/src/cbor/internal/builder_callbacks.h2
-rw-r--r--lib/libcbor/src/cbor/internal/encoders.c4
-rw-r--r--lib/libcbor/src/cbor/internal/encoders.h2
-rw-r--r--lib/libcbor/src/cbor/internal/loaders.c2
-rw-r--r--lib/libcbor/src/cbor/internal/loaders.h2
-rw-r--r--lib/libcbor/src/cbor/internal/memory_utils.c2
-rw-r--r--lib/libcbor/src/cbor/internal/memory_utils.h2
-rw-r--r--lib/libcbor/src/cbor/internal/stack.c3
-rw-r--r--lib/libcbor/src/cbor/internal/stack.h2
-rw-r--r--lib/libcbor/src/cbor/internal/unicode.c2
-rw-r--r--lib/libcbor/src/cbor/internal/unicode.h2
-rw-r--r--lib/libcbor/src/cbor/ints.c2
-rw-r--r--lib/libcbor/src/cbor/ints.h2
-rw-r--r--lib/libcbor/src/cbor/maps.c2
-rw-r--r--lib/libcbor/src/cbor/maps.h2
-rw-r--r--lib/libcbor/src/cbor/serialization.c2
-rw-r--r--lib/libcbor/src/cbor/serialization.h2
-rw-r--r--lib/libcbor/src/cbor/streaming.c2
-rw-r--r--lib/libcbor/src/cbor/streaming.h2
-rw-r--r--lib/libcbor/src/cbor/strings.c8
-rw-r--r--lib/libcbor/src/cbor/strings.h2
-rw-r--r--lib/libcbor/src/cbor/tags.c2
-rw-r--r--lib/libcbor/src/cbor/tags.h2
42 files changed, 124 insertions, 97 deletions
diff --git a/lib/libcbor/src/allocators.c b/lib/libcbor/src/allocators.c
index 230306823f7..273e09321a6 100644
--- a/lib/libcbor/src/allocators.c
+++ b/lib/libcbor/src/allocators.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor.c b/lib/libcbor/src/cbor.c
index b0b9dfd6cf5..24e5aa3d7f3 100644
--- a/lib/libcbor/src/cbor.c
+++ b/lib/libcbor/src/cbor.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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_item_t *item, FILE *out, int indent) {
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))
diff --git a/lib/libcbor/src/cbor.h b/lib/libcbor/src/cbor.h
index 5bf78e2e416..f4dfc9e3d75 100644
--- a/lib/libcbor/src/cbor.h
+++ b/lib/libcbor/src/cbor.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/arrays.c b/lib/libcbor/src/cbor/arrays.c
index 8a86cf102b7..c1d01afafee 100644
--- a/lib/libcbor/src/cbor/arrays.c
+++ b/lib/libcbor/src/cbor/arrays.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/arrays.h b/lib/libcbor/src/cbor/arrays.h
index 1e68689f462..38519750442 100644
--- a/lib/libcbor/src/cbor/arrays.h
+++ b/lib/libcbor/src/cbor/arrays.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/bytestrings.c b/lib/libcbor/src/cbor/bytestrings.c
index 3b96eeb34fa..75a737bd92a 100644
--- a/lib/libcbor/src/cbor/bytestrings.c
+++ b/lib/libcbor/src/cbor/bytestrings.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/bytestrings.h b/lib/libcbor/src/cbor/bytestrings.h
index a133f949edb..9f9322ca260 100644
--- a/lib/libcbor/src/cbor/bytestrings.h
+++ b/lib/libcbor/src/cbor/bytestrings.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/callbacks.c b/lib/libcbor/src/cbor/callbacks.c
index 6f868f1b793..7d0f1c62a75 100644
--- a/lib/libcbor/src/cbor/callbacks.c
+++ b/lib/libcbor/src/cbor/callbacks.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/callbacks.h b/lib/libcbor/src/cbor/callbacks.h
index f789e5cef08..1d37f3ee865 100644
--- a/lib/libcbor/src/cbor/callbacks.h
+++ b/lib/libcbor/src/cbor/callbacks.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/common.c b/lib/libcbor/src/cbor/common.c
index 9c1239d53ab..7ccce38ac25 100644
--- a/lib/libcbor/src/cbor/common.c
+++ b/lib/libcbor/src/cbor/common.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/common.h b/lib/libcbor/src/cbor/common.h
index fbe3e5719c3..d54a23cc81e 100644
--- a/lib/libcbor/src/cbor/common.h
+++ b/lib/libcbor/src/cbor/common.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/configuration.h b/lib/libcbor/src/cbor/configuration.h
index 3a8adf6a902..8e4e3be4bff 100644
--- a/lib/libcbor/src/cbor/configuration.h
+++ b/lib/libcbor/src/cbor/configuration.h
@@ -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
diff --git a/lib/libcbor/src/cbor/configuration.h.in b/lib/libcbor/src/cbor/configuration.h.in
index b81a0e64185..6f65980aa8a 100644
--- a/lib/libcbor/src/cbor/configuration.h.in
+++ b/lib/libcbor/src/cbor/configuration.h.in
@@ -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}
diff --git a/lib/libcbor/src/cbor/data.h b/lib/libcbor/src/cbor/data.h
index df0eb953083..7f703bc0635 100644
--- a/lib/libcbor/src/cbor/data.h
+++ b/lib/libcbor/src/cbor/data.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/encoding.c b/lib/libcbor/src/cbor/encoding.c
index 341d9290f34..19281520edd 100644
--- a/lib/libcbor/src/cbor/encoding.c
+++ b/lib/libcbor/src/cbor/encoding.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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, unsigned char *buffer,
/* 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, unsigned char *buffer,
/* 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);
diff --git a/lib/libcbor/src/cbor/encoding.h b/lib/libcbor/src/cbor/encoding.h
index 8261467215e..34a7382758a 100644
--- a/lib/libcbor/src/cbor/encoding.h
+++ b/lib/libcbor/src/cbor/encoding.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/floats_ctrls.c b/lib/libcbor/src/cbor/floats_ctrls.c
index 1da8ed66771..b7e5fcef853 100644
--- a/lib/libcbor/src/cbor/floats_ctrls.c
+++ b/lib/libcbor/src/cbor/floats_ctrls.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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_item_t *item) {
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, uint8_t value) {
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() {
diff --git a/lib/libcbor/src/cbor/floats_ctrls.h b/lib/libcbor/src/cbor/floats_ctrls.h
index 83cb75acd6e..7e60620395e 100644
--- a/lib/libcbor/src/cbor/floats_ctrls.h
+++ b/lib/libcbor/src/cbor/floats_ctrls.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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_item_t *item);
*/
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
@@ -162,13 +176,6 @@ void cbor_set_float8(cbor_item_t *item, double 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
*
* @param value the value to use
diff --git a/lib/libcbor/src/cbor/internal/builder_callbacks.c b/lib/libcbor/src/cbor/internal/builder_callbacks.c
index bd445bd1ee8..f6c57113616 100644
--- a/lib/libcbor/src/cbor/internal/builder_callbacks.c
+++ b/lib/libcbor/src/cbor/internal/builder_callbacks.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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 *item,
}
}
-// 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 *item,
} \
} 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 *context, uint8_t value) {
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 *context, uint16_t value) {
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 *context, uint32_t value) {
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 *context, uint64_t value) {
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 *context, uint16_t value) {
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 *context, uint32_t value) {
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(void *context, cbor_data data,
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 *context, cbor_data data,
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 *context, cbor_data data,
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(void *context, size_t size) {
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 *context, float value) {
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 *context, float value) {
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 *context, double value) {
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);
}
diff --git a/lib/libcbor/src/cbor/internal/builder_callbacks.h b/lib/libcbor/src/cbor/internal/builder_callbacks.h
index 66eea39b26b..a93afb1ca8f 100644
--- a/lib/libcbor/src/cbor/internal/builder_callbacks.h
+++ b/lib/libcbor/src/cbor/internal/builder_callbacks.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/internal/encoders.c b/lib/libcbor/src/cbor/internal/encoders.c
index e562b49b5f6..657e25c3987 100644
--- a/lib/libcbor/src/cbor/internal/encoders.c
+++ b/lib/libcbor/src/cbor/internal/encoders.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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 value, unsigned char *buffer,
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;
diff --git a/lib/libcbor/src/cbor/internal/encoders.h b/lib/libcbor/src/cbor/internal/encoders.h
index e9b756070a1..14ad5015cb5 100644
--- a/lib/libcbor/src/cbor/internal/encoders.h
+++ b/lib/libcbor/src/cbor/internal/encoders.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/internal/loaders.c b/lib/libcbor/src/cbor/internal/loaders.c
index fe000788923..af00f135527 100644
--- a/lib/libcbor/src/cbor/internal/loaders.c
+++ b/lib/libcbor/src/cbor/internal/loaders.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/internal/loaders.h b/lib/libcbor/src/cbor/internal/loaders.h
index c39a1b81335..a4c82b209f5 100644
--- a/lib/libcbor/src/cbor/internal/loaders.h
+++ b/lib/libcbor/src/cbor/internal/loaders.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/internal/memory_utils.c b/lib/libcbor/src/cbor/internal/memory_utils.c
index aa049a2f9e2..918b708e331 100644
--- a/lib/libcbor/src/cbor/internal/memory_utils.c
+++ b/lib/libcbor/src/cbor/internal/memory_utils.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/internal/memory_utils.h b/lib/libcbor/src/cbor/internal/memory_utils.h
index 132142383b6..c41ace67948 100644
--- a/lib/libcbor/src/cbor/internal/memory_utils.h
+++ b/lib/libcbor/src/cbor/internal/memory_utils.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/internal/stack.c b/lib/libcbor/src/cbor/internal/stack.c
index fc433ef31f0..79c9e5e5297 100644
--- a/lib/libcbor/src/cbor/internal/stack.c
+++ b/lib/libcbor/src/cbor/internal/stack.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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 *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;
diff --git a/lib/libcbor/src/cbor/internal/stack.h b/lib/libcbor/src/cbor/internal/stack.h
index 0d92c96a0e8..42ed04429c7 100644
--- a/lib/libcbor/src/cbor/internal/stack.h
+++ b/lib/libcbor/src/cbor/internal/stack.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/internal/unicode.c b/lib/libcbor/src/cbor/internal/unicode.c
index b92fefeb4d5..98b49728989 100644
--- a/lib/libcbor/src/cbor/internal/unicode.c
+++ b/lib/libcbor/src/cbor/internal/unicode.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/internal/unicode.h b/lib/libcbor/src/cbor/internal/unicode.h
index fc3a5051223..5f645602930 100644
--- a/lib/libcbor/src/cbor/internal/unicode.h
+++ b/lib/libcbor/src/cbor/internal/unicode.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/ints.c b/lib/libcbor/src/cbor/ints.c
index 328d0bdf9f1..880982e5a3e 100644
--- a/lib/libcbor/src/cbor/ints.c
+++ b/lib/libcbor/src/cbor/ints.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/ints.h b/lib/libcbor/src/cbor/ints.h
index 899caefd9bc..f965c298948 100644
--- a/lib/libcbor/src/cbor/ints.h
+++ b/lib/libcbor/src/cbor/ints.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/maps.c b/lib/libcbor/src/cbor/maps.c
index 6b04c5eef10..45140e2cfa2 100644
--- a/lib/libcbor/src/cbor/maps.c
+++ b/lib/libcbor/src/cbor/maps.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/maps.h b/lib/libcbor/src/cbor/maps.h
index d737d6974ee..4e27eefe325 100644
--- a/lib/libcbor/src/cbor/maps.h
+++ b/lib/libcbor/src/cbor/maps.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/serialization.c b/lib/libcbor/src/cbor/serialization.c
index f2666e1b22f..41343eff994 100644
--- a/lib/libcbor/src/cbor/serialization.c
+++ b/lib/libcbor/src/cbor/serialization.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/serialization.h b/lib/libcbor/src/cbor/serialization.h
index 44b47b74755..ef68cf86aec 100644
--- a/lib/libcbor/src/cbor/serialization.h
+++ b/lib/libcbor/src/cbor/serialization.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/streaming.c b/lib/libcbor/src/cbor/streaming.c
index 9bc315687cc..9d85e15f8b8 100644
--- a/lib/libcbor/src/cbor/streaming.c
+++ b/lib/libcbor/src/cbor/streaming.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/streaming.h b/lib/libcbor/src/cbor/streaming.h
index 8c153bb0019..d9d54b8c8e3 100644
--- a/lib/libcbor/src/cbor/streaming.h
+++ b/lib/libcbor/src/cbor/streaming.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/strings.c b/lib/libcbor/src/cbor/strings.c
index 4e201cccb12..209886b5f8c 100644
--- a/lib/libcbor/src/cbor/strings.c
+++ b/lib/libcbor/src/cbor/strings.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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 *item, cbor_item_t *chunk) {
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);
diff --git a/lib/libcbor/src/cbor/strings.h b/lib/libcbor/src/cbor/strings.h
index b867afa9d88..342d0988fdd 100644
--- a/lib/libcbor/src/cbor/strings.h
+++ b/lib/libcbor/src/cbor/strings.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/tags.c b/lib/libcbor/src/cbor/tags.c
index 0a29e46476f..3853db4d4ae 100644
--- a/lib/libcbor/src/cbor/tags.c
+++ b/lib/libcbor/src/cbor/tags.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.
diff --git a/lib/libcbor/src/cbor/tags.h b/lib/libcbor/src/cbor/tags.h
index 3a805fb096c..6e76c8263d6 100644
--- a/lib/libcbor/src/cbor/tags.h
+++ b/lib/libcbor/src/cbor/tags.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
+ * Copyright (c) 2014-2020 Pavel Kalvoda <me@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.