summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2026-03-22 14:31:02 +0000
committerEd Maste <emaste@FreeBSD.org>2026-03-22 14:31:23 +0000
commitaa1599ed2bad271ece23ac2d2ca14c6540fa5ffa (patch)
tree7edde4075fab7e96cf8adcd6135a761a87900cfc
parent5f50d6b344f0d272a12c6f5598dde05bbe025e97 (diff)
-rw-r--r--.circleci/config.yml79
-rw-r--r--.cirrus.yml8
-rw-r--r--.clang-format2
-rw-r--r--.github/workflows/fuzz-pr.yml2
-rw-r--r--.github/workflows/fuzz.yml2
-rw-r--r--.gitignore3
-rw-r--r--BUILD58
-rw-r--r--Bazel.md100
-rw-r--r--CHANGELOG.md19
-rw-r--r--CMakeLists.txt286
-rw-r--r--CONTRIBUTING.md17
-rw-r--r--Doxyfile2
-rw-r--r--MODULE.bazel1
-rw-r--r--doc/source/api.rst14
-rw-r--r--doc/source/api/streaming_encoding.rst2
-rw-r--r--doc/source/api/type_0_1_integers.rst (renamed from doc/source/api/type_0_1.rst)0
-rw-r--r--doc/source/api/type_2_byte_strings.rst (renamed from doc/source/api/type_2.rst)2
-rw-r--r--doc/source/api/type_3_strings.rst (renamed from doc/source/api/type_3.rst)2
-rw-r--r--doc/source/api/type_4_arrays.rst (renamed from doc/source/api/type_4.rst)2
-rw-r--r--doc/source/api/type_5_maps.rst (renamed from doc/source/api/type_5.rst)0
-rw-r--r--doc/source/api/type_6_tags.rst (renamed from doc/source/api/type_6.rst)7
-rw-r--r--doc/source/api/type_7_floats_ctrls.rst (renamed from doc/source/api/type_7.rst)9
-rw-r--r--doc/source/conf.py4
-rw-r--r--doc/source/development.rst3
-rw-r--r--doc/source/getting_started.rst73
-rw-r--r--doc/source/internal.rst6
-rw-r--r--doc/source/requirements.txt70
-rw-r--r--doc/source/standard_conformance.rst2
-rw-r--r--doc/source/using.rst14
-rw-r--r--examples/CMakeLists.txt13
-rw-r--r--examples/bazel/MODULE.bazel13
-rw-r--r--examples/bazel/WORKSPACE19
-rw-r--r--examples/bazel/src/BUILD10
-rw-r--r--examples/bazel/src/hello_test.cc10
-rw-r--r--examples/bazel/third_party/libcbor.BUILD21
-rw-r--r--examples/bazel/third_party/libcbor/cbor/configuration.h2
-rw-r--r--examples/cbor2cjson.c3
-rw-r--r--examples/cjson2cbor.c32
-rw-r--r--examples/sort.c12
-rw-r--r--examples/streaming_array.c3
-rw-r--r--examples/streaming_parser.c8
-rwxr-xr-xmisc/hooks/pre-commit9
-rwxr-xr-xmisc/update_version.py14
-rwxr-xr-xoss-fuzz/build.sh10
-rw-r--r--oss-fuzz/cbor_load_fuzzer.cc2
-rwxr-xr-xrelease.sh19
-rw-r--r--src/CMakeLists.txt108
-rw-r--r--src/cbor.c55
-rw-r--r--src/cbor/arrays.c50
-rw-r--r--src/cbor/bytestrings.c44
-rw-r--r--src/cbor/bytestrings.h26
-rw-r--r--src/cbor/callbacks.c86
-rw-r--r--src/cbor/callbacks.h68
-rw-r--r--src/cbor/common.c54
-rw-r--r--src/cbor/common.h56
-rw-r--r--src/cbor/encoding.c80
-rw-r--r--src/cbor/encoding.h71
-rw-r--r--src/cbor/floats_ctrls.c90
-rw-r--r--src/cbor/floats_ctrls.h48
-rw-r--r--src/cbor/internal/builder_callbacks.c160
-rw-r--r--src/cbor/internal/builder_callbacks.h54
-rw-r--r--src/cbor/internal/encoders.c47
-rw-r--r--src/cbor/internal/encoders.h10
-rw-r--r--src/cbor/internal/loaders.c16
-rw-r--r--src/cbor/internal/loaders.h8
-rw-r--r--src/cbor/internal/stack.c10
-rw-r--r--src/cbor/internal/stack.h10
-rw-r--r--src/cbor/ints.c95
-rw-r--r--src/cbor/ints.h48
-rw-r--r--src/cbor/maps.c36
-rw-r--r--src/cbor/maps.h26
-rw-r--r--src/cbor/serialization.c63
-rw-r--r--src/cbor/serialization.h26
-rw-r--r--src/cbor/streaming.c9
-rw-r--r--src/cbor/strings.c56
-rw-r--r--src/cbor/strings.h30
-rw-r--r--src/cbor/tags.c26
-rw-r--r--src/cbor/tags.h48
-rw-r--r--src/libcborConfig.cmake.in3
-rw-r--r--test/CMakeLists.txt36
-rw-r--r--test/array_encoders_test.c14
-rw-r--r--test/array_test.c50
-rw-r--r--test/bad_inputs_test.c20
-rw-r--r--test/bytestring_encoders_test.c6
-rw-r--r--test/bytestring_test.c46
-rw-r--r--test/callbacks_test.c26
-rw-r--r--test/cbor_serialize_test.c272
-rw-r--r--test/cbor_stream_decode_test.c110
-rw-r--r--test/copy_test.c67
-rw-r--r--test/float_ctrl_encoders_test.c34
-rw-r--r--test/float_ctrl_test.c20
-rw-r--r--test/fuzz_test.c12
-rw-r--r--test/map_encoders_test.c6
-rw-r--r--test/map_test.c60
-rw-r--r--test/memory_utils_test.c10
-rw-r--r--test/negint_encoders_test.c12
-rw-r--r--test/negint_test.c14
-rw-r--r--test/pretty_printer_test.c64
-rw-r--r--test/stack_over_limit_test.c8
-rw-r--r--test/stream_expectations.c50
-rw-r--r--test/stream_expectations.h50
-rw-r--r--test/string_encoders_test.c6
-rw-r--r--test/string_test.c62
-rw-r--r--test/tag_encoders_test.c4
-rw-r--r--test/tag_test.c36
-rw-r--r--test/test_allocator.c16
-rw-r--r--test/test_allocator.h8
-rw-r--r--test/uint_encoders_test.c12
-rw-r--r--test/uint_test.c22
-rw-r--r--test/unicode_test.c4
110 files changed, 2009 insertions, 1754 deletions
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 4391ad8d1e9c..2d3d1ea8fcc1 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -3,30 +3,48 @@ version: 2.1
commands:
linux-setup:
steps:
- - run: sudo apt-get update
- # NEEDRESTART_MODE prevents automatic restarts which seem to hang.
- - run: sudo NEEDRESTART_MODE=l apt-get install -y cmake ${TOOLCHAIN_PACKAGES}
- - run: sudo NEEDRESTART_MODE=l apt-get install -y libcmocka-dev libcjson-dev
+ - run: sudo apt-get update
+ # NEEDRESTART_MODE prevents automatic restarts which seem to hang.
+ - run: sudo NEEDRESTART_MODE=l apt-get install -y cmake ${TOOLCHAIN_PACKAGES}
+ - run: sudo NEEDRESTART_MODE=l apt-get install -y libcmocka-dev libcjson-dev
+ build-with-cmocka-from-source:
+ # For whatever reason, cmocka find stopped working on dockercross at some point.
+ steps:
+ - run: git clone https://git.cryptomilk.org/projects/cmocka.git ~/cmocka
+ - run: >
+ cd $(mktemp -d /tmp/build.XXXX) &&
+ cmake ~/cmocka &&
+ make &&
+ sudo make install
+ - run: >
+ cmake -DWITH_TESTS=ON \
+ -DWITH_EXAMPLES=ON \
+ -DCMAKE_BUILD_TYPE=Debug \
+ -DSANITIZE=OFF \
+ -DCOVERAGE="${CMAKE_COVERAGE:='OFF'}" \
+ -DCMOCKA_INCLUDE_DIR=/usr/local/include \
+ -DCMOCKA_LIBRARIES=/usr/local/lib/libcmocka.so
+ - run: make -j 16 VERBOSE=1
build:
steps:
- - run: >
- cmake -DWITH_TESTS=ON \
- -DWITH_EXAMPLES=ON \
- -DCMAKE_BUILD_TYPE=Debug \
- -DSANITIZE=OFF \
- -DCOVERAGE="${CMAKE_COVERAGE:='OFF'}" \
- .
- - run: make -j 16 VERBOSE=1
+ - run: >
+ cmake -DWITH_TESTS=ON \
+ -DWITH_EXAMPLES=ON \
+ -DCMAKE_BUILD_TYPE=Debug \
+ -DSANITIZE=OFF \
+ -DCOVERAGE="${CMAKE_COVERAGE:='OFF'}" \
+ .
+ - run: make -j 16 VERBOSE=1
build-release:
steps:
- - run: >
- cmake -DWITH_TESTS=ON \
- -DCMAKE_BUILD_TYPE=Release \
- .
- - run: make -j 16 VERBOSE=1
+ - run: >
+ cmake -DWITH_TESTS=ON \
+ -DCMAKE_BUILD_TYPE=Release \
+ .
+ - run: make -j 16 VERBOSE=1
test:
steps:
- - run: ctest -VV
+ - run: ctest -VV
orbs:
codecov: codecov/codecov@3.2.2
@@ -34,7 +52,7 @@ orbs:
jobs:
static-test:
machine: &default-machine
- image: ubuntu-2204:2023.07.2
+ image: ubuntu-2204:current
environment:
TOOLCHAIN_PACKAGES: g++
steps:
@@ -159,7 +177,7 @@ jobs:
build-bazel:
machine:
- image: ubuntu-2204:2023.07.2
+ <<: *default-machine
environment:
TOOLCHAIN_PACKAGES: g++
steps:
@@ -178,7 +196,7 @@ jobs:
build-and-test-osx:
macos:
- xcode: 12.5.1
+ xcode: 16.0.0
steps:
- checkout
- run: bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
@@ -203,7 +221,22 @@ jobs:
- run: /c/Program\ Files/Cmake/bin/cmake --build libcbor_build
- run: >
export PATH="$(pwd)/cmocka_build/src/Debug/:$PATH" &&
- /c/Program\ Files/Cmake/bin/ctest.exe --test-dir libcbor_build --output-on-failure
+ /c/Program\ Files/Cmake/bin/ctest.exe --test-dir libcbor_build -C Debug --output-on-failure
+
+ build-and-test-mips: &dockcross-job
+ docker:
+ - image: dockcross/linux-mips-lts
+ steps:
+ - checkout
+ - attach_workspace:
+ at: /home/circleci/project
+ - build-with-cmocka-from-source
+ - test
+
+ build-and-test-mipsel:
+ <<: *dockcross-job
+ docker:
+ - image: dockcross/linux-mipsel-lts
workflows:
build-and-test:
@@ -215,6 +248,8 @@ workflows:
- build-and-test-release-clang
- build-and-test-arm
- build-and-test-win
+ - build-and-test-mips
+ - build-and-test-mipsel
- build-bazel
- llvm-coverage
# OSX builds are expensive, run only on master
diff --git a/.cirrus.yml b/.cirrus.yml
index 948ae23b4a98..d3be21bc1d4c 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -15,12 +15,12 @@ freebsd_task:
- ctest -VV
matrix:
# From gcloud compute images list --project freebsd-org-cloud-dev --no-standard-images
- - name: freebsd-13-2
+ - name: freebsd-13-4
freebsd_instance:
- image_family: freebsd-13-2
- - name: freebsd-14-0
+ image_family: freebsd-13-4
+ - name: freebsd-14-2
freebsd_instance:
- image_family: freebsd-14-0
+ image_family: freebsd-14-2
- name: freebsd-15-0-snap
freebsd_instance:
image_family: freebsd-15-0-snap
diff --git a/.clang-format b/.clang-format
index de0dc5e77907..09a8bc907ac8 100644
--- a/.clang-format
+++ b/.clang-format
@@ -52,7 +52,7 @@ ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
-DerivePointerAlignment: true
+DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
diff --git a/.github/workflows/fuzz-pr.yml b/.github/workflows/fuzz-pr.yml
index 0e3c4fde4e02..aba933e193f3 100644
--- a/.github/workflows/fuzz-pr.yml
+++ b/.github/workflows/fuzz-pr.yml
@@ -18,7 +18,7 @@ jobs:
fuzz-seconds: 10
dry-run: false
- name: Upload Crash
- uses: actions/upload-artifact@v1
+ uses: actions/upload-artifact@v4
if: failure()
with:
name: artifacts
diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml
index 8603cc2f338e..8a95cdff76db 100644
--- a/.github/workflows/fuzz.yml
+++ b/.github/workflows/fuzz.yml
@@ -18,7 +18,7 @@ jobs:
fuzz-seconds: 14400 # 4 hours
dry-run: false
- name: Upload Crash
- uses: actions/upload-artifact@v1
+ uses: actions/upload-artifact@v4
if: failure()
with:
name: artifacts
diff --git a/.gitignore b/.gitignore
index 61f88a874965..a927c86360a3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,3 @@
-build
*~
nbproject
.idea
@@ -8,9 +7,11 @@ cmake-build-debug
venv
**.DS_Store
.vscode
+doc/build
# No top-level requirements, see doc/source
requirements.txt
examples/bazel/bazel-bazel
examples/bazel/bazel-bin
examples/bazel/bazel-out
examples/bazel/bazel-testlogs
+**MODULE.bazel.lock
diff --git a/BUILD b/BUILD
new file mode 100644
index 000000000000..5035c90f756b
--- /dev/null
+++ b/BUILD
@@ -0,0 +1,58 @@
+genrule(
+ name = "cbor_cmake",
+ srcs = glob(["**"]),
+ outs = [
+ "libcbor.a",
+ "cbor.h",
+ "cbor/arrays.h",
+ "cbor/bytestrings.h",
+ "cbor/callbacks.h",
+ "cbor/cbor_export.h",
+ "cbor/common.h",
+ "cbor/configuration.h",
+ "cbor/data.h",
+ "cbor/encoding.h",
+ "cbor/floats_ctrls.h",
+ "cbor/ints.h",
+ "cbor/maps.h",
+ "cbor/serialization.h",
+ "cbor/streaming.h",
+ "cbor/strings.h",
+ "cbor/tags.h",
+ ],
+ cmd = " && ".join([
+ # Remember where output should go.
+ "INITIAL_WD=`pwd`",
+ "cd `dirname $(location CMakeLists.txt)`",
+ "cmake -DCMAKE_BUILD_TYPE=Release .",
+ "cmake --build .",
+ # Export the .a and .h files for cbor rule, below.
+ "cp -R src/* $$INITIAL_WD/$(RULEDIR)",
+ "cp cbor/configuration.h $$INITIAL_WD/$(RULEDIR)/cbor",
+ ]),
+ visibility = ["//visibility:private"],
+)
+
+cc_import(
+ name = "cbor",
+ hdrs = [
+ "cbor.h",
+ "cbor/arrays.h",
+ "cbor/bytestrings.h",
+ "cbor/callbacks.h",
+ "cbor/cbor_export.h",
+ "cbor/common.h",
+ "cbor/configuration.h",
+ "cbor/data.h",
+ "cbor/encoding.h",
+ "cbor/floats_ctrls.h",
+ "cbor/ints.h",
+ "cbor/maps.h",
+ "cbor/serialization.h",
+ "cbor/streaming.h",
+ "cbor/strings.h",
+ "cbor/tags.h",
+ ],
+ static_library = "libcbor.a",
+ visibility = ["//visibility:public"],
+)
diff --git a/Bazel.md b/Bazel.md
deleted file mode 100644
index 9fa2081f58fc..000000000000
--- a/Bazel.md
+++ /dev/null
@@ -1,100 +0,0 @@
-# Use as a Bazel Dependency
-
-To use libcbor in your
-[Baze](https://bazel.build/)
-project, first add the following section to your project's `WORKSPACE` file.
-Note the location of the `third_party/libcbor.BUILD` file - you may use a
-different location if you wish, but you the file must be make available to
-`WORKSPACE`.
-
-## WORKSPACE
-
-Note, this imports version `0.8.0` - you may need to update the version and
-the sha256 hash.
-
-```python
-# libcbor
-http_archive(
- name = "libcbor",
- build_file = "//third_party:libcbor.BUILD",
- sha256 = "dd04ea1a7df484217058d389e027e7a0143a4f245aa18a9f89a5dd3e1a4fcc9a",
- strip_prefix = "libcbor-0.8.0",
- urls = ["https://github.com/PJK/libcbor/archive/refs/tags/v0.8.0.zip"],
-)
-```
-
-## third_party/libcbor.BUILD
-
-Bazel will unzip the libcbor zip file, then copy this file in as `BUILD`.
-Bazel will then use this file to compile libcbor.
-[Cmake](https://cmake.org/)
-is used in two passes: to create the Makefiles, and then to invoke Make to build
-the `libcbor.a` static library. `libcbor.a` and the `.h` files are then made
-available for other packages to use.
-
-```python
-genrule(
- name = "cbor_cmake",
- srcs = glob(["**"]),
- outs = ["libcbor.a", "cbor.h", "cbor/arrays.h", "cbor/bytestrings.h",
- "cbor/callbacks.h", "cbor/cbor_export.h", "cbor/common.h", "cbor/configuration.h", "cbor/data.h",
- "cbor/encoding.h", "cbor/floats_ctrls.h", "cbor/ints.h", "cbor/maps.h",
- "cbor/serialization.h", "cbor/streaming.h", "cbor/strings.h", "cbor/tags.h"],
- cmd = " && ".join([
- # Remember where output should go.
- "INITIAL_WD=`pwd`",
- # Build libcbor library.
- "cd `dirname $(location CMakeLists.txt)`",
- "cmake -DCMAKE_BUILD_TYPE=Release .",
- "cmake --build .",
- # Export the .a and .h files for cbor rule, below.
- "cp src/libcbor.a src/cbor.h $$INITIAL_WD/$(RULEDIR)",
- "cp src/cbor/*h cbor/configuration.h $$INITIAL_WD/$(RULEDIR)/cbor"]),
- visibility = ["//visibility:private"],
-)
-
-cc_import(
- name = "cbor",
- hdrs = ["cbor.h", "cbor/arrays.h", "cbor/bytestrings.h",
- "cbor/callbacks.h", "cbor/cbor_export.h", "cbor/common.h", "cbor/configuration.h", "cbor/data.h",
- "cbor/encoding.h", "cbor/floats_ctrls.h", "cbor/ints.h", "cbor/maps.h",
- "cbor/serialization.h", "cbor/streaming.h", "cbor/strings.h", "cbor/tags.h"],
- static_library = "libcbor.a",
- visibility = ["//visibility:public"],
-)
-```
-
-## third_party/BUILD
-
-The `libcbor.BUILD` file must be make available to the top-level `WORKSPACE`
-file:
-
-```python
-exports_files(["libcbor.BUILD"]))
-```
-
-## Your BUILD File
-
-Add libcbor dependency to your package's `BUILD` file like so:
-
-```python
-cc_library(
- name = "...",
- srcs = [ ... ],
- hdrs = [ ... ],
- deps = [
- ...
- "@libcbor//:cbor",
- ],
-)
-```
-
-## Your C File
-
-Now you may simply include `cbor.h`:
-
-```c
-#include "cbor.h"
-
-static const uint8_t version = cbor_major_version;
-```
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3c331f9266ab..8acd3265e490 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,11 +4,28 @@ Template:
Next
---------------------
+0.12.0 (2025-03-16)
+---------------------
+- BUILD BREAKING: [Respect `INTERPROCEDURAL_OPTIMIZATION` and use the default value](https://github.com/PJK/libcbor/issues/315)
+- BREAKING: Changes to NaN encoding
+ - [Fix NaN encoding on Windows](https://github.com/PJK/libcbor/issues/271)
+ - [Fix NaN encoding on mips/mipsel](https://github.com/PJK/libcbor/issues/329)
+ - [Signaling NaNs will from now on be encoded as canonical quiet NaNs](https://github.com/PJK/libcbor/pull/335). This was already the existing behavior for half-precision floats
+ - Decoding is unchanged
+ - Please note that this is an intermediate state and likely to be revisited (https://github.com/PJK/libcbor/issues/336)
+- [Make build compatible with CMake FetchContent](https://github.com/PJK/libcbor/pull/341) (by [Jan200101](https://github.com/Jan200101))
+- [Support Bzlmod for Bazel builds](https://github.com/PJK/libcbor/pull/340)
+ - This should significantly simplify including libcbor as a dependency/module in Bazel projects, see https://bazel.build/external/migration
+- Code quality improvements
+ - [Fix compiler pragmas](https://github.com/PJK/libcbor/pull/347) (by [brooksdavis](https://github.com/brooksdavis))
+ - [Fix code style issues](https://github.com/PJK/libcbor/pull/321)
+- [Fixed bug in cbor2cjson example](https://github.com/PJK/libcbor/pull/338) (by [whitehse](https://github.com/whitehse))
+
0.11.0 (2024-02-04)
---------------------
- [Updated documentation to refer to RFC 8949](https://github.com/PJK/libcbor/issues/269)
- Improvements to `cbor_describe`
- - [Bytestring data will now be printed as well](https://github.com/PJK/libcbor/pull/281) by [akallabeth](https://github.com/akallabeth)
+ - [Bytestring data will now be printed as well](https://github.com/PJK/libcbor/pull/281) by [akallabeth](https://github.com/akallabeth)
- [Formatting consistency and clarity improvements](https://github.com/PJK/libcbor/pull/285)
- [Fix `cbor_string_set_handle` not setting the codepoint count](https://github.com/PJK/libcbor/pull/286)
- BREAKING: [`cbor_load` will no longer fail on input strings that are well-formed but not valid UTF-8](https://github.com/PJK/libcbor/pull/286)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 16b9f0875d33..815675edd81a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,16 +1,19 @@
cmake_minimum_required(VERSION 3.0)
project(libcbor)
-set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/")
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
+ "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/")
include(CTest)
include(GNUInstallDirs) # Provides CMAKE_INSTALL_ variables
-SET(CBOR_VERSION_MAJOR "0")
-SET(CBOR_VERSION_MINOR "11")
-SET(CBOR_VERSION_PATCH "0")
-SET(CBOR_VERSION ${CBOR_VERSION_MAJOR}.${CBOR_VERSION_MINOR}.${CBOR_VERSION_PATCH})
+set(CBOR_VERSION_MAJOR "0")
+set(CBOR_VERSION_MINOR "12")
+set(CBOR_VERSION_PATCH "0")
+set(CBOR_VERSION
+ ${CBOR_VERSION_MAJOR}.${CBOR_VERSION_MINOR}.${CBOR_VERSION_PATCH})
-option(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY "cmake --build --target install does not depend on cmake --build" true)
+option(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY
+ "cmake --build --target install does not depend on cmake --build" true)
option(BUILD_SHARED_LIBS "Build as a shared library" false)
include(CheckIncludeFiles)
@@ -18,42 +21,51 @@ include(CheckIncludeFiles)
include(TestBigEndian)
test_big_endian(BIG_ENDIAN)
if(BIG_ENDIAN)
- add_definitions(-DIS_BIG_ENDIAN)
+ add_definitions(-DIS_BIG_ENDIAN)
endif()
option(CBOR_CUSTOM_ALLOC "Custom, dynamically defined allocator support" OFF)
if(CBOR_CUSTOM_ALLOC)
- message(WARNING
- "CBOR_CUSTOM_ALLOC has been deprecated. Custom allocators are now enabled by default."
- "The flag is a no-op and will be removed in the next version. "
- "Please remove CBOR_CUSTOM_ALLOC from your build configuration.")
-endif(CBOR_CUSTOM_ALLOC)
+ message(
+ WARNING
+ "CBOR_CUSTOM_ALLOC has been deprecated. \
+ Custom allocators are now enabled by default. \
+ The flag is a no-op and will be removed in the next version. \
+ Please remove CBOR_CUSTOM_ALLOC from your build configuration.")
+endif()
option(CBOR_PRETTY_PRINTER "Include a pretty-printing routine" ON)
-set(CBOR_BUFFER_GROWTH "2" CACHE STRING "Factor for buffer growth & shrinking")
-set(CBOR_MAX_STACK_SIZE "2048" CACHE STRING "maximum size for decoding context stack")
+set(CBOR_BUFFER_GROWTH
+ "2"
+ CACHE STRING "Factor for buffer growth & shrinking")
+set(CBOR_MAX_STACK_SIZE
+ "2048"
+ CACHE STRING "maximum size for decoding context stack")
option(WITH_TESTS "[TEST] Build unit tests (requires CMocka)" OFF)
if(WITH_TESTS)
- add_definitions(-DWITH_TESTS)
-endif(WITH_TESTS)
+ add_definitions(-DWITH_TESTS)
+endif()
option(WITH_EXAMPLES "Build examples" ON)
-option(HUGE_FUZZ "[TEST] Fuzz through 8GB of data in the test. Do not use with memory instrumentation!" OFF)
+option(HUGE_FUZZ "[TEST] Fuzz through 8GB of data in the test.\
+ Do not use with memory instrumentation!" OFF)
if(HUGE_FUZZ)
- add_definitions(-DHUGE_FUZZ)
-endif(HUGE_FUZZ)
+ add_definitions(-DHUGE_FUZZ)
+endif()
-option(SANE_MALLOC "[TEST] Assume that malloc will not allocate multi-GB blocks. Tests only, platform specific" OFF)
+option(SANE_MALLOC
+ "[TEST] Assume that malloc will not allocate multi-GB blocks.\
+ Tests only, platform specific" OFF)
if(SANE_MALLOC)
- add_definitions(-DSANE_MALLOC)
-endif(SANE_MALLOC)
+ add_definitions(-DSANE_MALLOC)
+endif()
option(PRINT_FUZZ "[TEST] Print the fuzzer input" OFF)
if(PRINT_FUZZ)
- add_definitions(-DPRINT_FUZZ)
-endif(PRINT_FUZZ)
+ add_definitions(-DPRINT_FUZZ)
+endif()
option(SANITIZE "Enable ASan & a few compatible sanitizers in Debug mode" ON)
@@ -68,118 +80,180 @@ set(CPACK_PACKAGE_VERSION_PATCH ${CBOR_VERSION_PATCH})
include(CPack)
if(MINGW)
- # https://github.com/PJK/libcbor/issues/13
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
+ # https://github.com/PJK/libcbor/issues/13
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
elseif(NOT MSVC)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -pedantic")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -pedantic")
endif()
if(MSVC)
- # This just doesn't work right -- https://msdn.microsoft.com/en-us/library/5ft82fed.aspx
- set(CBOR_RESTRICT_SPECIFIER "")
+ # This just doesn't work right --
+ # https://msdn.microsoft.com/en-us/library/5ft82fed.aspx
+ set(CBOR_RESTRICT_SPECIFIER "")
+ # Safe stdio is only available in C11
+ add_definitions(-D_CRT_SECURE_NO_WARNINGS)
+
+ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /sdl")
else()
- set(CBOR_RESTRICT_SPECIFIER "restrict")
+ set(CBOR_RESTRICT_SPECIFIER "restrict")
- set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -Wall -g -ggdb -DDEBUG=true")
- set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -Wall -DNDEBUG")
+ set(CMAKE_C_FLAGS_DEBUG
+ "${CMAKE_C_FLAGS_DEBUG} -O0 -pedantic -Wall -Wextra -g -ggdb -DDEBUG=true")
+ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -pedantic -Wall -Wextra -DNDEBUG")
- if(SANITIZE)
- set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} \
+ if(SANITIZE)
+ set(CMAKE_C_FLAGS_DEBUG
+ "${CMAKE_C_FLAGS_DEBUG} \
-fsanitize=undefined -fsanitize=address \
-fsanitize=bounds -fsanitize=alignment")
- endif()
-endif()
-
-set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-g")
+ endif()
+ set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-g")
+endif()
include(CheckTypeSize)
check_type_size("size_t" SIZEOF_SIZE_T)
if(SIZEOF_SIZE_T LESS 8)
- message(WARNING "Your size_t is less than 8 bytes. Decoding of huge items that would exceed the memory address space will always fail. Consider implementing a custom streaming decoder if you need to deal with huge items.")
+ message(
+ WARNING
+ "Your size_t is less than 8 bytes. \
+ Decoding of huge items that would exceed the memory address space \
+ will always fail. Consider implementing a custom streaming \
+ decoder if you need to deal with huge items.")
else()
- add_definitions(-DEIGHT_BYTE_SIZE_T)
+ add_definitions(-DEIGHT_BYTE_SIZE_T)
+endif()
+
+include(CheckCSourceCompiles)
+
+check_c_source_compiles("
+ int main() {
+ __builtin_unreachable();
+ return 0;
+ }
+" HAS_BUILTIN_UNREACHABLE)
+
+if (HAS_BUILTIN_UNREACHABLE)
+ add_definitions(-D_CBOR_HAS_BUILTIN_UNREACHABLE)
endif()
enable_testing()
set(CTEST_MEMORYCHECK_COMMAND "/usr/bin/valgrind")
-set(MEMORYCHECK_COMMAND_OPTIONS "--tool=memcheck --track-origins=yes --leak-check=full --error-exitcode=1")
+set(MEMORYCHECK_COMMAND_OPTIONS
+ "--tool=memcheck --track-origins=yes --leak-check=full --error-exitcode=1")
-add_custom_target(coverage
- COMMAND ctest
- COMMAND lcov --capture --directory . --output-file coverage.info
- COMMAND genhtml coverage.info --highlight --legend --output-directory coverage_html
- COMMAND echo "Coverage report ready: ${CMAKE_CURRENT_BINARY_DIR}/coverage_html/index.html")
+add_custom_target(
+ coverage
+ COMMAND ctest
+ COMMAND lcov --capture --directory . --output-file coverage.info
+ COMMAND genhtml coverage.info --highlight --legend --output-directory
+ coverage_html
+ COMMAND
+ echo
+ "Coverage report ready: ${CMAKE_CURRENT_BINARY_DIR}/coverage_html/index.html"
+ COMMENT "Generate coverage report using the GNU toolchain"
+)
-add_custom_target(llvm-coverage
- COMMAND make -j 16
- COMMAND rm -rf coverage_profiles
- COMMAND mkdir coverage_profiles
- COMMAND bash -c [[ for TEST in $(ls test/*_test); do LLVM_PROFILE_FILE="coverage_profiles/$(basename -- ${TEST}).profraw" ./${TEST}; done ]]
- # VERBATIM makes escaping working, but breaks shell expansions, so we need to explicitly use bash
- COMMAND bash -c [[ llvm-profdata merge -sparse $(ls coverage_profiles/*.profraw) -o coverage_profiles/combined.profdata ]]
- COMMAND bash -c [[ llvm-cov show -instr-profile=coverage_profiles/combined.profdata test/*_test -format=html > coverage_profiles/report.html ]]
- COMMAND bash -c [[ llvm-cov report -instr-profile=coverage_profiles/combined.profdata test/*_test ]]
- COMMAND echo "Coverage report ready: ${CMAKE_CURRENT_BINARY_DIR}/coverage_profiles/report.html"
- VERBATIM)
+add_custom_target(
+ llvm-coverage
+ COMMAND make -j 16
+ COMMAND rm -rf coverage_profiles
+ COMMAND mkdir coverage_profiles
+ COMMAND
+ bash -c
+ [[ for TEST in $(ls test/*_test); do LLVM_PROFILE_FILE="coverage_profiles/$(basename -- ${TEST}).profraw" ./${TEST}; done ]]
+ # VERBATIM makes escaping working, but breaks shell expansions, so we need to
+ # explicitly use bash
+ COMMAND
+ bash -c
+ [[ llvm-profdata merge -sparse $(ls coverage_profiles/*.profraw) -o coverage_profiles/combined.profdata ]]
+ COMMAND
+ bash -c
+ [[ llvm-cov show -instr-profile=coverage_profiles/combined.profdata test/*_test -format=html > coverage_profiles/report.html ]]
+ COMMAND
+ bash -c
+ [[ llvm-cov report -instr-profile=coverage_profiles/combined.profdata test/*_test ]]
+ COMMAND
+ echo
+ "Coverage report ready: ${CMAKE_CURRENT_BINARY_DIR}/coverage_profiles/report.html"
+ VERBATIM
+ COMMENT "Generate coverage report using the LLVM toolchain")
include_directories(src)
+option(COVERAGE "Enable code coverage instrumentation" OFF)
+if(COVERAGE)
+ message("Configuring code coverage instrumentation")
+ if(CMAKE_C_COMPILER_ID MATCHES "GNU")
+ # https://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html
+ set(CMAKE_C_FLAGS
+ "${CMAKE_C_FLAGS} -g -fprofile-arcs -ftest-coverage --coverage")
+ set(CMAKE_EXE_LINKER_FLAGS_DEBUG
+ "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -g -fprofile-arcs -ftest-coverage --coverage"
+ )
+ elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
+ set(CMAKE_C_FLAGS
+ "${CMAKE_C_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
+ set(CMAKE_EXE_LINKER_FLAGS_DEBUG
+ "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fprofile-instr-generate")
+ else()
+ message(
+ WARNING
+ "Code coverage build not implemented for compiler ${CMAKE_C_COMPILER_ID}"
+ )
+ endif()
+endif()
-option(c "Enable code coverage instrumentation" OFF)
-if (COVERAGE)
- message("Configuring code coverage instrumentation")
- if(CMAKE_C_COMPILER_ID MATCHES "GNU")
- # https://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fprofile-arcs -ftest-coverage --coverage")
- set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -g -fprofile-arcs -ftest-coverage --coverage")
- elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
- set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fprofile-instr-generate")
- else()
- message(WARNING "Code coverage build not implemented for compiler ${CMAKE_C_COMPILER_ID}")
- endif()
-endif (COVERAGE)
-
-# We want to generate configuration.h from the template and make it so that it is accessible using the same
-# path during both library build and installed header use, without littering the source dir.
-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/cbor/configuration.h.in ${PROJECT_BINARY_DIR}/cbor/configuration.h)
-install(FILES ${PROJECT_BINARY_DIR}/cbor/configuration.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cbor)
-# Make the header visible at compile time
-include_directories(${PROJECT_BINARY_DIR})
+# We want to generate configuration.h from the template and make it so that it
+# is accessible using the same path during both library build and installed
+# header use, without littering the source dir.
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/cbor/configuration.h.in
+ ${PROJECT_BINARY_DIR}/cbor/configuration.h)
+install(FILES ${PROJECT_BINARY_DIR}/cbor/configuration.h
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cbor)
# CMake >= 3.9.0 enables LTO for GCC and Clang with INTERPROCEDURAL_OPTIMIZATION
-# Policy CMP0069 enables this behavior when we set the minimum CMake version < 3.9.0
-# Checking for LTO support before setting INTERPROCEDURAL_OPTIMIZATION is mandatory with CMP0069 set to NEW.
-set(use_lto FALSE)
-if(${CMAKE_VERSION} VERSION_GREATER "3.9.0" OR ${CMAKE_VERSION} VERSION_EQUAL "3.9.0")
- cmake_policy(SET CMP0069 NEW)
- # Require LTO support to build libcbor with newer CMake versions
- include(CheckIPOSupported)
- check_ipo_supported(RESULT use_lto)
-endif(${CMAKE_VERSION} VERSION_GREATER "3.9.0" OR ${CMAKE_VERSION} VERSION_EQUAL "3.9.0")
-if(use_lto)
- message(STATUS "LTO is enabled")
+# Policy CMP0069 enables this behavior when we set the minimum CMake version <
+# 3.9.0 Checking for LTO support before setting INTERPROCEDURAL_OPTIMIZATION is
+# mandatory with CMP0069 set to NEW.
+set(LTO_SUPPORTED FALSE)
+if(${CMAKE_VERSION} VERSION_GREATER "3.9.0" OR ${CMAKE_VERSION} VERSION_EQUAL
+ "3.9.0")
+ cmake_policy(SET CMP0069 NEW)
+ # Require LTO support to build libcbor with newer CMake versions
+ include(CheckIPOSupported)
+ check_ipo_supported(RESULT LTO_SUPPORTED)
+endif()
+
+if(NOT DEFINED CMAKE_INTERPROCEDURAL_OPTIMIZATION)
+ set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
+endif()
+
+if(LTO_SUPPORTED)
+ message(
+ STATUS
+ "LTO is supported and CMAKE_INTERPROCEDURAL_OPTIMIZATION=${CMAKE_INTERPROCEDURAL_OPTIMIZATION}"
+ )
else()
- message(STATUS "LTO is not enabled")
-endif(use_lto)
+ message(STATUS "LTO is not supported")
+endif()
add_subdirectory(src)
-if(use_lto)
- set_property(DIRECTORY src PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
-endif(use_lto)
+if(LTO_SUPPORTED)
+ set_property(DIRECTORY src PROPERTY INTERPROCEDURAL_OPTIMIZATION CMAKE_INTERPROCEDURAL_OPTIMIZATION)
+endif()
-if (WITH_TESTS)
- add_subdirectory(test)
- if(use_lto)
- set_property(DIRECTORY test PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
- endif(use_lto)
-endif (WITH_TESTS)
+if(WITH_TESTS)
+ add_subdirectory(test)
+ if(LTO_SUPPORTED)
+ set_property(DIRECTORY test PROPERTY INTERPROCEDURAL_OPTIMIZATION CMAKE_INTERPROCEDURAL_OPTIMIZATION)
+ endif()
+endif()
-if (WITH_EXAMPLES)
- add_subdirectory(examples)
- if(use_lto)
- set_property(DIRECTORY examples PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
- endif(use_lto)
-endif (WITH_EXAMPLES)
+if(WITH_EXAMPLES)
+ add_subdirectory(examples)
+ if(LTO_SUPPORTED)
+ set_property(DIRECTORY examples PROPERTY INTERPROCEDURAL_OPTIMIZATION CMAKE_INTERPROCEDURAL_OPTIMIZATION)
+ endif()
+endif()
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 9bd42a06b6dc..c0f0da6029ca 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -29,6 +29,23 @@ I work on libcbor on a best effort basis. The typical response time is a few day
If you do not receive a response in a few weeks, feel free to ping the PR or issue.
+## Coding style
+
+C++ code: `./clang-format.sh`.
+
+Function Doxygen strings:
+```c
+/** An example short description
+ *
+ * @param item The item to fooify. Describe any expectations on it (e.g."must
+ * be a valid array") and reference counting manipulation.
+ * Multi-line descriptions are OK where necessary.
+ * @param target_item Short description, always with a full stop.
+ * @return Has fooification succeeded? List any special cases.
+ */
+ bool foo(cbor_item_t *item, cbor_item_t *target_item);
+```
+
## Resources
- [Development documentation](https://libcbor.readthedocs.io/en/latest/development.html)
diff --git a/Doxyfile b/Doxyfile
index 67df45cfbb94..e612afb4b199 100644
--- a/Doxyfile
+++ b/Doxyfile
@@ -48,7 +48,7 @@ PROJECT_NAME = libcbor
# could be handy for archiving the generated documentation or if some version
# control system is used.
-PROJECT_NUMBER = 0.11.0
+PROJECT_NUMBER = 0.12.0
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
diff --git a/MODULE.bazel b/MODULE.bazel
new file mode 100644
index 000000000000..fbc208ab2397
--- /dev/null
+++ b/MODULE.bazel
@@ -0,0 +1 @@
+module(name = "libcbor")
diff --git a/doc/source/api.rst b/doc/source/api.rst
index 75b0541cb94e..616f12103124 100644
--- a/doc/source/api.rst
+++ b/doc/source/api.rst
@@ -30,12 +30,12 @@ The API is designed to allow both very tight control & flexibility and general c
api/encoding
api/streaming_decoding
api/streaming_encoding
- api/type_0_1
- api/type_2
- api/type_3
- api/type_4
- api/type_5
- api/type_6
- api/type_7
+ api/type_0_1_integers
+ api/type_2_byte_strings
+ api/type_3_strings
+ api/type_4_arrays
+ api/type_5_maps
+ api/type_6_tags
+ api/type_7_floats_ctrls
.. [#] http://softwareengineering.vazexqi.com/files/pattern.html
diff --git a/doc/source/api/streaming_encoding.rst b/doc/source/api/streaming_encoding.rst
index 25100da9b5e0..ebb2f72057af 100644
--- a/doc/source/api/streaming_encoding.rst
+++ b/doc/source/api/streaming_encoding.rst
@@ -7,7 +7,7 @@ exposes a low-level encoding API to encode CBOR objects on the fly. Unlike
strings, etc.) instead of :type:`cbor_item_t`. The client is responsible for
constructing the compound types correctly (e.g. terminating arrays).
-Streaming encoding is typically used to create an streaming (indefinite length) CBOR :doc:`strings <type_2>`, :doc:`byte strings <type_3>`, :doc:`arrays <type_4>`, and :doc:`maps <type_5>`. Complete example: `examples/streaming_array.c <https://github.com/PJK/libcbor/blob/master/examples/streaming_array.c>`_
+Streaming encoding is typically used to create an streaming (indefinite length) CBOR :doc:`strings <type_2_byte_strings>`, :doc:`byte strings <type_3_strings>`, :doc:`arrays <type_4_arrays>`, and :doc:`maps <type_5_maps>`. Complete example: `examples/streaming_array.c <https://github.com/PJK/libcbor/blob/master/examples/streaming_array.c>`_
.. doxygenfunction:: cbor_encode_uint8
diff --git a/doc/source/api/type_0_1.rst b/doc/source/api/type_0_1_integers.rst
index 4fc851dd1ed1..4fc851dd1ed1 100644
--- a/doc/source/api/type_0_1.rst
+++ b/doc/source/api/type_0_1_integers.rst
diff --git a/doc/source/api/type_2.rst b/doc/source/api/type_2_byte_strings.rst
index ff9369a90d67..d0644fffb137 100644
--- a/doc/source/api/type_2.rst
+++ b/doc/source/api/type_2_byte_strings.rst
@@ -1,7 +1,7 @@
Type 2 – Byte strings
=============================
-CBOR byte strings are just (ordered) series of bytes without further interpretation (unless there is a :doc:`tag <type_6>`). Byte string's length may or may not be known during encoding. These two kinds of byte strings can be distinguished using :func:`cbor_bytestring_is_definite` and :func:`cbor_bytestring_is_indefinite` respectively.
+CBOR byte strings are just (ordered) series of bytes without further interpretation (unless there is a :doc:`tag <type_6_tags>`). Byte string's length may or may not be known during encoding. These two kinds of byte strings can be distinguished using :func:`cbor_bytestring_is_definite` and :func:`cbor_bytestring_is_indefinite` respectively.
In case a byte string is indefinite, it is encoded as a series of definite byte strings. These are called "chunks". For example, the encoded item
diff --git a/doc/source/api/type_3.rst b/doc/source/api/type_3_strings.rst
index be06fc176566..847c474b0417 100644
--- a/doc/source/api/type_3.rst
+++ b/doc/source/api/type_3_strings.rst
@@ -1,7 +1,7 @@
Type 3 – UTF-8 strings
=============================
-CBOR strings have the same structure as :doc:`type_2`.
+CBOR strings have the same structure as :doc:`type_2_byte_strings`.
================================== ======================================================
Corresponding :type:`cbor_type` ``CBOR_TYPE_STRING``
diff --git a/doc/source/api/type_4.rst b/doc/source/api/type_4_arrays.rst
index a76202f4a0fd..2fa615df0eb4 100644
--- a/doc/source/api/type_4.rst
+++ b/doc/source/api/type_4_arrays.rst
@@ -1,7 +1,7 @@
Type 4 – Arrays
=============================
-CBOR arrays, just like :doc:`byte strings <type_2>` and :doc:`strings <type_3>`, can be encoded either as definite, or as indefinite.
+CBOR arrays, just like :doc:`byte strings <type_2_byte_strings>` and :doc:`strings <type_3_strings>`, can be encoded either as definite, or as indefinite.
Definite arrays have a fixed size which is stored in the header, whereas indefinite arrays do not and are terminated by a special "break" byte instead.
Arrays are explicitly created or decoded as definite or indefinite and will be encoded using the corresponding wire representation, regardless of whether the actual size is known at the time of encoding.
diff --git a/doc/source/api/type_5.rst b/doc/source/api/type_5_maps.rst
index 7f7be273aba9..7f7be273aba9 100644
--- a/doc/source/api/type_5.rst
+++ b/doc/source/api/type_5_maps.rst
diff --git a/doc/source/api/type_6.rst b/doc/source/api/type_6_tags.rst
index e98457ceae2a..1ee5f6949a2e 100644
--- a/doc/source/api/type_6.rst
+++ b/doc/source/api/type_6_tags.rst
@@ -5,7 +5,12 @@ Tag are additional metadata that can be used to extend or specialize the meaning
For example, one might tag an array of numbers to communicate that it should be interpreted as a vector.
-Please consult the official `IANA repository of CBOR tags <https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml>`_ before inventing new ones.
+Please consult the official `IANA repository of CBOR tags <https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml>`_ for known registered values.
+
+Please note that libcbor does *not* understand the semantics of tags and will
+process all `well-formed <https://datatracker.ietf.org/doc/html/rfc8949#name-terminology>`_
+tags regardless of whether they are valid with respect to the data they are
+applied to.
================================== ======================================================
Corresponding :type:`cbor_type` ``CBOR_TYPE_TAG``
diff --git a/doc/source/api/type_7.rst b/doc/source/api/type_7_floats_ctrls.rst
index b105402a08b2..d893fe37cb7b 100644
--- a/doc/source/api/type_7.rst
+++ b/doc/source/api/type_7_floats_ctrls.rst
@@ -60,9 +60,16 @@ Manipulating existing items
.. doxygenfunction:: cbor_set_float8
-.. _api_type_7_hard_floats:
+.. _api_type_7_floats_ctrls_half_floats:
Half floats
~~~~~~~~~~~~
CBOR supports two `bytes wide ("half-precision") <https://en.wikipedia.org/wiki/Half-precision_floating-point_format>`_
floats which are not supported by the C language. *libcbor* represents them using `float <https://en.cppreference.com/w/c/language/type>` values throughout the API. Encoding will be performed by :func:`cbor_encode_half`, which will handle any values that cannot be represented as a half-float.
+
+Signaling NaNs
+~~~~~~~~~~~~~~~~
+
+`Signaling NaNs <https://en.wikipedia.org/wiki/NaN#Signaling_NaN)>`_ are always encoded as a standard, "quiet" NaN.
+
+The reason for this simplification is that standard C does not offer a way to handle the signaling payload without assumptions about the host architecture. See https://github.com/PJK/libcbor/issues/336 for more context.
diff --git a/doc/source/conf.py b/doc/source/conf.py
index 0eee7103bb5a..4574669505e8 100644
--- a/doc/source/conf.py
+++ b/doc/source/conf.py
@@ -77,8 +77,8 @@ copyright = '2014 - 2020, Pavel Kalvoda'
# built documents.
#
# The short X.Y version.
-version = '0.11'
-release = '0.11.0'
+version = '0.12'
+release = '0.12.0'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
diff --git a/doc/source/development.rst b/doc/source/development.rst
index 0b0ac21007ed..5471047317af 100644
--- a/doc/source/development.rst
+++ b/doc/source/development.rst
@@ -99,7 +99,8 @@ Development dependencies
- There are some `Ruby <https://www.ruby-lang.org/en/>`_ scripts in ``misc``
- `Valgrind <http://valgrind.org/>`_ (memory correctness & profiling)
- `GCOV/LCOV <http://ltp.sourceforge.net/coverage/lcov.php>`_ (test coverage)
-- `clang-format`
+- `clang-format` (linter)
+- `cmakelang <https://cmake-format.readthedocs.io/en/latest/index.html>`_ (linter)
Installing *sphinx*
diff --git a/doc/source/getting_started.rst b/doc/source/getting_started.rst
index 98c5a3956337..ee57c094458d 100644
--- a/doc/source/getting_started.rst
+++ b/doc/source/getting_started.rst
@@ -38,26 +38,65 @@ Prerequisites:
A handful of configuration flags can be passed to `cmake`. The following table lists libcbor compile-time directives and several important generic flags.
-======================== ======================================================= ====================== =====================================================================================================================
-Option Meaning Default Possible values
------------------------- ------------------------------------------------------- ---------------------- ---------------------------------------------------------------------------------------------------------------------
-``CMAKE_C_COMPILER`` C compiler to use ``cc`` ``gcc``, ``clang``, ``clang-3.5``, ...
-``CMAKE_INSTALL_PREFIX`` Installation prefix System-dependent ``/usr/local/lib``, ...
-``BUILD_SHARED_LIBS`` Build as a shared library ``OFF`` ``ON``, ``OFF``
-``HUGE_FUZZ`` :doc:`Fuzz test </tests>` with 8GB of data ``OFF`` ``ON``, ``OFF``
-``SANE_MALLOC`` Assume ``malloc`` will refuse unreasonable allocations ``OFF`` ``ON``, ``OFF``
-``COVERAGE`` Generate test coverage instrumentation ``OFF`` ``ON``, ``OFF``
-``WITH_TESTS`` Build unit tests (see :doc:`development`) ``OFF`` ``ON``, ``OFF``
-======================== ======================================================= ====================== =====================================================================================================================
+.. list-table::
+ :header-rows: 1
+
+ * - Option
+ - Meaning
+ - Default
+ - Possible values
+ * - ``CMAKE_C_COMPILER``
+ - C compiler to use
+ - ``cc``
+ - ``gcc``, ``clang``, ``clang-3.5``, ...
+ * - ``CMAKE_INSTALL_PREFIX``
+ - Installation prefix
+ - System-dependent
+ - ``/usr/local/lib``, ...
+ * - ``CMAKE_INTERPROCEDURAL_OPTIMIZATION``
+ - Enable LTO (if supported)
+ - System-dependent
+ - ``ON``, ``OFF``
+ * - ``BUILD_SHARED_LIBS``
+ - Build as a shared library
+ - ``OFF``
+ - ``ON``, ``OFF``
+ * - ``HUGE_FUZZ``
+ - :doc:`Fuzz test </tests>` with 8GB of data
+ - ``OFF``
+ - ``ON``, ``OFF``
+ * - ``SANE_MALLOC``
+ - Assume ``malloc`` will refuse unreasonable allocations
+ - ``OFF``
+ - ``ON``, ``OFF``
+ * - ``COVERAGE``
+ - Generate test coverage instrumentation
+ - ``OFF``
+ - ``ON``, ``OFF``
+ * - ``WITH_TESTS``
+ - Build unit tests (see :doc:`development`)
+ - ``OFF``
+ - ``ON``, ``OFF``
+
The following configuration options will also be defined as macros [#]_ in ``<cbor/common.h>`` and can therefore be used in client code:
-======================== ======================================================= ====================== =====================================================================================================================
-Option Meaning Default Possible values
------------------------- ------------------------------------------------------- ---------------------- ---------------------------------------------------------------------------------------------------------------------
-``CBOR_PRETTY_PRINTER`` Include a pretty-printing routine ``ON`` ``ON``, ``OFF``
-``CBOR_BUFFER_GROWTH`` Factor for buffer growth & shrinking ``2`` Decimals > 1
-======================== ======================================================= ====================== =====================================================================================================================
+.. list-table::
+ :header-rows: 1
+
+ * - Option
+ - Meaning
+ - Default
+ - Possible values
+ * - ``CBOR_PRETTY_PRINTER``
+ - Include a pretty-printing routine
+ - ``ON``
+ - ``ON``, ``OFF``
+ * - ``CBOR_BUFFER_GROWTH``
+ - Factor for buffer growth & shrinking
+ - ``2``
+ - Decimals > 1
+
.. [#] ``ON`` & ``OFF`` will be translated to ``1`` and ``0`` using `cmakedefine <https://cmake.org/cmake/help/v3.2/command/configure_file.html?highlight=cmakedefine>`_.
diff --git a/doc/source/internal.rst b/doc/source/internal.rst
index e30cb11dffa1..07cd7cfc10c6 100644
--- a/doc/source/internal.rst
+++ b/doc/source/internal.rst
@@ -82,7 +82,7 @@ Generally speaking, data items consist of three parts:
.. member:: unsigned char * data
- Contains pointer to the actual data. Small, fixed size items (:doc:`api/type_0_1`, :doc:`api/type_6`, :doc:`api/type_7`) are allocated as a single memory block.
+ Contains pointer to the actual data. Small, fixed size items (:doc:`api/type_0_1_integers`, :doc:`api/type_6_tags`, :doc:`api/type_7_floats_ctrls`) are allocated as a single memory block.
Consider the following snippet
@@ -103,7 +103,7 @@ Generally speaking, data items consist of three parts:
| |
+--- item +--- item->data
- Dynamically sized types (:doc:`api/type_2`, :doc:`api/type_3`, :doc:`api/type_4`, :doc:`api/type_5`) may store handle and data in separate locations. This enables creating large items (e.g :doc:`byte strings <api/type_2>`) without :func:`realloc` or copying large blocks of memory. One simply attaches the correct pointer to the handle.
+ Dynamically sized types (:doc:`api/type_2_byte_strings`, :doc:`api/type_3_strings`, :doc:`api/type_4_arrays`, :doc:`api/type_5_maps`) may store handle and data in separate locations. This enables creating large items (e.g :doc:`byte strings <api/type_2_byte_strings>`) without :func:`realloc` or copying large blocks of memory. One simply attaches the correct pointer to the handle.
.. type:: cbor_item_metadata
@@ -112,7 +112,7 @@ Generally speaking, data items consist of three parts:
.. member:: struct _cbor_int_metadata int_metadata
- Used both by both :doc:`api/type_0_1`
+ Used both by both :doc:`api/type_0_1_integers`
.. member:: struct _cbor_bytestring_metadata bytestring_metadata
.. member:: struct _cbor_string_metadata string_metadata
diff --git a/doc/source/requirements.txt b/doc/source/requirements.txt
index 502d79cc62e6..1b34e120b8b2 100644
--- a/doc/source/requirements.txt
+++ b/doc/source/requirements.txt
@@ -1,31 +1,47 @@
-alabaster==0.7.13
-Babel==2.13.1
-breathe==4.35.0
-certifi==2023.11.17
-charset-normalizer==3.3.2
+alabaster==1.0.0
+anyio==4.8.0
+babel==2.17.0
+breathe==4.36.0
+build==1.2.2.post1
+certifi==2025.1.31
+charset-normalizer==3.4.1
+click==8.1.8
colorama==0.4.6
-docutils==0.18.1
-idna==3.4
+docutils==0.21.2
+h11==0.14.0
+idna==3.10
imagesize==1.4.1
-importlib-metadata==6.8.0
-Jinja2==3.1.2
-livereload==2.6.3
-MarkupSafe==2.1.3
-packaging==23.2
-Pygments==2.16.1
-pyparsing==3.1.1
-pytz==2021.3
-requests==2.31.0
+importlib_metadata==8.6.1
+Jinja2==3.1.6
+livereload @ https://github.com/lepture/python-livereload/archive/master.zip#sha256=95371213cf9107242808ea6e1353b524d7c38d96e299604e651e43271263352c
+MarkupSafe==3.0.2
+packaging==24.2
+pip-tools==7.4.1
+Pygments==2.19.1
+pyparsing==3.2.1
+pyproject_hooks==1.2.0
+pytz==2025.1
+requests==2.32.3
+roman-numerals-py==3.1.0
+setuptools==75.8.2
+six==1.17.0
+sniffio==1.3.1
snowballstemmer==2.2.0
-Sphinx==7.2.6
-sphinx-autobuild==2021.3.14
-sphinx-rtd-theme==1.3.0
-sphinxcontrib-applehelp==1.0.7
-sphinxcontrib-devhelp==1.0.5
-sphinxcontrib-htmlhelp==2.0.4
+Sphinx==8.2.3
+sphinx-autobuild==2024.10.3
+sphinx-rtd-theme==3.0.2
+sphinxcontrib-applehelp==2.0.0
+sphinxcontrib-devhelp==2.0.0
+sphinxcontrib-htmlhelp==2.1.0
+sphinxcontrib-jquery==4.1
sphinxcontrib-jsmath==1.0.1
-sphinxcontrib-qthelp==1.0.6
-sphinxcontrib-serializinghtml==1.1.9
-tornado==6.3.3
-urllib3==2.1.0
-zipp==3.17.0
+sphinxcontrib-qthelp==2.0.0
+sphinxcontrib-serializinghtml==2.0.0
+starlette==0.46.0
+tornado==6.4.2
+urllib3==2.3.0
+uvicorn==0.34.0
+watchfiles==1.0.4
+websockets==15.0
+wheel==0.45.1
+zipp==3.21.0
diff --git a/doc/source/standard_conformance.rst b/doc/source/standard_conformance.rst
index 62965f0c4493..4f57bb4c091f 100644
--- a/doc/source/standard_conformance.rst
+++ b/doc/source/standard_conformance.rst
@@ -13,5 +13,5 @@ There is no explicit limitation of indefinite length byte strings. [#]_ *libcbor
---------------------------------
As of C99 and even C11, there is no standard implementation for 2 bytes floats. *libcbor* packs them as a `float <https://en.cppreference.com/w/c/language/type>`. When encoding, *libcbor* selects the appropriate wire representation based on metadata and the actual value. This applies both to canonical and normal mode.
-For more information on half-float serialization, please refer to the section on :ref:`api_type_7_hard_floats`.
+For more information on half-float serialization, please refer to the section on :ref:`api_type_7_floats_ctrls_half_floats`.
diff --git a/doc/source/using.rst b/doc/source/using.rst
index ccb7372f23b6..c6688bbad7bd 100644
--- a/doc/source/using.rst
+++ b/doc/source/using.rst
@@ -32,19 +32,19 @@ Headers to include
The ``cbor.h`` header includes all the symbols. If, for any reason, you don't want to include all the exported symbols,
feel free to use just some of the ``cbor/*.h`` headers:
- - ``cbor/arrays.h`` - :doc:`api/type_4`
- - ``cbor/bytestrings.h`` - :doc:`api/type_2`
+ - ``cbor/arrays.h`` - :doc:`api/type_4_arrays`
+ - ``cbor/bytestrings.h`` - :doc:`api/type_2_byte_strings`
- ``cbor/callbacks.h`` - Callbacks used for :doc:`api/streaming_decoding`
- ``cbor/common.h`` - Common utilities - always transitively included
- ``cbor/data.h`` - Data types definitions - always transitively included
- ``cbor/encoding.h`` - Streaming encoders for :doc:`api/streaming_encoding`
- - ``cbor/floats_ctrls.h`` - :doc:`api/type_7`
- - ``cbor/ints.h`` - :doc:`api/type_0_1`
- - ``cbor/maps.h`` - :doc:`api/type_5`
+ - ``cbor/floats_ctrls.h`` - :doc:`api/type_7_floats_ctrls`
+ - ``cbor/ints.h`` - :doc:`api/type_0_1_integers`
+ - ``cbor/maps.h`` - :doc:`api/type_5_maps`
- ``cbor/serialization.h`` - High level serialization such as :func:`cbor_serialize`
- ``cbor/streaming.h`` - Home of :func:`cbor_stream_decode`
- - ``cbor/strings.h`` - :doc:`api/type_3`
- - ``cbor/tags.h`` - :doc:`api/type_6`
+ - ``cbor/strings.h`` - :doc:`api/type_3_strings`
+ - ``cbor/tags.h`` - :doc:`api/type_6_tags`
Using libcbor
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index b1f2ec290e7a..5ef9162c12d1 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -19,14 +19,13 @@ target_link_libraries(hello cbor)
find_package(CJSON)
if(CJSON_FOUND)
- add_executable(cjson2cbor cjson2cbor.c)
- target_include_directories(cjson2cbor PUBLIC ${CJSON_INCLUDE_DIRS})
- target_link_libraries(cjson2cbor cbor ${CJSON_LIBRARY})
+ add_executable(cjson2cbor cjson2cbor.c)
+ target_include_directories(cjson2cbor PUBLIC ${CJSON_INCLUDE_DIRS})
+ target_link_libraries(cjson2cbor cbor ${CJSON_LIBRARY})
- add_executable(cbor2cjson cbor2cjson.c)
- target_include_directories(cbor2cjson PUBLIC ${CJSON_INCLUDE_DIRS})
- target_link_libraries(cbor2cjson cbor ${CJSON_LIBRARY})
+ add_executable(cbor2cjson cbor2cjson.c)
+ target_include_directories(cbor2cjson PUBLIC ${CJSON_INCLUDE_DIRS})
+ target_link_libraries(cbor2cjson cbor ${CJSON_LIBRARY})
endif()
file(COPY data DESTINATION .)
-
diff --git a/examples/bazel/MODULE.bazel b/examples/bazel/MODULE.bazel
new file mode 100644
index 000000000000..5d14df5cf761
--- /dev/null
+++ b/examples/bazel/MODULE.bazel
@@ -0,0 +1,13 @@
+module(
+ name = "libcbor_bazel_example",
+ version = "0.1.0",
+)
+
+bazel_dep(name = "rules_cc", version = "0.1.1")
+bazel_dep(name = "googletest", version = "1.15.2")
+
+bazel_dep(name = "libcbor")
+local_path_override(
+ module_name = "libcbor",
+ path = "../..",
+)
diff --git a/examples/bazel/WORKSPACE b/examples/bazel/WORKSPACE
deleted file mode 100644
index c7601f3035ff..000000000000
--- a/examples/bazel/WORKSPACE
+++ /dev/null
@@ -1,19 +0,0 @@
-workspace(name = "libcbor_bazel_example")
-
-load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
-
-# Google Test
-http_archive(
- name = "gtest",
- sha256 = "94c634d499558a76fa649edb13721dce6e98fb1e7018dfaeba3cd7a083945e91",
- strip_prefix = "googletest-release-1.10.0",
- url = "https://github.com/google/googletest/archive/release-1.10.0.zip",
-)
-
-# libcbor
-new_local_repository(
- name = "libcbor",
- build_file = "//third_party:libcbor.BUILD",
- path = "../../src",
-)
-
diff --git a/examples/bazel/src/BUILD b/examples/bazel/src/BUILD
index d3acb578398a..367094644a5f 100644
--- a/examples/bazel/src/BUILD
+++ b/examples/bazel/src/BUILD
@@ -2,7 +2,7 @@ load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_cc//cc:defs.bzl", "cc_binary")
cc_library(
- name = "src",
+ name = "hello_lib",
srcs = [
"hello.cc",
],
@@ -18,7 +18,7 @@ cc_library(
)
cc_test(
- name = "tests",
+ name = "hello_test",
size = "small",
srcs = [
"hello_test.cc",
@@ -27,8 +27,8 @@ cc_test(
"//visibility:private",
],
deps = [
- ":src",
- "@gtest//:gtest_main",
+ ":hello_lib",
+ "@googletest//:gtest_main",
"@libcbor//:cbor",
],
)
@@ -40,7 +40,7 @@ cc_binary(
"main.cc",
],
deps = [
- ":src",
+ ":hello_lib",
],
)
diff --git a/examples/bazel/src/hello_test.cc b/examples/bazel/src/hello_test.cc
index 68d8633c8772..7aa85e79fc5a 100644
--- a/examples/bazel/src/hello_test.cc
+++ b/examples/bazel/src/hello_test.cc
@@ -1,10 +1,14 @@
#include "src/hello.h"
+#include "cbor.h"
#include "gtest/gtest.h"
-class HelloTest : public ::testing::Test {};
+class CborTest : public ::testing::Test {};
-TEST_F(HelloTest, CborVersion) {
- EXPECT_EQ(cbor_version(), 0);
+TEST_F(CborTest, IntegerItem) {
+ cbor_item_t * answer = cbor_build_uint8(42);
+ EXPECT_EQ(cbor_get_uint8(answer), 42);
+ cbor_decref(&answer);
+ EXPECT_EQ(answer, nullptr);
}
diff --git a/examples/bazel/third_party/libcbor.BUILD b/examples/bazel/third_party/libcbor.BUILD
deleted file mode 100644
index 45f4975b4fc8..000000000000
--- a/examples/bazel/third_party/libcbor.BUILD
+++ /dev/null
@@ -1,21 +0,0 @@
-cc_library(
- name = "cbor",
- srcs = glob([
- "src/**/*.h",
- "src/**/*.c",
- ]),
- hdrs = [
- "cbor.h",
- ] + glob([
- "cbor/*.h",
- ]),
- includes = [
- "src",
- "src/cbor",
- "src/cbor/internal",
- ],
- visibility = ["//visibility:public"],
- deps = [
- "@libcbor_bazel_example//third_party/libcbor:config",
- ],
-)
diff --git a/examples/bazel/third_party/libcbor/cbor/configuration.h b/examples/bazel/third_party/libcbor/cbor/configuration.h
index ddf6b9dc5f2b..070b54d9c2ae 100644
--- a/examples/bazel/third_party/libcbor/cbor/configuration.h
+++ b/examples/bazel/third_party/libcbor/cbor/configuration.h
@@ -2,7 +2,7 @@
#define LIBCBOR_CONFIGURATION_H
#define CBOR_MAJOR_VERSION 0
-#define CBOR_MINOR_VERSION 11
+#define CBOR_MINOR_VERSION 12
#define CBOR_PATCH_VERSION 0
#define CBOR_BUFFER_GROWTH 2
diff --git a/examples/cbor2cjson.c b/examples/cbor2cjson.c
index 99ddc9ee09e1..df6a5041b9ba 100644
--- a/examples/cbor2cjson.c
+++ b/examples/cbor2cjson.c
@@ -41,7 +41,8 @@ cJSON* cbor_to_cjson(cbor_item_t* item) {
case CBOR_TYPE_ARRAY: {
cJSON* result = cJSON_CreateArray();
for (size_t i = 0; i < cbor_array_size(item); i++) {
- cJSON_AddItemToArray(result, cbor_to_cjson(cbor_array_get(item, i)));
+ cJSON_AddItemToArray(result,
+ cbor_to_cjson(cbor_move(cbor_array_get(item, i))));
}
return result;
}
diff --git a/examples/cjson2cbor.c b/examples/cjson2cbor.c
index b67439902442..1182175d684d 100644
--- a/examples/cjson2cbor.c
+++ b/examples/cjson2cbor.c
@@ -22,10 +22,10 @@
#include "cbor/internal/builder_callbacks.h"
#include "cbor/internal/loaders.h"
-typedef void (*cbor_load_callback_t)(cJSON *, const struct cbor_callbacks *,
- void *);
+typedef void (*cbor_load_callback_t)(cJSON*, const struct cbor_callbacks*,
+ void*);
-cbor_item_t *cjson_cbor_load(void *source,
+cbor_item_t* cjson_cbor_load(void* source,
cbor_load_callback_t cbor_load_callback) {
static struct cbor_callbacks callbacks = {
.uint64 = &cbor_builder_uint64_callback,
@@ -51,9 +51,9 @@ cbor_item_t *cjson_cbor_load(void *source,
return context.root;
}
-void cjson_cbor_stream_decode(cJSON *source,
- const struct cbor_callbacks *callbacks,
- void *context) {
+void cjson_cbor_stream_decode(cJSON* source,
+ const struct cbor_callbacks* callbacks,
+ void* context) {
switch (source->type) {
case cJSON_False: {
callbacks->boolean(context, false);
@@ -83,13 +83,13 @@ void cjson_cbor_stream_decode(cJSON *source,
}
case cJSON_String: {
// XXX: Assume cJSON handled unicode correctly
- callbacks->string(context, (unsigned char *)source->valuestring,
+ callbacks->string(context, (unsigned char*)source->valuestring,
strlen(source->valuestring));
return;
}
case cJSON_Array: {
callbacks->array_start(context, cJSON_GetArraySize(source));
- cJSON *item = source->child;
+ cJSON* item = source->child;
while (item != NULL) {
cjson_cbor_stream_decode(item, callbacks, context);
item = item->next;
@@ -98,9 +98,9 @@ void cjson_cbor_stream_decode(cJSON *source,
}
case cJSON_Object: {
callbacks->map_start(context, cJSON_GetArraySize(source));
- cJSON *item = source->child;
+ cJSON* item = source->child;
while (item != NULL) {
- callbacks->string(context, (unsigned char *)item->string,
+ callbacks->string(context, (unsigned char*)item->string,
strlen(item->string));
cjson_cbor_stream_decode(item, callbacks, context);
item = item->next;
@@ -115,24 +115,24 @@ void usage(void) {
exit(1);
}
-int main(int argc, char *argv[]) {
+int main(int argc, char* argv[]) {
if (argc != 2) usage();
- FILE *f = fopen(argv[1], "rb");
+ FILE* f = fopen(argv[1], "rb");
if (f == NULL) usage();
/* Read input file into a buffer (cJSON doesn't work with streams) */
fseek(f, 0, SEEK_END);
size_t length = (size_t)ftell(f);
fseek(f, 0, SEEK_SET);
- char *json_buffer = malloc(length + 1);
+ char* json_buffer = malloc(length + 1);
fread(json_buffer, length, 1, f);
json_buffer[length] = '\0';
/* Convert between JSON and CBOR */
- cJSON *json = cJSON_Parse(json_buffer);
- cbor_item_t *cbor = cjson_cbor_load(json, cjson_cbor_stream_decode);
+ cJSON* json = cJSON_Parse(json_buffer);
+ cbor_item_t* cbor = cjson_cbor_load(json, cjson_cbor_stream_decode);
/* Print out CBOR bytes */
- unsigned char *buffer;
+ unsigned char* buffer;
size_t buffer_size;
cbor_serialize_alloc(cbor, &buffer, &buffer_size);
diff --git a/examples/sort.c b/examples/sort.c
index 22f3760b4843..66da12fd246a 100644
--- a/examples/sort.c
+++ b/examples/sort.c
@@ -14,9 +14,9 @@
* standard library functions.
*/
-int compareUint(const void *a, const void *b) {
- uint8_t av = cbor_get_uint8(*(cbor_item_t **)a),
- bv = cbor_get_uint8(*(cbor_item_t **)b);
+int compare_uint(const void* a, const void* b) {
+ uint8_t av = cbor_get_uint8(*(cbor_item_t**)a),
+ bv = cbor_get_uint8(*(cbor_item_t**)b);
if (av < bv)
return -1;
@@ -27,15 +27,15 @@ int compareUint(const void *a, const void *b) {
}
int main(void) {
- cbor_item_t *array = cbor_new_definite_array(4);
+ cbor_item_t* array = cbor_new_definite_array(4);
bool success = cbor_array_push(array, cbor_move(cbor_build_uint8(4)));
success &= cbor_array_push(array, cbor_move(cbor_build_uint8(3)));
success &= cbor_array_push(array, cbor_move(cbor_build_uint8(1)));
success &= cbor_array_push(array, cbor_move(cbor_build_uint8(2)));
if (!success) return 1;
- qsort(cbor_array_handle(array), cbor_array_size(array), sizeof(cbor_item_t *),
- compareUint);
+ qsort(cbor_array_handle(array), cbor_array_size(array), sizeof(cbor_item_t*),
+ compare_uint);
cbor_describe(array, stdout);
fflush(stdout);
diff --git a/examples/streaming_array.c b/examples/streaming_array.c
index d165e62b1c9e..f3e7295df0f3 100644
--- a/examples/streaming_array.c
+++ b/examples/streaming_array.c
@@ -30,7 +30,8 @@ void flush(size_t bytes) {
*/
int main(int argc, char* argv[]) {
if (argc != 2) usage();
- long n = strtol(argv[1], NULL, 10);
+ size_t n;
+ scanf(argv[1], "%zu", &n);
out = freopen(NULL, "wb", stdout);
if (!out) exit(1);
diff --git a/examples/streaming_parser.c b/examples/streaming_parser.c
index f5eacb4fb7ac..bb760ca8cd7c 100644
--- a/examples/streaming_parser.c
+++ b/examples/streaming_parser.c
@@ -9,12 +9,6 @@
#include <string.h>
#include "cbor.h"
-#ifdef __GNUC__
-#define UNUSED(x) __attribute__((__unused__)) x
-#else
-#define UNUSED(x) x
-#endif
-
void usage(void) {
printf("Usage: streaming_parser [input file]\n");
exit(1);
@@ -30,7 +24,7 @@ void usage(void) {
const char* key = "a secret key";
bool key_found = false;
-void find_string(void* UNUSED(_ctx), cbor_data buffer, uint64_t len) {
+void find_string(void* _ctx _CBOR_UNUSED, cbor_data buffer, uint64_t len) {
if (key_found) {
printf("Found the value: %.*s\n", (int)len, buffer);
key_found = false;
diff --git a/misc/hooks/pre-commit b/misc/hooks/pre-commit
index f3ac9f483799..16d6c37a94d7 100755
--- a/misc/hooks/pre-commit
+++ b/misc/hooks/pre-commit
@@ -2,10 +2,16 @@
set -e
-# Run clang-format and add modified files
+# Run cmake-lint, clang-format, and add modified files
MODIFIED_UNSTAGED=$(git -C . diff --name-only)
MODIFIED_STAGED=$(git -C . diff --name-only --cached --diff-filter=d)
+CMAKE_FILES=$(echo "${MODIFIED_STAGED} ${MODIFIED_UNSTAGED}" | grep -oE '(\S*)CMakeLists.txt' | cat)
+if ! cmake-lint --line-width 140 ${CMAKE_FILES} > /dev/null; then
+ echo "cmake-lint failed:"
+ cmake-lint --line-width 140 ${CMAKE_FILES}
+fi
+
./clang-format.sh
git add ${MODIFIED_STAGED}
@@ -15,4 +21,3 @@ if [[ ${MODIFIED_UNSTAGED} != $(git -C . diff --name-only) ]]; then
"them"
fi
-
diff --git a/misc/update_version.py b/misc/update_version.py
index 475953021cc4..22d175b4bc06 100755
--- a/misc/update_version.py
+++ b/misc/update_version.py
@@ -35,16 +35,16 @@ replace('Doxyfile', DOXY_VERSION + '.*', DOXY_VERSION + version)
# Update CMakeLists.txt
replace('CMakeLists.txt',
- '''SET\\(CBOR_VERSION_MAJOR "\d+"\\)
-SET\\(CBOR_VERSION_MINOR "\d+"\\)
-SET\\(CBOR_VERSION_PATCH "\d+"\\)''',
- f'''SET(CBOR_VERSION_MAJOR "{major}")
-SET(CBOR_VERSION_MINOR "{minor}")
-SET(CBOR_VERSION_PATCH "{patch}")''')
+ r'''set\(CBOR_VERSION_MAJOR "\d+"\)
+set\(CBOR_VERSION_MINOR "\d+"\)
+set\(CBOR_VERSION_PATCH "\d+"\)''',
+ f'''set(CBOR_VERSION_MAJOR "{major}")
+set(CBOR_VERSION_MINOR "{minor}")
+set(CBOR_VERSION_PATCH "{patch}")''')
# Update Basel build example
replace('examples/bazel/third_party/libcbor/cbor/configuration.h',
- '''#define CBOR_MAJOR_VERSION \d+
+ r'''#define CBOR_MAJOR_VERSION \d+
#define CBOR_MINOR_VERSION \d+
#define CBOR_PATCH_VERSION \d+''',
f'''#define CBOR_MAJOR_VERSION {major}
diff --git a/oss-fuzz/build.sh b/oss-fuzz/build.sh
index e7b1df3ada0a..504937221042 100755
--- a/oss-fuzz/build.sh
+++ b/oss-fuzz/build.sh
@@ -15,10 +15,14 @@
#
################################################################################
-mkdir build
-cd build
+mkdir oss_fuzz_build
+cd oss_fuzz_build
# We disable libcbor's default sanitizers since we'll be configuring them ourselves via CFLAGS.
-cmake -D CMAKE_BUILD_TYPE=Debug -D CMAKE_INSTALL_PREFIX="$WORK" -D SANITIZE=OFF ..
+cmake -D CMAKE_BUILD_TYPE=Debug \
+ -D CMAKE_INSTALL_PREFIX="$WORK" \
+ -D SANITIZE=OFF \
+ -D CMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF \
+ ..
make "-j$(nproc)"
make install
diff --git a/oss-fuzz/cbor_load_fuzzer.cc b/oss-fuzz/cbor_load_fuzzer.cc
index 0ab04e5a1374..6c681c344bf3 100644
--- a/oss-fuzz/cbor_load_fuzzer.cc
+++ b/oss-fuzz/cbor_load_fuzzer.cc
@@ -61,7 +61,7 @@ void *limited_realloc(void *ptr, size_t size) {
struct State {
FILE* fout;
- State() : fout(fopen("/dev/null", "r")) {
+ State() : fout(fopen("/dev/null", "w")) {
cbor_set_allocs(limited_malloc, limited_realloc, limited_free);
}
};
diff --git a/release.sh b/release.sh
index ec56862883eb..e16bcbc99b31 100755
--- a/release.sh
+++ b/release.sh
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Guides my forgetful self through the release process.
-# Usage release.sh VERSION
+# Usage: release.sh 0.42.0
set -e
@@ -17,9 +17,16 @@ function prompt() {
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
OUTDIR=$(mktemp -d)
TAG_NAME="v$1"
+BRANCH_NAME="release-$1"
+
+echo ">>>>> Bumping version"
cd $DIR
+git checkout -b "$BRANCH_NAME"
python3 misc/update_version.py "$1"
+git commit -a -m "Bump version to $1"
+git log -2
+prompt "Check the repository state, everything looks good?"
echo ">>>>> Checking changelog"
grep -A 10 -F "$1" CHANGELOG.md || true
@@ -30,7 +37,7 @@ grep PROJECT_NUMBER Doxyfile
prompt "Is the Doxyfile version correct?"
echo ">>>>> Checking CMakeLists"
-grep -A 2 'SET(CBOR_VERSION_MAJOR' CMakeLists.txt
+grep -A 2 'set(CBOR_VERSION_MAJOR' CMakeLists.txt
prompt "Is the CMake version correct?"
echo ">>>>> Checking Bazel build"
@@ -64,6 +71,14 @@ make
ctest
popd
+echo ">>>>> Pushing version bump branch"
+git push --set-upstream origin $(git rev-parse --abbrev-ref HEAD)
+echo "Open and merge PR: https://github.com/PJK/libcbor/pull/new/${BRANCH_NAME}"
+prompt "Did you merge the PR?"
+
+git checkout master
+git pull
+
prompt "Will proceed to tag the release with $TAG_NAME."
git commit -a -m "Release $TAG_NAME"
git tag "$TAG_NAME"
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e9312395db25..7b0a72bda872 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,70 +1,104 @@
-set(SOURCES cbor.c allocators.c cbor/streaming.c cbor/internal/encoders.c cbor/internal/builder_callbacks.c cbor/internal/loaders.c cbor/internal/memory_utils.c cbor/internal/stack.c cbor/internal/unicode.c cbor/encoding.c cbor/serialization.c cbor/arrays.c cbor/common.c cbor/floats_ctrls.c cbor/bytestrings.c cbor/callbacks.c cbor/strings.c cbor/maps.c cbor/tags.c cbor/ints.c)
+set(SOURCES
+ cbor.c
+ allocators.c
+ cbor/streaming.c
+ cbor/internal/encoders.c
+ cbor/internal/builder_callbacks.c
+ cbor/internal/loaders.c
+ cbor/internal/memory_utils.c
+ cbor/internal/stack.c
+ cbor/internal/unicode.c
+ cbor/encoding.c
+ cbor/serialization.c
+ cbor/arrays.c
+ cbor/common.c
+ cbor/floats_ctrls.c
+ cbor/bytestrings.c
+ cbor/callbacks.c
+ cbor/strings.c
+ cbor/maps.c
+ cbor/tags.c
+ cbor/ints.c)
include(JoinPaths)
include(CheckFunctionExists)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
-if (NOT DEFINED CMAKE_MACOSX_RPATH)
- set(CMAKE_MACOSX_RPATH 0)
+if(NOT DEFINED CMAKE_MACOSX_RPATH)
+ set(CMAKE_MACOSX_RPATH 0)
endif()
add_library(cbor ${SOURCES})
-target_include_directories(cbor PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
+target_include_directories(cbor PUBLIC
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
+ $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
+set_target_properties(cbor PROPERTIES EXPORT_NAME libcbor)
+# For vendored builds
+add_library(libcbor::libcbor ALIAS cbor)
# Explicitly link math.h if necessary
check_function_exists(ldexp LDEXP_AVAILABLE)
-if (NOT LDEXP_AVAILABLE)
- target_link_libraries(cbor m)
+if(NOT LDEXP_AVAILABLE)
+ target_link_libraries(cbor m)
endif()
include(GenerateExportHeader)
-generate_export_header(cbor EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/cbor/cbor_export.h)
-target_include_directories(cbor PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
-install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cbor/cbor_export.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cbor)
+generate_export_header(cbor EXPORT_FILE_NAME
+ ${CMAKE_CURRENT_BINARY_DIR}/cbor/cbor_export.h)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cbor/cbor_export.h
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cbor)
-if (NOT ${CBOR_VERSION_MAJOR} EQUAL 0)
- MESSAGE(FATAL_ERROR "Change the shared library version scheme to reflect https://github.com/PJK/libcbor/issues/52.")
+if(NOT ${CBOR_VERSION_MAJOR} EQUAL 0)
+ message(
+ FATAL_ERROR
+ "Change the shared library version scheme to reflect https://github.com/PJK/libcbor/issues/52."
+ )
endif()
-set_target_properties(cbor PROPERTIES
- VERSION ${CBOR_VERSION}
- MACHO_COMPATIBILITY_VERSION ${CBOR_VERSION_MAJOR}.${CBOR_VERSION_MINOR}.0
- SOVERSION ${CBOR_VERSION_MAJOR}.${CBOR_VERSION_MINOR})
+set_target_properties(
+ cbor
+ PROPERTIES VERSION ${CBOR_VERSION}
+ MACHO_COMPATIBILITY_VERSION
+ ${CBOR_VERSION_MAJOR}.${CBOR_VERSION_MINOR}.0
+ SOVERSION ${CBOR_VERSION_MAJOR}.${CBOR_VERSION_MINOR})
join_paths(libdir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
configure_file(libcbor.pc.in libcbor.pc @ONLY)
# http://www.cmake.org/Wiki/CMake:Install_Commands
-install(TARGETS cbor
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+install(
+ TARGETS cbor
+ EXPORT libcborTargets
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
-install(DIRECTORY cbor DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
- FILES_MATCHING PATTERN "*.h")
+install(
+ DIRECTORY cbor
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
+ FILES_MATCHING
+ PATTERN "*.h")
install(FILES cbor.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libcbor.pc"
- DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
+ DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
include(CMakePackageConfigHelpers)
configure_package_config_file(
- libcborConfig.cmake.in
- ${CMAKE_CURRENT_BINARY_DIR}/libcborConfig.cmake
+ libcborConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/libcborConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libcbor
- PATH_VARS CMAKE_INSTALL_INCLUDEDIR
-)
+ PATH_VARS CMAKE_INSTALL_INCLUDEDIR)
write_basic_package_version_file(
- ${CMAKE_CURRENT_BINARY_DIR}/libcborConfigVersion.cmake
- VERSION ${CBOR_VERSION}
- COMPATIBILITY SameMajorVersion
-)
-install(
- FILES
- ${CMAKE_CURRENT_BINARY_DIR}/libcborConfig.cmake
- ${CMAKE_CURRENT_BINARY_DIR}/libcborConfigVersion.cmake
- DESTINATION
- ${CMAKE_INSTALL_LIBDIR}/cmake/libcbor
- )
+ ${CMAKE_CURRENT_BINARY_DIR}/libcborConfigVersion.cmake
+ VERSION ${CBOR_VERSION}
+ COMPATIBILITY SameMajorVersion)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcborConfig.cmake
+ ${CMAKE_CURRENT_BINARY_DIR}/libcborConfigVersion.cmake
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libcbor)
+install(EXPORT libcborTargets
+ NAMESPACE libcbor::
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libcbor)
diff --git a/src/cbor.c b/src/cbor.c
index a8b4bcd7a080..819ff6077c34 100644
--- a/src/cbor.c
+++ b/src/cbor.c
@@ -9,9 +9,8 @@
#include "cbor/internal/builder_callbacks.h"
#include "cbor/internal/loaders.h"
-#pragma clang diagnostic push
-cbor_item_t *cbor_load(cbor_data source, size_t source_size,
- struct cbor_load_result *result) {
+cbor_item_t* cbor_load(cbor_data source, size_t source_size,
+ struct cbor_load_result* result) {
/* Context stack */
static struct cbor_callbacks callbacks = {
.uint8 = &cbor_builder_uint8_callback,
@@ -115,8 +114,8 @@ error:
return NULL;
}
-static cbor_item_t *_cbor_copy_int(cbor_item_t *item, bool negative) {
- cbor_item_t *res;
+static cbor_item_t* _cbor_copy_int(cbor_item_t* item, bool negative) {
+ cbor_item_t* res = NULL;
switch (cbor_int_get_width(item)) {
case CBOR_INT_8:
res = cbor_build_uint8(cbor_get_uint8(item));
@@ -137,8 +136,7 @@ static cbor_item_t *_cbor_copy_int(cbor_item_t *item, bool negative) {
return res;
}
-static cbor_item_t *_cbor_copy_float_ctrl(cbor_item_t *item) {
- // cppcheck-suppress missingReturn
+static cbor_item_t* _cbor_copy_float_ctrl(cbor_item_t* item) {
switch (cbor_float_get_width(item)) {
case CBOR_FLOAT_0:
return cbor_build_ctrl(cbor_ctrl_value(item));
@@ -148,11 +146,13 @@ static cbor_item_t *_cbor_copy_float_ctrl(cbor_item_t *item) {
return cbor_build_float4(cbor_float_get_float4(item));
case CBOR_FLOAT_64:
return cbor_build_float8(cbor_float_get_float8(item));
+ default:
+ _CBOR_UNREACHABLE;
+ return NULL;
}
}
-cbor_item_t *cbor_copy(cbor_item_t *item) {
- // cppcheck-suppress missingReturn
+cbor_item_t* cbor_copy(cbor_item_t* item) {
switch (cbor_typeof(item)) {
case CBOR_TYPE_UINT:
return _cbor_copy_int(item, false);
@@ -163,13 +163,13 @@ cbor_item_t *cbor_copy(cbor_item_t *item) {
return cbor_build_bytestring(cbor_bytestring_handle(item),
cbor_bytestring_length(item));
} else {
- cbor_item_t *res = cbor_new_indefinite_bytestring();
+ cbor_item_t* res = cbor_new_indefinite_bytestring();
if (res == NULL) {
return NULL;
}
for (size_t i = 0; i < cbor_bytestring_chunk_count(item); i++) {
- cbor_item_t *chunk_copy =
+ cbor_item_t* chunk_copy =
cbor_copy(cbor_bytestring_chunks_handle(item)[i]);
if (chunk_copy == NULL) {
cbor_decref(&res);
@@ -186,16 +186,16 @@ cbor_item_t *cbor_copy(cbor_item_t *item) {
}
case CBOR_TYPE_STRING:
if (cbor_string_is_definite(item)) {
- return cbor_build_stringn((const char *)cbor_string_handle(item),
+ return cbor_build_stringn((const char*)cbor_string_handle(item),
cbor_string_length(item));
} else {
- cbor_item_t *res = cbor_new_indefinite_string();
+ cbor_item_t* res = cbor_new_indefinite_string();
if (res == NULL) {
return NULL;
}
for (size_t i = 0; i < cbor_string_chunk_count(item); i++) {
- cbor_item_t *chunk_copy =
+ cbor_item_t* chunk_copy =
cbor_copy(cbor_string_chunks_handle(item)[i]);
if (chunk_copy == NULL) {
cbor_decref(&res);
@@ -211,7 +211,7 @@ cbor_item_t *cbor_copy(cbor_item_t *item) {
return res;
}
case CBOR_TYPE_ARRAY: {
- cbor_item_t *res;
+ cbor_item_t* res;
if (cbor_array_is_definite(item)) {
res = cbor_new_definite_array(cbor_array_size(item));
} else {
@@ -222,7 +222,7 @@ cbor_item_t *cbor_copy(cbor_item_t *item) {
}
for (size_t i = 0; i < cbor_array_size(item); i++) {
- cbor_item_t *entry_copy = cbor_copy(cbor_move(cbor_array_get(item, i)));
+ cbor_item_t* entry_copy = cbor_copy(cbor_move(cbor_array_get(item, i)));
if (entry_copy == NULL) {
cbor_decref(&res);
return NULL;
@@ -237,7 +237,7 @@ cbor_item_t *cbor_copy(cbor_item_t *item) {
return res;
}
case CBOR_TYPE_MAP: {
- cbor_item_t *res;
+ cbor_item_t* res;
if (cbor_map_is_definite(item)) {
res = cbor_new_definite_map(cbor_map_size(item));
} else {
@@ -247,14 +247,14 @@ cbor_item_t *cbor_copy(cbor_item_t *item) {
return NULL;
}
- struct cbor_pair *it = cbor_map_handle(item);
+ struct cbor_pair* it = cbor_map_handle(item);
for (size_t i = 0; i < cbor_map_size(item); i++) {
- cbor_item_t *key_copy = cbor_copy(it[i].key);
+ cbor_item_t* key_copy = cbor_copy(it[i].key);
if (key_copy == NULL) {
cbor_decref(&res);
return NULL;
}
- cbor_item_t *value_copy = cbor_copy(it[i].value);
+ cbor_item_t* value_copy = cbor_copy(it[i].value);
if (value_copy == NULL) {
cbor_decref(&res);
cbor_decref(&key_copy);
@@ -273,16 +273,19 @@ cbor_item_t *cbor_copy(cbor_item_t *item) {
return res;
}
case CBOR_TYPE_TAG: {
- cbor_item_t *item_copy = cbor_copy(cbor_move(cbor_tag_item(item)));
+ cbor_item_t* item_copy = cbor_copy(cbor_move(cbor_tag_item(item)));
if (item_copy == NULL) {
return NULL;
}
- cbor_item_t *tag = cbor_build_tag(cbor_tag_value(item), item_copy);
+ cbor_item_t* tag = cbor_build_tag(cbor_tag_value(item), item_copy);
cbor_decref(&item_copy);
return tag;
}
case CBOR_TYPE_FLOAT_CTRL:
return _cbor_copy_float_ctrl(item);
+ default:
+ _CBOR_UNREACHABLE;
+ return NULL;
}
}
@@ -301,11 +304,11 @@ static int _pow(int b, int ex) {
return res;
}
-static void _cbor_type_marquee(FILE *out, char *label, int indent) {
+static void _cbor_type_marquee(FILE* out, char* label, int indent) {
fprintf(out, "%*.*s[%s] ", indent, indent, " ", label);
}
-static void _cbor_nested_describe(cbor_item_t *item, FILE *out, int indent) {
+static void _cbor_nested_describe(cbor_item_t* item, FILE* out, int indent) {
const int indent_offset = 4;
switch (cbor_typeof(item)) {
case CBOR_TYPE_UINT: {
@@ -329,7 +332,7 @@ static void _cbor_nested_describe(cbor_item_t *item, FILE *out, int indent) {
_cbor_nested_describe(cbor_bytestring_chunks_handle(item)[i], out,
indent + indent_offset);
} else {
- const unsigned char *data = cbor_bytestring_handle(item);
+ const unsigned char* data = cbor_bytestring_handle(item);
fprintf(out, "Definite, Length: %zuB, Data:\n",
cbor_bytestring_length(item));
fprintf(out, "%*s", indent + indent_offset, " ");
@@ -418,7 +421,7 @@ static void _cbor_nested_describe(cbor_item_t *item, FILE *out, int indent) {
}
}
-void cbor_describe(cbor_item_t *item, FILE *out) {
+void cbor_describe(cbor_item_t* item, FILE* out) {
_cbor_nested_describe(item, out, 0);
}
diff --git a/src/cbor/arrays.c b/src/cbor/arrays.c
index a23bbe3cd152..174c97e9a61e 100644
--- a/src/cbor/arrays.c
+++ b/src/cbor/arrays.c
@@ -9,21 +9,21 @@
#include <string.h>
#include "internal/memory_utils.h"
-size_t cbor_array_size(const cbor_item_t *item) {
+size_t cbor_array_size(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_array(item));
return item->metadata.array_metadata.end_ptr;
}
-size_t cbor_array_allocated(const cbor_item_t *item) {
+size_t cbor_array_allocated(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_array(item));
return item->metadata.array_metadata.allocated;
}
-cbor_item_t *cbor_array_get(const cbor_item_t *item, size_t index) {
- return cbor_incref(((cbor_item_t **)item->data)[index]);
+cbor_item_t* cbor_array_get(const cbor_item_t* item, size_t index) {
+ return cbor_incref(((cbor_item_t**)item->data)[index]);
}
-bool cbor_array_set(cbor_item_t *item, size_t index, cbor_item_t *value) {
+bool cbor_array_set(cbor_item_t* item, size_t index, cbor_item_t* value) {
if (index == item->metadata.array_metadata.end_ptr) {
return cbor_array_push(item, value);
} else if (index < item->metadata.array_metadata.end_ptr) {
@@ -33,19 +33,19 @@ bool cbor_array_set(cbor_item_t *item, size_t index, cbor_item_t *value) {
}
}
-bool cbor_array_replace(cbor_item_t *item, size_t index, cbor_item_t *value) {
+bool cbor_array_replace(cbor_item_t* item, size_t index, cbor_item_t* value) {
if (index >= item->metadata.array_metadata.end_ptr) return false;
/* We cannot use cbor_array_get as that would increase the refcount */
- cbor_intermediate_decref(((cbor_item_t **)item->data)[index]);
- ((cbor_item_t **)item->data)[index] = cbor_incref(value);
+ cbor_intermediate_decref(((cbor_item_t**)item->data)[index]);
+ ((cbor_item_t**)item->data)[index] = cbor_incref(value);
return true;
}
-bool cbor_array_push(cbor_item_t *array, cbor_item_t *pushee) {
+bool cbor_array_push(cbor_item_t* array, cbor_item_t* pushee) {
CBOR_ASSERT(cbor_isa_array(array));
- struct _cbor_array_metadata *metadata =
- (struct _cbor_array_metadata *)&array->metadata;
- cbor_item_t **data = (cbor_item_t **)array->data;
+ struct _cbor_array_metadata* metadata =
+ (struct _cbor_array_metadata*)&array->metadata;
+ cbor_item_t** data = (cbor_item_t**)array->data;
if (cbor_array_is_definite(array)) {
/* Do not reallocate definite arrays */
if (metadata->end_ptr >= metadata->allocated) {
@@ -64,8 +64,8 @@ bool cbor_array_push(cbor_item_t *array, cbor_item_t *pushee) {
? 1
: CBOR_BUFFER_GROWTH * metadata->allocated;
- unsigned char *new_data = _cbor_realloc_multiple(
- array->data, sizeof(cbor_item_t *), new_allocation);
+ unsigned char* new_data = _cbor_realloc_multiple(
+ array->data, sizeof(cbor_item_t*), new_allocation);
if (new_data == NULL) {
return false;
}
@@ -73,31 +73,31 @@ bool cbor_array_push(cbor_item_t *array, cbor_item_t *pushee) {
array->data = new_data;
metadata->allocated = new_allocation;
}
- ((cbor_item_t **)array->data)[metadata->end_ptr++] = pushee;
+ ((cbor_item_t**)array->data)[metadata->end_ptr++] = pushee;
}
cbor_incref(pushee);
return true;
}
-bool cbor_array_is_definite(const cbor_item_t *item) {
+bool cbor_array_is_definite(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_array(item));
return item->metadata.array_metadata.type == _CBOR_METADATA_DEFINITE;
}
-bool cbor_array_is_indefinite(const cbor_item_t *item) {
+bool cbor_array_is_indefinite(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_array(item));
return item->metadata.array_metadata.type == _CBOR_METADATA_INDEFINITE;
}
-cbor_item_t **cbor_array_handle(const cbor_item_t *item) {
+cbor_item_t** cbor_array_handle(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_array(item));
- return (cbor_item_t **)item->data;
+ return (cbor_item_t**)item->data;
}
-cbor_item_t *cbor_new_definite_array(size_t size) {
- cbor_item_t *item = _cbor_malloc(sizeof(cbor_item_t));
+cbor_item_t* cbor_new_definite_array(size_t size) {
+ cbor_item_t* item = _cbor_malloc(sizeof(cbor_item_t));
_CBOR_NOTNULL(item);
- cbor_item_t **data = _cbor_alloc_multiple(sizeof(cbor_item_t *), size);
+ cbor_item_t** data = _cbor_alloc_multiple(sizeof(cbor_item_t*), size);
_CBOR_DEPENDENT_NOTNULL(item, data);
for (size_t i = 0; i < size; i++) {
@@ -110,13 +110,13 @@ cbor_item_t *cbor_new_definite_array(size_t size) {
.metadata = {.array_metadata = {.type = _CBOR_METADATA_DEFINITE,
.allocated = size,
.end_ptr = 0}},
- .data = (unsigned char *)data};
+ .data = (unsigned char*)data};
return item;
}
-cbor_item_t *cbor_new_indefinite_array(void) {
- cbor_item_t *item = _cbor_malloc(sizeof(cbor_item_t));
+cbor_item_t* cbor_new_indefinite_array(void) {
+ cbor_item_t* item = _cbor_malloc(sizeof(cbor_item_t));
_CBOR_NOTNULL(item);
*item = (cbor_item_t){
diff --git a/src/cbor/bytestrings.c b/src/cbor/bytestrings.c
index 528937179aee..f8290a56328a 100644
--- a/src/cbor/bytestrings.c
+++ b/src/cbor/bytestrings.c
@@ -9,27 +9,27 @@
#include <string.h>
#include "internal/memory_utils.h"
-size_t cbor_bytestring_length(const cbor_item_t *item) {
+size_t cbor_bytestring_length(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_bytestring(item));
return item->metadata.bytestring_metadata.length;
}
-unsigned char *cbor_bytestring_handle(const cbor_item_t *item) {
+unsigned char* cbor_bytestring_handle(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_bytestring(item));
return item->data;
}
-bool cbor_bytestring_is_definite(const cbor_item_t *item) {
+bool cbor_bytestring_is_definite(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_bytestring(item));
return item->metadata.bytestring_metadata.type == _CBOR_METADATA_DEFINITE;
}
-bool cbor_bytestring_is_indefinite(const cbor_item_t *item) {
+bool cbor_bytestring_is_indefinite(const cbor_item_t* item) {
return !cbor_bytestring_is_definite(item);
}
-cbor_item_t *cbor_new_definite_bytestring(void) {
- cbor_item_t *item = _cbor_malloc(sizeof(cbor_item_t));
+cbor_item_t* cbor_new_definite_bytestring(void) {
+ cbor_item_t* item = _cbor_malloc(sizeof(cbor_item_t));
_CBOR_NOTNULL(item);
*item = (cbor_item_t){
.refcount = 1,
@@ -39,8 +39,8 @@ cbor_item_t *cbor_new_definite_bytestring(void) {
return item;
}
-cbor_item_t *cbor_new_indefinite_bytestring(void) {
- cbor_item_t *item = _cbor_malloc(sizeof(cbor_item_t));
+cbor_item_t* cbor_new_indefinite_bytestring(void) {
+ cbor_item_t* item = _cbor_malloc(sizeof(cbor_item_t));
_CBOR_NOTNULL(item);
*item = (cbor_item_t){
.refcount = 1,
@@ -49,7 +49,7 @@ cbor_item_t *cbor_new_indefinite_bytestring(void) {
.length = 0}},
.data = _cbor_malloc(sizeof(struct cbor_indefinite_string_data))};
_CBOR_DEPENDENT_NOTNULL(item, item->data);
- *((struct cbor_indefinite_string_data *)item->data) =
+ *((struct cbor_indefinite_string_data*)item->data) =
(struct cbor_indefinite_string_data){
.chunk_count = 0,
.chunk_capacity = 0,
@@ -58,17 +58,17 @@ cbor_item_t *cbor_new_indefinite_bytestring(void) {
return item;
}
-cbor_item_t *cbor_build_bytestring(cbor_data handle, size_t length) {
- cbor_item_t *item = cbor_new_definite_bytestring();
+cbor_item_t* cbor_build_bytestring(cbor_data handle, size_t length) {
+ cbor_item_t* item = cbor_new_definite_bytestring();
_CBOR_NOTNULL(item);
- void *content = _cbor_malloc(length);
+ void* content = _cbor_malloc(length);
_CBOR_DEPENDENT_NOTNULL(item, content);
memcpy(content, handle, length);
cbor_bytestring_set_handle(item, content, length);
return item;
}
-void cbor_bytestring_set_handle(cbor_item_t *item,
+void cbor_bytestring_set_handle(cbor_item_t* item,
cbor_mutable_data CBOR_RESTRICT_POINTER data,
size_t length) {
CBOR_ASSERT(cbor_isa_bytestring(item));
@@ -77,25 +77,25 @@ void cbor_bytestring_set_handle(cbor_item_t *item,
item->metadata.bytestring_metadata.length = length;
}
-cbor_item_t **cbor_bytestring_chunks_handle(const cbor_item_t *item) {
+cbor_item_t** cbor_bytestring_chunks_handle(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_bytestring(item));
CBOR_ASSERT(cbor_bytestring_is_indefinite(item));
- return ((struct cbor_indefinite_string_data *)item->data)->chunks;
+ return ((struct cbor_indefinite_string_data*)item->data)->chunks;
}
-size_t cbor_bytestring_chunk_count(const cbor_item_t *item) {
+size_t cbor_bytestring_chunk_count(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_bytestring(item));
CBOR_ASSERT(cbor_bytestring_is_indefinite(item));
- return ((struct cbor_indefinite_string_data *)item->data)->chunk_count;
+ return ((struct cbor_indefinite_string_data*)item->data)->chunk_count;
}
-bool cbor_bytestring_add_chunk(cbor_item_t *item, cbor_item_t *chunk) {
+bool cbor_bytestring_add_chunk(cbor_item_t* item, cbor_item_t* chunk) {
CBOR_ASSERT(cbor_isa_bytestring(item));
CBOR_ASSERT(cbor_bytestring_is_indefinite(item));
CBOR_ASSERT(cbor_isa_bytestring(chunk));
CBOR_ASSERT(cbor_bytestring_is_definite(chunk));
- struct cbor_indefinite_string_data *data =
- (struct cbor_indefinite_string_data *)item->data;
+ struct cbor_indefinite_string_data* data =
+ (struct cbor_indefinite_string_data*)item->data;
if (data->chunk_count == data->chunk_capacity) {
if (!_cbor_safe_to_multiply(CBOR_BUFFER_GROWTH, data->chunk_capacity)) {
return false;
@@ -105,8 +105,8 @@ bool cbor_bytestring_add_chunk(cbor_item_t *item, cbor_item_t *chunk) {
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);
+ cbor_item_t** new_chunks_data = _cbor_realloc_multiple(
+ data->chunks, sizeof(cbor_item_t*), new_chunk_capacity);
if (new_chunks_data == NULL) {
return false;
diff --git a/src/cbor/bytestrings.h b/src/cbor/bytestrings.h
index cacd1adf95f3..59cae2add7f3 100644
--- a/src/cbor/bytestrings.h
+++ b/src/cbor/bytestrings.h
@@ -29,7 +29,7 @@ extern "C" {
* @return length of the binary data. Zero if no chunk has been attached yet
*/
_CBOR_NODISCARD
-CBOR_EXPORT size_t cbor_bytestring_length(const cbor_item_t *item);
+CBOR_EXPORT size_t cbor_bytestring_length(const cbor_item_t* item);
/** Is the byte string definite?
*
@@ -37,7 +37,7 @@ CBOR_EXPORT size_t cbor_bytestring_length(const cbor_item_t *item);
* @return Is the byte string definite?
*/
_CBOR_NODISCARD
-CBOR_EXPORT bool cbor_bytestring_is_definite(const cbor_item_t *item);
+CBOR_EXPORT bool cbor_bytestring_is_definite(const cbor_item_t* item);
/** Is the byte string indefinite?
*
@@ -45,7 +45,7 @@ CBOR_EXPORT bool cbor_bytestring_is_definite(const cbor_item_t *item);
* @return Is the byte string indefinite?
*/
_CBOR_NODISCARD
-CBOR_EXPORT bool cbor_bytestring_is_indefinite(const cbor_item_t *item);
+CBOR_EXPORT bool cbor_bytestring_is_indefinite(const cbor_item_t* item);
/** Get the handle to the binary data
*
@@ -58,7 +58,7 @@ CBOR_EXPORT bool cbor_bytestring_is_indefinite(const cbor_item_t *item);
* yet.
*/
_CBOR_NODISCARD
-CBOR_EXPORT cbor_mutable_data cbor_bytestring_handle(const cbor_item_t *item);
+CBOR_EXPORT cbor_mutable_data cbor_bytestring_handle(const cbor_item_t* item);
/** Set the handle to the binary data
*
@@ -69,7 +69,7 @@ CBOR_EXPORT cbor_mutable_data cbor_bytestring_handle(const cbor_item_t *item);
* @param length Length of the data block
*/
CBOR_EXPORT void cbor_bytestring_set_handle(
- cbor_item_t *item, cbor_mutable_data CBOR_RESTRICT_POINTER data,
+ cbor_item_t* item, cbor_mutable_data CBOR_RESTRICT_POINTER data,
size_t length);
/** Get the handle to the array of chunks
@@ -81,8 +81,8 @@ CBOR_EXPORT void cbor_bytestring_set_handle(
* @return array of #cbor_bytestring_chunk_count definite bytestrings
*/
_CBOR_NODISCARD
-CBOR_EXPORT cbor_item_t **cbor_bytestring_chunks_handle(
- const cbor_item_t *item);
+CBOR_EXPORT cbor_item_t** cbor_bytestring_chunks_handle(
+ const cbor_item_t* item);
/** Get the number of chunks this string consist of
*
@@ -90,7 +90,7 @@ CBOR_EXPORT cbor_item_t **cbor_bytestring_chunks_handle(
* @return The chunk count. 0 for freshly created items.
*/
_CBOR_NODISCARD
-CBOR_EXPORT size_t cbor_bytestring_chunk_count(const cbor_item_t *item);
+CBOR_EXPORT size_t cbor_bytestring_chunk_count(const cbor_item_t* item);
/** Appends a chunk to the bytestring
*
@@ -105,8 +105,8 @@ CBOR_EXPORT size_t cbor_bytestring_chunk_count(const cbor_item_t *item);
* of `chunk` is not increased and the `item` is left intact.
*/
_CBOR_NODISCARD
-CBOR_EXPORT bool cbor_bytestring_add_chunk(cbor_item_t *item,
- cbor_item_t *chunk);
+CBOR_EXPORT bool cbor_bytestring_add_chunk(cbor_item_t* item,
+ cbor_item_t* chunk);
/** Creates a new definite byte string
*
@@ -117,7 +117,7 @@ CBOR_EXPORT bool cbor_bytestring_add_chunk(cbor_item_t *item,
* @return `NULL` if memory allocation fails
*/
_CBOR_NODISCARD
-CBOR_EXPORT cbor_item_t *cbor_new_definite_bytestring(void);
+CBOR_EXPORT cbor_item_t* cbor_new_definite_bytestring(void);
/** Creates a new indefinite byte string
*
@@ -128,7 +128,7 @@ CBOR_EXPORT cbor_item_t *cbor_new_definite_bytestring(void);
* @return `NULL` if memory allocation fails
*/
_CBOR_NODISCARD
-CBOR_EXPORT cbor_item_t *cbor_new_indefinite_bytestring(void);
+CBOR_EXPORT cbor_item_t* cbor_new_indefinite_bytestring(void);
/** Creates a new byte string and initializes it
*
@@ -141,7 +141,7 @@ CBOR_EXPORT cbor_item_t *cbor_new_indefinite_bytestring(void);
* @return `NULL` if memory allocation fails
*/
_CBOR_NODISCARD
-CBOR_EXPORT cbor_item_t *cbor_build_bytestring(cbor_data handle, size_t length);
+CBOR_EXPORT cbor_item_t* cbor_build_bytestring(cbor_data handle, size_t length);
#ifdef __cplusplus
}
diff --git a/src/cbor/callbacks.c b/src/cbor/callbacks.c
index bdf3f79eee69..2b58edaa0bc0 100644
--- a/src/cbor/callbacks.c
+++ b/src/cbor/callbacks.c
@@ -7,72 +7,72 @@
#include "callbacks.h"
-void cbor_null_uint8_callback(void *_CBOR_UNUSED(_ctx),
- uint8_t _CBOR_UNUSED(_val)) {}
+void cbor_null_uint8_callback(void* _ctx _CBOR_UNUSED,
+ uint8_t _CBOR_UNUSED _val) {}
-void cbor_null_uint16_callback(void *_CBOR_UNUSED(_ctx),
- uint16_t _CBOR_UNUSED(_val)) {}
+void cbor_null_uint16_callback(void* _ctx _CBOR_UNUSED,
+ uint16_t _CBOR_UNUSED _val) {}
-void cbor_null_uint32_callback(void *_CBOR_UNUSED(_ctx),
- uint32_t _CBOR_UNUSED(_val)) {}
+void cbor_null_uint32_callback(void* _ctx _CBOR_UNUSED,
+ uint32_t _CBOR_UNUSED _val) {}
-void cbor_null_uint64_callback(void *_CBOR_UNUSED(_ctx),
- uint64_t _CBOR_UNUSED(_val)) {}
+void cbor_null_uint64_callback(void* _ctx _CBOR_UNUSED,
+ uint64_t _CBOR_UNUSED _val) {}
-void cbor_null_negint8_callback(void *_CBOR_UNUSED(_ctx),
- uint8_t _CBOR_UNUSED(_val)) {}
+void cbor_null_negint8_callback(void* _ctx _CBOR_UNUSED,
+ uint8_t _CBOR_UNUSED _val) {}
-void cbor_null_negint16_callback(void *_CBOR_UNUSED(_ctx),
- uint16_t _CBOR_UNUSED(_val)) {}
+void cbor_null_negint16_callback(void* _ctx _CBOR_UNUSED,
+ uint16_t _CBOR_UNUSED _val) {}
-void cbor_null_negint32_callback(void *_CBOR_UNUSED(_ctx),
- uint32_t _CBOR_UNUSED(_val)) {}
+void cbor_null_negint32_callback(void* _ctx _CBOR_UNUSED,
+ uint32_t _CBOR_UNUSED _val) {}
-void cbor_null_negint64_callback(void *_CBOR_UNUSED(_ctx),
- uint64_t _CBOR_UNUSED(_val)) {}
+void cbor_null_negint64_callback(void* _ctx _CBOR_UNUSED,
+ uint64_t _CBOR_UNUSED _val) {}
-void cbor_null_string_callback(void *_CBOR_UNUSED(_ctx),
- cbor_data _CBOR_UNUSED(_val),
- uint64_t _CBOR_UNUSED(_val2)) {}
+void cbor_null_string_callback(void* _ctx _CBOR_UNUSED,
+ cbor_data _CBOR_UNUSED _val,
+ uint64_t _CBOR_UNUSED _val2) {}
-void cbor_null_string_start_callback(void *_CBOR_UNUSED(_ctx)) {}
+void cbor_null_string_start_callback(void* _ctx _CBOR_UNUSED) {}
-void cbor_null_byte_string_callback(void *_CBOR_UNUSED(_ctx),
- cbor_data _CBOR_UNUSED(_val),
- uint64_t _CBOR_UNUSED(_val2)) {}
+void cbor_null_byte_string_callback(void* _ctx _CBOR_UNUSED,
+ cbor_data _CBOR_UNUSED _val,
+ uint64_t _CBOR_UNUSED _val2) {}
-void cbor_null_byte_string_start_callback(void *_CBOR_UNUSED(_ctx)) {}
+void cbor_null_byte_string_start_callback(void* _ctx _CBOR_UNUSED) {}
-void cbor_null_array_start_callback(void *_CBOR_UNUSED(_ctx),
- uint64_t _CBOR_UNUSED(_val)) {}
+void cbor_null_array_start_callback(void* _ctx _CBOR_UNUSED,
+ uint64_t _CBOR_UNUSED _val) {}
-void cbor_null_indef_array_start_callback(void *_CBOR_UNUSED(_ctx)) {}
+void cbor_null_indef_array_start_callback(void* _ctx _CBOR_UNUSED) {}
-void cbor_null_map_start_callback(void *_CBOR_UNUSED(_ctx),
- uint64_t _CBOR_UNUSED(_val)) {}
+void cbor_null_map_start_callback(void* _ctx _CBOR_UNUSED,
+ uint64_t _CBOR_UNUSED _val) {}
-void cbor_null_indef_map_start_callback(void *_CBOR_UNUSED(_ctx)) {}
+void cbor_null_indef_map_start_callback(void* _ctx _CBOR_UNUSED) {}
-void cbor_null_tag_callback(void *_CBOR_UNUSED(_ctx),
- uint64_t _CBOR_UNUSED(_val)) {}
+void cbor_null_tag_callback(void* _ctx _CBOR_UNUSED,
+ uint64_t _CBOR_UNUSED _val) {}
-void cbor_null_float2_callback(void *_CBOR_UNUSED(_ctx),
- float _CBOR_UNUSED(_val)) {}
+void cbor_null_float2_callback(void* _ctx _CBOR_UNUSED,
+ float _CBOR_UNUSED _val) {}
-void cbor_null_float4_callback(void *_CBOR_UNUSED(_ctx),
- float _CBOR_UNUSED(_val)) {}
+void cbor_null_float4_callback(void* _ctx _CBOR_UNUSED,
+ float _CBOR_UNUSED _val) {}
-void cbor_null_float8_callback(void *_CBOR_UNUSED(_ctx),
- double _CBOR_UNUSED(_val)) {}
+void cbor_null_float8_callback(void* _ctx _CBOR_UNUSED,
+ double _CBOR_UNUSED _val) {}
-void cbor_null_null_callback(void *_CBOR_UNUSED(_ctx)) {}
+void cbor_null_null_callback(void* _ctx _CBOR_UNUSED) {}
-void cbor_null_undefined_callback(void *_CBOR_UNUSED(_ctx)) {}
+void cbor_null_undefined_callback(void* _ctx _CBOR_UNUSED) {}
-void cbor_null_boolean_callback(void *_CBOR_UNUSED(_ctx),
- bool _CBOR_UNUSED(_val)) {}
+void cbor_null_boolean_callback(void* _ctx _CBOR_UNUSED,
+ bool _CBOR_UNUSED _val) {}
-void cbor_null_indef_break_callback(void *_CBOR_UNUSED(_ctx)) {}
+void cbor_null_indef_break_callback(void* _ctx _CBOR_UNUSED) {}
CBOR_EXPORT const struct cbor_callbacks cbor_empty_callbacks = {
/* Type 0 - Unsigned integers */
diff --git a/src/cbor/callbacks.h b/src/cbor/callbacks.h
index c7ae20568dc8..f5fab43bc711 100644
--- a/src/cbor/callbacks.h
+++ b/src/cbor/callbacks.h
@@ -18,34 +18,34 @@ extern "C" {
#endif
/** Callback prototype */
-typedef void (*cbor_int8_callback)(void *, uint8_t);
+typedef void (*cbor_int8_callback)(void*, uint8_t);
/** Callback prototype */
-typedef void (*cbor_int16_callback)(void *, uint16_t);
+typedef void (*cbor_int16_callback)(void*, uint16_t);
/** Callback prototype */
-typedef void (*cbor_int32_callback)(void *, uint32_t);
+typedef void (*cbor_int32_callback)(void*, uint32_t);
/** Callback prototype */
-typedef void (*cbor_int64_callback)(void *, uint64_t);
+typedef void (*cbor_int64_callback)(void*, uint64_t);
/** Callback prototype */
-typedef void (*cbor_simple_callback)(void *);
+typedef void (*cbor_simple_callback)(void*);
/** Callback prototype */
-typedef void (*cbor_string_callback)(void *, cbor_data, uint64_t);
+typedef void (*cbor_string_callback)(void*, cbor_data, uint64_t);
/** Callback prototype */
-typedef void (*cbor_collection_callback)(void *, uint64_t);
+typedef void (*cbor_collection_callback)(void*, uint64_t);
/** Callback prototype */
-typedef void (*cbor_float_callback)(void *, float);
+typedef void (*cbor_float_callback)(void*, float);
/** Callback prototype */
-typedef void (*cbor_double_callback)(void *, double);
+typedef void (*cbor_double_callback)(void*, double);
/** Callback prototype */
-typedef void (*cbor_bool_callback)(void *, bool);
+typedef void (*cbor_bool_callback)(void*, bool);
/** Callback bundle -- passed to the decoder */
struct cbor_callbacks {
@@ -108,76 +108,76 @@ struct cbor_callbacks {
};
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_uint8_callback(void *, uint8_t);
+CBOR_EXPORT void cbor_null_uint8_callback(void*, uint8_t);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_uint16_callback(void *, uint16_t);
+CBOR_EXPORT void cbor_null_uint16_callback(void*, uint16_t);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_uint32_callback(void *, uint32_t);
+CBOR_EXPORT void cbor_null_uint32_callback(void*, uint32_t);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_uint64_callback(void *, uint64_t);
+CBOR_EXPORT void cbor_null_uint64_callback(void*, uint64_t);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_negint8_callback(void *, uint8_t);
+CBOR_EXPORT void cbor_null_negint8_callback(void*, uint8_t);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_negint16_callback(void *, uint16_t);
+CBOR_EXPORT void cbor_null_negint16_callback(void*, uint16_t);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_negint32_callback(void *, uint32_t);
+CBOR_EXPORT void cbor_null_negint32_callback(void*, uint32_t);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_negint64_callback(void *, uint64_t);
+CBOR_EXPORT void cbor_null_negint64_callback(void*, uint64_t);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_string_callback(void *, cbor_data, uint64_t);
+CBOR_EXPORT void cbor_null_string_callback(void*, cbor_data, uint64_t);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_string_start_callback(void *);
+CBOR_EXPORT void cbor_null_string_start_callback(void*);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_byte_string_callback(void *, cbor_data, uint64_t);
+CBOR_EXPORT void cbor_null_byte_string_callback(void*, cbor_data, uint64_t);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_byte_string_start_callback(void *);
+CBOR_EXPORT void cbor_null_byte_string_start_callback(void*);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_array_start_callback(void *, uint64_t);
+CBOR_EXPORT void cbor_null_array_start_callback(void*, uint64_t);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_indef_array_start_callback(void *);
+CBOR_EXPORT void cbor_null_indef_array_start_callback(void*);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_map_start_callback(void *, uint64_t);
+CBOR_EXPORT void cbor_null_map_start_callback(void*, uint64_t);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_indef_map_start_callback(void *);
+CBOR_EXPORT void cbor_null_indef_map_start_callback(void*);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_tag_callback(void *, uint64_t);
+CBOR_EXPORT void cbor_null_tag_callback(void*, uint64_t);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_float2_callback(void *, float);
+CBOR_EXPORT void cbor_null_float2_callback(void*, float);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_float4_callback(void *, float);
+CBOR_EXPORT void cbor_null_float4_callback(void*, float);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_float8_callback(void *, double);
+CBOR_EXPORT void cbor_null_float8_callback(void*, double);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_null_callback(void *);
+CBOR_EXPORT void cbor_null_null_callback(void*);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_undefined_callback(void *);
+CBOR_EXPORT void cbor_null_undefined_callback(void*);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_boolean_callback(void *, bool);
+CBOR_EXPORT void cbor_null_boolean_callback(void*, bool);
/** Dummy callback implementation - does nothing */
-CBOR_EXPORT void cbor_null_indef_break_callback(void *);
+CBOR_EXPORT void cbor_null_indef_break_callback(void*);
/** Dummy callback bundle - does nothing */
CBOR_EXPORT extern const struct cbor_callbacks cbor_empty_callbacks;
diff --git a/src/cbor/common.c b/src/cbor/common.c
index efbd37ed79d3..704dd0c3205d 100644
--- a/src/cbor/common.c
+++ b/src/cbor/common.c
@@ -19,69 +19,69 @@
bool _cbor_enable_assert = true;
#endif
-bool cbor_isa_uint(const cbor_item_t *item) {
+bool cbor_isa_uint(const cbor_item_t* item) {
return item->type == CBOR_TYPE_UINT;
}
-bool cbor_isa_negint(const cbor_item_t *item) {
+bool cbor_isa_negint(const cbor_item_t* item) {
return item->type == CBOR_TYPE_NEGINT;
}
-bool cbor_isa_bytestring(const cbor_item_t *item) {
+bool cbor_isa_bytestring(const cbor_item_t* item) {
return item->type == CBOR_TYPE_BYTESTRING;
}
-bool cbor_isa_string(const cbor_item_t *item) {
+bool cbor_isa_string(const cbor_item_t* item) {
return item->type == CBOR_TYPE_STRING;
}
-bool cbor_isa_array(const cbor_item_t *item) {
+bool cbor_isa_array(const cbor_item_t* item) {
return item->type == CBOR_TYPE_ARRAY;
}
-bool cbor_isa_map(const cbor_item_t *item) {
+bool cbor_isa_map(const cbor_item_t* item) {
return item->type == CBOR_TYPE_MAP;
}
-bool cbor_isa_tag(const cbor_item_t *item) {
+bool cbor_isa_tag(const cbor_item_t* item) {
return item->type == CBOR_TYPE_TAG;
}
-bool cbor_isa_float_ctrl(const cbor_item_t *item) {
+bool cbor_isa_float_ctrl(const cbor_item_t* item) {
return item->type == CBOR_TYPE_FLOAT_CTRL;
}
-cbor_type cbor_typeof(const cbor_item_t *item) { return item->type; }
+cbor_type cbor_typeof(const cbor_item_t* item) { return item->type; }
-bool cbor_is_int(const cbor_item_t *item) {
+bool cbor_is_int(const cbor_item_t* item) {
return cbor_isa_uint(item) || cbor_isa_negint(item);
}
-bool cbor_is_bool(const cbor_item_t *item) {
+bool cbor_is_bool(const cbor_item_t* item) {
return cbor_isa_float_ctrl(item) &&
(cbor_ctrl_value(item) == CBOR_CTRL_FALSE ||
cbor_ctrl_value(item) == CBOR_CTRL_TRUE);
}
-bool cbor_is_null(const cbor_item_t *item) {
+bool cbor_is_null(const cbor_item_t* item) {
return cbor_isa_float_ctrl(item) && cbor_ctrl_value(item) == CBOR_CTRL_NULL;
}
-bool cbor_is_undef(const cbor_item_t *item) {
+bool cbor_is_undef(const cbor_item_t* item) {
return cbor_isa_float_ctrl(item) && cbor_ctrl_value(item) == CBOR_CTRL_UNDEF;
}
-bool cbor_is_float(const cbor_item_t *item) {
+bool cbor_is_float(const cbor_item_t* item) {
return cbor_isa_float_ctrl(item) && !cbor_float_ctrl_is_ctrl(item);
}
-cbor_item_t *cbor_incref(cbor_item_t *item) {
+cbor_item_t* cbor_incref(cbor_item_t* item) {
item->refcount++;
return item;
}
-void cbor_decref(cbor_item_t **item_ref) {
- cbor_item_t *item = *item_ref;
+void cbor_decref(cbor_item_t** item_ref) {
+ cbor_item_t* item = *item_ref;
CBOR_ASSERT(item->refcount > 0);
if (--item->refcount == 0) {
switch (item->type) {
@@ -95,11 +95,10 @@ void cbor_decref(cbor_item_t **item_ref) {
_cbor_free(item->data);
} else {
/* We need to decref all chunks */
- cbor_item_t **handle = cbor_bytestring_chunks_handle(item);
+ cbor_item_t** handle = cbor_bytestring_chunks_handle(item);
for (size_t i = 0; i < cbor_bytestring_chunk_count(item); i++)
cbor_decref(&handle[i]);
- _cbor_free(
- ((struct cbor_indefinite_string_data *)item->data)->chunks);
+ _cbor_free(((struct cbor_indefinite_string_data*)item->data)->chunks);
_cbor_free(item->data);
}
break;
@@ -109,18 +108,17 @@ void cbor_decref(cbor_item_t **item_ref) {
_cbor_free(item->data);
} else {
/* We need to decref all chunks */
- cbor_item_t **handle = cbor_string_chunks_handle(item);
+ cbor_item_t** handle = cbor_string_chunks_handle(item);
for (size_t i = 0; i < cbor_string_chunk_count(item); i++)
cbor_decref(&handle[i]);
- _cbor_free(
- ((struct cbor_indefinite_string_data *)item->data)->chunks);
+ _cbor_free(((struct cbor_indefinite_string_data*)item->data)->chunks);
_cbor_free(item->data);
}
break;
}
case CBOR_TYPE_ARRAY: {
/* Get all items and decref them */
- cbor_item_t **handle = cbor_array_handle(item);
+ cbor_item_t** handle = cbor_array_handle(item);
size_t size = cbor_array_size(item);
for (size_t i = 0; i < size; i++)
if (handle[i] != NULL) cbor_decref(&handle[i]);
@@ -128,7 +126,7 @@ void cbor_decref(cbor_item_t **item_ref) {
break;
}
case CBOR_TYPE_MAP: {
- struct cbor_pair *handle = cbor_map_handle(item);
+ struct cbor_pair* handle = cbor_map_handle(item);
for (size_t i = 0; i < item->metadata.map_metadata.end_ptr;
i++, handle++) {
cbor_decref(&handle->key);
@@ -153,11 +151,11 @@ void cbor_decref(cbor_item_t **item_ref) {
}
}
-void cbor_intermediate_decref(cbor_item_t *item) { cbor_decref(&item); }
+void cbor_intermediate_decref(cbor_item_t* item) { cbor_decref(&item); }
-size_t cbor_refcount(const cbor_item_t *item) { return item->refcount; }
+size_t cbor_refcount(const cbor_item_t* item) { return item->refcount; }
-cbor_item_t *cbor_move(cbor_item_t *item) {
+cbor_item_t* cbor_move(cbor_item_t* item) {
item->refcount--;
return item;
}
diff --git a/src/cbor/common.h b/src/cbor/common.h
index 1d0b426cff4c..89968db95442 100644
--- a/src/cbor/common.h
+++ b/src/cbor/common.h
@@ -81,21 +81,27 @@ extern bool _cbor_enable_assert;
#define _CBOR_TO_STR(x) _CBOR_TO_STR_(x) /* enables proper double expansion */
#ifdef __GNUC__
-#define _CBOR_UNUSED(x) __attribute__((__unused__)) x
+#define _CBOR_UNUSED __attribute__((__unused__))
// TODO(https://github.com/PJK/libcbor/issues/247): Prefer [[nodiscard]] if
// available
#define _CBOR_NODISCARD __attribute__((warn_unused_result))
#elif defined(_MSC_VER)
-#define _CBOR_UNUSED(x) __pragma(warning(suppress : 4100 4101)) x
+#define _CBOR_UNUSED __pragma(warning(suppress : 4100 4101))
#define _CBOR_NODISCARD
#else
-#define _CBOR_UNUSED(x) x
+#define _CBOR_UNUSED
#define _CBOR_NODISCARD
#endif
-typedef void *(*_cbor_malloc_t)(size_t);
-typedef void *(*_cbor_realloc_t)(void *, size_t);
-typedef void (*_cbor_free_t)(void *);
+#ifdef CBOR_HAS_BUILTIN_UNREACHABLE
+#define _CBOR_UNREACHABLE __builtin_unreachable()
+#else
+#define _CBOR_UNREACHABLE
+#endif
+
+typedef void* (*_cbor_malloc_t)(size_t);
+typedef void* (*_cbor_realloc_t)(void*, size_t);
+typedef void (*_cbor_free_t)(void*);
CBOR_EXPORT extern _cbor_malloc_t _cbor_malloc;
CBOR_EXPORT extern _cbor_realloc_t _cbor_realloc;
@@ -155,7 +161,7 @@ CBOR_EXPORT void cbor_set_allocs(_cbor_malloc_t custom_malloc,
*/
_CBOR_NODISCARD
CBOR_EXPORT cbor_type cbor_typeof(
- const cbor_item_t *item); /* Will be inlined iff link-time opt is enabled */
+ const cbor_item_t* item); /* Will be inlined iff link-time opt is enabled */
/* Standard CBOR Major item types */
@@ -164,56 +170,56 @@ CBOR_EXPORT cbor_type cbor_typeof(
* @return Is the item an #CBOR_TYPE_UINT?
*/
_CBOR_NODISCARD
-CBOR_EXPORT bool cbor_isa_uint(const cbor_item_t *item);
+CBOR_EXPORT bool cbor_isa_uint(const cbor_item_t* item);
/** Does the item have the appropriate major type?
* @param item the item
* @return Is the item a #CBOR_TYPE_NEGINT?
*/
_CBOR_NODISCARD
-CBOR_EXPORT bool cbor_isa_negint(const cbor_item_t *item);
+CBOR_EXPORT bool cbor_isa_negint(const cbor_item_t* item);
/** Does the item have the appropriate major type?
* @param item the item
* @return Is the item a #CBOR_TYPE_BYTESTRING?
*/
_CBOR_NODISCARD
-CBOR_EXPORT bool cbor_isa_bytestring(const cbor_item_t *item);
+CBOR_EXPORT bool cbor_isa_bytestring(const cbor_item_t* item);
/** Does the item have the appropriate major type?
* @param item the item
* @return Is the item a #CBOR_TYPE_STRING?
*/
_CBOR_NODISCARD
-CBOR_EXPORT bool cbor_isa_string(const cbor_item_t *item);
+CBOR_EXPORT bool cbor_isa_string(const cbor_item_t* item);
/** Does the item have the appropriate major type?
* @param item the item
* @return Is the item an #CBOR_TYPE_ARRAY?
*/
_CBOR_NODISCARD
-CBOR_EXPORT bool cbor_isa_array(const cbor_item_t *item);
+CBOR_EXPORT bool cbor_isa_array(const cbor_item_t* item);
/** Does the item have the appropriate major type?
* @param item the item
* @return Is the item a #CBOR_TYPE_MAP?
*/
_CBOR_NODISCARD
-CBOR_EXPORT bool cbor_isa_map(const cbor_item_t *item);
+CBOR_EXPORT bool cbor_isa_map(const cbor_item_t* item);
/** Does the item have the appropriate major type?
* @param item the item
* @return Is the item a #CBOR_TYPE_TAG?
*/
_CBOR_NODISCARD
-CBOR_EXPORT bool cbor_isa_tag(const cbor_item_t *item);
+CBOR_EXPORT bool cbor_isa_tag(const cbor_item_t* item);
/** Does the item have the appropriate major type?
* @param item the item
* @return Is the item a #CBOR_TYPE_FLOAT_CTRL?
*/
_CBOR_NODISCARD
-CBOR_EXPORT bool cbor_isa_float_ctrl(const cbor_item_t *item);
+CBOR_EXPORT bool cbor_isa_float_ctrl(const cbor_item_t* item);
/* Practical types with respect to their semantics (but not tag values) */
@@ -222,21 +228,21 @@ CBOR_EXPORT bool cbor_isa_float_ctrl(const cbor_item_t *item);
* @return Is the item an integer, either positive or negative?
*/
_CBOR_NODISCARD
-CBOR_EXPORT bool cbor_is_int(const cbor_item_t *item);
+CBOR_EXPORT bool cbor_is_int(const cbor_item_t* item);
/** Is the item an a floating point number?
* @param item the item
* @return Is the item a floating point number?
*/
_CBOR_NODISCARD
-CBOR_EXPORT bool cbor_is_float(const cbor_item_t *item);
+CBOR_EXPORT bool cbor_is_float(const cbor_item_t* item);
/** Is the item an a boolean?
* @param item the item
* @return Is the item a boolean?
*/
_CBOR_NODISCARD
-CBOR_EXPORT bool cbor_is_bool(const cbor_item_t *item);
+CBOR_EXPORT bool cbor_is_bool(const cbor_item_t* item);
/** Does this item represent `null`
*
@@ -249,7 +255,7 @@ CBOR_EXPORT bool cbor_is_bool(const cbor_item_t *item);
* @return Is the item (CBOR logical) null?
*/
_CBOR_NODISCARD
-CBOR_EXPORT bool cbor_is_null(const cbor_item_t *item);
+CBOR_EXPORT bool cbor_is_null(const cbor_item_t* item);
/** Does this item represent `undefined`
*
@@ -262,7 +268,7 @@ CBOR_EXPORT bool cbor_is_null(const cbor_item_t *item);
* @return Is the item (CBOR logical) undefined?
*/
_CBOR_NODISCARD
-CBOR_EXPORT bool cbor_is_undef(const cbor_item_t *item);
+CBOR_EXPORT bool cbor_is_undef(const cbor_item_t* item);
/*
* ============================================================================
@@ -280,7 +286,7 @@ CBOR_EXPORT bool cbor_is_undef(const cbor_item_t *item);
* @param item Reference to an item
* @return The input \p item
*/
-CBOR_EXPORT cbor_item_t *cbor_incref(cbor_item_t *item);
+CBOR_EXPORT cbor_item_t* cbor_incref(cbor_item_t* item);
/** Decreases the item's reference count by one, deallocating the item if needed
*
@@ -289,7 +295,7 @@ CBOR_EXPORT cbor_item_t *cbor_incref(cbor_item_t *item);
*
* @param item Reference to an item. Will be set to `NULL` if deallocated
*/
-CBOR_EXPORT void cbor_decref(cbor_item_t **item);
+CBOR_EXPORT void cbor_decref(cbor_item_t** item);
/** Decreases the item's reference count by one, deallocating the item if needed
*
@@ -298,7 +304,7 @@ CBOR_EXPORT void cbor_decref(cbor_item_t **item);
*
* @param item Reference to an item
*/
-CBOR_EXPORT void cbor_intermediate_decref(cbor_item_t *item);
+CBOR_EXPORT void cbor_intermediate_decref(cbor_item_t* item);
/** Get the item's reference count
*
@@ -312,7 +318,7 @@ CBOR_EXPORT void cbor_intermediate_decref(cbor_item_t *item);
* @return the reference count
*/
_CBOR_NODISCARD
-CBOR_EXPORT size_t cbor_refcount(const cbor_item_t *item);
+CBOR_EXPORT size_t cbor_refcount(const cbor_item_t* item);
/** Provides CPP-like move construct
*
@@ -330,7 +336,7 @@ CBOR_EXPORT size_t cbor_refcount(const cbor_item_t *item);
* @return the item with reference count decreased by one
*/
_CBOR_NODISCARD
-CBOR_EXPORT cbor_item_t *cbor_move(cbor_item_t *item);
+CBOR_EXPORT cbor_item_t* cbor_move(cbor_item_t* item);
#ifdef __cplusplus
}
diff --git a/src/cbor/encoding.c b/src/cbor/encoding.c
index 9d931d17570f..76be4de9da3d 100644
--- a/src/cbor/encoding.c
+++ b/src/cbor/encoding.c
@@ -6,64 +6,67 @@
*/
#include "encoding.h"
+
+#include <math.h>
+
#include "internal/encoders.h"
-size_t cbor_encode_uint8(uint8_t value, unsigned char *buffer,
+size_t cbor_encode_uint8(uint8_t value, unsigned char* buffer,
size_t buffer_size) {
return _cbor_encode_uint8(value, buffer, buffer_size, 0x00);
}
-size_t cbor_encode_uint16(uint16_t value, unsigned char *buffer,
+size_t cbor_encode_uint16(uint16_t value, unsigned char* buffer,
size_t buffer_size) {
return _cbor_encode_uint16(value, buffer, buffer_size, 0x00);
}
-size_t cbor_encode_uint32(uint32_t value, unsigned char *buffer,
+size_t cbor_encode_uint32(uint32_t value, unsigned char* buffer,
size_t buffer_size) {
return _cbor_encode_uint32(value, buffer, buffer_size, 0x00);
}
-size_t cbor_encode_uint64(uint64_t value, unsigned char *buffer,
+size_t cbor_encode_uint64(uint64_t value, unsigned char* buffer,
size_t buffer_size) {
return _cbor_encode_uint64(value, buffer, buffer_size, 0x00);
}
-size_t cbor_encode_uint(uint64_t value, unsigned char *buffer,
+size_t cbor_encode_uint(uint64_t value, unsigned char* buffer,
size_t buffer_size) {
return _cbor_encode_uint(value, buffer, buffer_size, 0x00);
}
-size_t cbor_encode_negint8(uint8_t value, unsigned char *buffer,
+size_t cbor_encode_negint8(uint8_t value, unsigned char* buffer,
size_t buffer_size) {
return _cbor_encode_uint8(value, buffer, buffer_size, 0x20);
}
-size_t cbor_encode_negint16(uint16_t value, unsigned char *buffer,
+size_t cbor_encode_negint16(uint16_t value, unsigned char* buffer,
size_t buffer_size) {
return _cbor_encode_uint16(value, buffer, buffer_size, 0x20);
}
-size_t cbor_encode_negint32(uint32_t value, unsigned char *buffer,
+size_t cbor_encode_negint32(uint32_t value, unsigned char* buffer,
size_t buffer_size) {
return _cbor_encode_uint32(value, buffer, buffer_size, 0x20);
}
-size_t cbor_encode_negint64(uint64_t value, unsigned char *buffer,
+size_t cbor_encode_negint64(uint64_t value, unsigned char* buffer,
size_t buffer_size) {
return _cbor_encode_uint64(value, buffer, buffer_size, 0x20);
}
-size_t cbor_encode_negint(uint64_t value, unsigned char *buffer,
+size_t cbor_encode_negint(uint64_t value, unsigned char* buffer,
size_t buffer_size) {
return _cbor_encode_uint(value, buffer, buffer_size, 0x20);
}
-size_t cbor_encode_bytestring_start(size_t length, unsigned char *buffer,
+size_t cbor_encode_bytestring_start(size_t length, unsigned char* buffer,
size_t buffer_size) {
return _cbor_encode_uint((size_t)length, buffer, buffer_size, 0x40);
}
-size_t _cbor_encode_byte(uint8_t value, unsigned char *buffer,
+size_t _cbor_encode_byte(uint8_t value, unsigned char* buffer,
size_t buffer_size) {
if (buffer_size >= 1) {
buffer[0] = value;
@@ -72,60 +75,61 @@ size_t _cbor_encode_byte(uint8_t value, unsigned char *buffer,
return 0;
}
-size_t cbor_encode_indef_bytestring_start(unsigned char *buffer,
+size_t cbor_encode_indef_bytestring_start(unsigned char* buffer,
size_t buffer_size) {
return _cbor_encode_byte(0x5F, buffer, buffer_size);
}
-size_t cbor_encode_string_start(size_t length, unsigned char *buffer,
+size_t cbor_encode_string_start(size_t length, unsigned char* buffer,
size_t buffer_size) {
return _cbor_encode_uint((size_t)length, buffer, buffer_size, 0x60);
}
-size_t cbor_encode_indef_string_start(unsigned char *buffer,
+size_t cbor_encode_indef_string_start(unsigned char* buffer,
size_t buffer_size) {
return _cbor_encode_byte(0x7F, buffer, buffer_size);
}
-size_t cbor_encode_array_start(size_t length, unsigned char *buffer,
+size_t cbor_encode_array_start(size_t length, unsigned char* buffer,
size_t buffer_size) {
return _cbor_encode_uint((size_t)length, buffer, buffer_size, 0x80);
}
-size_t cbor_encode_indef_array_start(unsigned char *buffer,
+size_t cbor_encode_indef_array_start(unsigned char* buffer,
size_t buffer_size) {
return _cbor_encode_byte(0x9F, buffer, buffer_size);
}
-size_t cbor_encode_map_start(size_t length, unsigned char *buffer,
+size_t cbor_encode_map_start(size_t length, unsigned char* buffer,
size_t buffer_size) {
return _cbor_encode_uint((size_t)length, buffer, buffer_size, 0xA0);
}
-size_t cbor_encode_indef_map_start(unsigned char *buffer, size_t buffer_size) {
+size_t cbor_encode_indef_map_start(unsigned char* buffer, size_t buffer_size) {
return _cbor_encode_byte(0xBF, buffer, buffer_size);
}
-size_t cbor_encode_tag(uint64_t value, unsigned char *buffer,
+size_t cbor_encode_tag(uint64_t value, unsigned char* buffer,
size_t buffer_size) {
return _cbor_encode_uint(value, buffer, buffer_size, 0xC0);
}
-size_t cbor_encode_bool(bool value, unsigned char *buffer, size_t buffer_size) {
+size_t cbor_encode_bool(bool value, unsigned char* buffer, size_t buffer_size) {
return value ? _cbor_encode_byte(0xF5, buffer, buffer_size)
: _cbor_encode_byte(0xF4, buffer, buffer_size);
}
-size_t cbor_encode_null(unsigned char *buffer, size_t buffer_size) {
+size_t cbor_encode_null(unsigned char* buffer, size_t buffer_size) {
return _cbor_encode_byte(0xF6, buffer, buffer_size);
}
-size_t cbor_encode_undef(unsigned char *buffer, size_t buffer_size) {
+size_t cbor_encode_undef(unsigned char* buffer, size_t buffer_size) {
return _cbor_encode_byte(0xF7, buffer, buffer_size);
}
-size_t cbor_encode_half(float value, unsigned char *buffer,
+size_t cbor_encode_half(float value, unsigned char* buffer,
size_t buffer_size) {
+ // TODO: Broken on systems that do not use IEEE 754
/* Assuming value is normalized */
uint32_t val = ((union _cbor_float_helper){.as_float = value}).as_uint;
uint16_t res;
@@ -134,11 +138,8 @@ size_t cbor_encode_half(float value, unsigned char *buffer,
uint32_t mant =
val & 0x7FFFFFu; /* 0b0000_0000_0111_1111_1111_1111_1111_1111 */
if (exp == 0xFF) { /* Infinity or NaNs */
- if (value != value) {
- // We discard information bits in half-float NaNs. This is
- // not required for the core CBOR protocol (it is only a suggestion in
- // Section 3.9).
- // See https://github.com/PJK/libcbor/issues/215
+ if (isnan(value)) {
+ // Note: Values of signaling NaNs are discarded. See `cbor_encode_single`.
res = (uint16_t)0x007e00;
} else {
// If the mantissa is non-zero, we have a NaN, but those are handled
@@ -176,25 +177,38 @@ size_t cbor_encode_half(float value, unsigned char *buffer,
return _cbor_encode_uint16(res, buffer, buffer_size, 0xE0);
}
-size_t cbor_encode_single(float value, unsigned char *buffer,
+size_t cbor_encode_single(float value, unsigned char* buffer,
size_t buffer_size) {
+ // Note: Values of signaling NaNs are discarded. There is no standard
+ // way to extract it without assumptions about the internal float
+ // representation.
+ if (isnan(value)) {
+ return _cbor_encode_uint32(0x7FC0 << 16, buffer, buffer_size, 0xE0);
+ }
+ // TODO: Broken on systems that do not use IEEE 754
return _cbor_encode_uint32(
((union _cbor_float_helper){.as_float = value}).as_uint, buffer,
buffer_size, 0xE0);
}
-size_t cbor_encode_double(double value, unsigned char *buffer,
+size_t cbor_encode_double(double value, unsigned char* buffer,
size_t buffer_size) {
+ // Note: Values of signaling NaNs are discarded. See `cbor_encode_single`.
+ if (isnan(value)) {
+ return _cbor_encode_uint64((uint64_t)0x7FF8 << 48, buffer, buffer_size,
+ 0xE0);
+ }
+ // TODO: Broken on systems that do not use IEEE 754
return _cbor_encode_uint64(
((union _cbor_double_helper){.as_double = value}).as_uint, buffer,
buffer_size, 0xE0);
}
-size_t cbor_encode_break(unsigned char *buffer, size_t buffer_size) {
+size_t cbor_encode_break(unsigned char* buffer, size_t buffer_size) {
return _cbor_encode_byte(0xFF, buffer, buffer_size);
}
-size_t cbor_encode_ctrl(uint8_t value, unsigned char *buffer,
+size_t cbor_encode_ctrl(uint8_t value, unsigned char* buffer,
size_t buffer_size) {
return _cbor_encode_uint8(value, buffer, buffer_size, 0xE0);
}
diff --git a/src/cbor/encoding.h b/src/cbor/encoding.h
index bcc04f8a98e5..c05bbc545737 100644
--- a/src/cbor/encoding.h
+++ b/src/cbor/encoding.h
@@ -27,76 +27,72 @@ extern "C" {
* case it is not modified).
*/
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_uint8(uint8_t, unsigned char *,
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_uint8(uint8_t, unsigned char*,
size_t);
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_uint16(uint16_t, unsigned char *,
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_uint16(uint16_t, unsigned char*,
size_t);
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_uint32(uint32_t, unsigned char *,
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_uint32(uint32_t, unsigned char*,
size_t);
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_uint64(uint64_t, unsigned char *,
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_uint64(uint64_t, unsigned char*,
size_t);
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_uint(uint64_t, unsigned char *,
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_uint(uint64_t, unsigned char*,
size_t);
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_negint8(uint8_t, unsigned char *,
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_negint8(uint8_t, unsigned char*,
size_t);
_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_negint16(uint16_t,
- unsigned char *,
- size_t);
+ unsigned char*, size_t);
_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_negint32(uint32_t,
- unsigned char *,
- size_t);
+ unsigned char*, size_t);
_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_negint64(uint64_t,
- unsigned char *,
- size_t);
+ unsigned char*, size_t);
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_negint(uint64_t, unsigned char *,
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_negint(uint64_t, unsigned char*,
size_t);
_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_bytestring_start(size_t,
- unsigned char *,
+ unsigned char*,
size_t);
_CBOR_NODISCARD CBOR_EXPORT size_t
-cbor_encode_indef_bytestring_start(unsigned char *, size_t);
+cbor_encode_indef_bytestring_start(unsigned char*, size_t);
_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_string_start(size_t,
- unsigned char *,
+ unsigned char*,
size_t);
_CBOR_NODISCARD CBOR_EXPORT size_t
-cbor_encode_indef_string_start(unsigned char *, size_t);
+cbor_encode_indef_string_start(unsigned char*, size_t);
_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_array_start(size_t,
- unsigned char *,
+ unsigned char*,
size_t);
-_CBOR_NODISCARD CBOR_EXPORT size_t
-cbor_encode_indef_array_start(unsigned char *, size_t);
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_indef_array_start(unsigned char*,
+ size_t);
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_map_start(size_t,
- unsigned char *,
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_map_start(size_t, unsigned char*,
size_t);
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_indef_map_start(unsigned char *,
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_indef_map_start(unsigned char*,
size_t);
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_tag(uint64_t, unsigned char *,
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_tag(uint64_t, unsigned char*,
size_t);
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_bool(bool, unsigned char *,
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_bool(bool, unsigned char*,
size_t);
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_null(unsigned char *, size_t);
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_null(unsigned char*, size_t);
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_undef(unsigned char *, size_t);
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_undef(unsigned char*, size_t);
/** Encodes a half-precision float
*
@@ -118,19 +114,28 @@ _CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_undef(unsigned char *, size_t);
* lost.
* - In all other cases, the sign bit, the exponent, and 10 most significant
* bits of the significand are kept
+ *
+ * Note: Signaling NaNs are encoded as a standard, "quiet" NaN.
*/
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_half(float, unsigned char *,
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_half(float, unsigned char*,
size_t);
-
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_single(float, unsigned char *,
+/** Encodes a single precision float
+ *
+ * Note: Signaling NaNs are encoded as a standard, "quiet" NaN.
+ */
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_single(float, unsigned char*,
size_t);
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_double(double, unsigned char *,
+/** Encodes a double precision float
+ *
+ * Note: Signaling NaNs are encoded as a standard, "quiet" NaN.
+ */
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_double(double, unsigned char*,
size_t);
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_break(unsigned char *, size_t);
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_break(unsigned char*, size_t);
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_ctrl(uint8_t, unsigned char *,
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_encode_ctrl(uint8_t, unsigned char*,
size_t);
#ifdef __cplusplus
diff --git a/src/cbor/floats_ctrls.c b/src/cbor/floats_ctrls.c
index 57bf477d4d3d..705e78cb20ca 100644
--- a/src/cbor/floats_ctrls.c
+++ b/src/cbor/floats_ctrls.c
@@ -9,43 +9,42 @@
#include <math.h>
#include "assert.h"
-cbor_float_width cbor_float_get_width(const cbor_item_t *item) {
+cbor_float_width cbor_float_get_width(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_float_ctrl(item));
return item->metadata.float_ctrl_metadata.width;
}
-uint8_t cbor_ctrl_value(const cbor_item_t *item) {
+uint8_t cbor_ctrl_value(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_float_ctrl(item));
CBOR_ASSERT(cbor_float_get_width(item) == CBOR_FLOAT_0);
return item->metadata.float_ctrl_metadata.ctrl;
}
-bool cbor_float_ctrl_is_ctrl(const cbor_item_t *item) {
+bool cbor_float_ctrl_is_ctrl(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_float_ctrl(item));
return cbor_float_get_width(item) == CBOR_FLOAT_0;
}
-float cbor_float_get_float2(const cbor_item_t *item) {
+float cbor_float_get_float2(const cbor_item_t* item) {
CBOR_ASSERT(cbor_is_float(item));
CBOR_ASSERT(cbor_float_get_width(item) == CBOR_FLOAT_16);
- return *(float *)item->data;
+ return *(float*)item->data;
}
-float cbor_float_get_float4(const cbor_item_t *item) {
+float cbor_float_get_float4(const cbor_item_t* item) {
CBOR_ASSERT(cbor_is_float(item));
CBOR_ASSERT(cbor_float_get_width(item) == CBOR_FLOAT_32);
- return *(float *)item->data;
+ return *(float*)item->data;
}
-double cbor_float_get_float8(const cbor_item_t *item) {
+double cbor_float_get_float8(const cbor_item_t* item) {
CBOR_ASSERT(cbor_is_float(item));
CBOR_ASSERT(cbor_float_get_width(item) == CBOR_FLOAT_64);
- return *(double *)item->data;
+ return *(double*)item->data;
}
-double cbor_float_get_float(const cbor_item_t *item) {
+double cbor_float_get_float(const cbor_item_t* item) {
CBOR_ASSERT(cbor_is_float(item));
- // cppcheck-suppress missingReturn
switch (cbor_float_get_width(item)) {
case CBOR_FLOAT_0:
return NAN;
@@ -55,46 +54,49 @@ double cbor_float_get_float(const cbor_item_t *item) {
return cbor_float_get_float4(item);
case CBOR_FLOAT_64:
return cbor_float_get_float8(item);
+ default:
+ _CBOR_UNREACHABLE;
+ return 0;
}
}
-bool cbor_get_bool(const cbor_item_t *item) {
+bool cbor_get_bool(const cbor_item_t* item) {
CBOR_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) {
+void cbor_set_float2(cbor_item_t* item, float value) {
CBOR_ASSERT(cbor_is_float(item));
CBOR_ASSERT(cbor_float_get_width(item) == CBOR_FLOAT_16);
- *((float *)item->data) = value;
+ *((float*)item->data) = value;
}
-void cbor_set_float4(cbor_item_t *item, float value) {
+void cbor_set_float4(cbor_item_t* item, float value) {
CBOR_ASSERT(cbor_is_float(item));
CBOR_ASSERT(cbor_float_get_width(item) == CBOR_FLOAT_32);
- *((float *)item->data) = value;
+ *((float*)item->data) = value;
}
-void cbor_set_float8(cbor_item_t *item, double value) {
+void cbor_set_float8(cbor_item_t* item, double value) {
CBOR_ASSERT(cbor_is_float(item));
CBOR_ASSERT(cbor_float_get_width(item) == CBOR_FLOAT_64);
- *((double *)item->data) = value;
+ *((double*)item->data) = value;
}
-void cbor_set_ctrl(cbor_item_t *item, uint8_t value) {
+void cbor_set_ctrl(cbor_item_t* item, uint8_t value) {
CBOR_ASSERT(cbor_isa_float_ctrl(item));
CBOR_ASSERT(cbor_float_get_width(item) == CBOR_FLOAT_0);
item->metadata.float_ctrl_metadata.ctrl = value;
}
-void cbor_set_bool(cbor_item_t *item, bool value) {
+void cbor_set_bool(cbor_item_t* item, bool value) {
CBOR_ASSERT(cbor_is_bool(item));
item->metadata.float_ctrl_metadata.ctrl =
value ? CBOR_CTRL_TRUE : CBOR_CTRL_FALSE;
}
-cbor_item_t *cbor_new_ctrl(void) {
- cbor_item_t *item = _cbor_malloc(sizeof(cbor_item_t));
+cbor_item_t* cbor_new_ctrl(void) {
+ cbor_item_t* item = _cbor_malloc(sizeof(cbor_item_t));
_CBOR_NOTNULL(item);
*item = (cbor_item_t){
@@ -106,83 +108,83 @@ cbor_item_t *cbor_new_ctrl(void) {
return item;
}
-cbor_item_t *cbor_new_float2(void) {
- cbor_item_t *item = _cbor_malloc(sizeof(cbor_item_t) + 4);
+cbor_item_t* cbor_new_float2(void) {
+ cbor_item_t* item = _cbor_malloc(sizeof(cbor_item_t) + 4);
_CBOR_NOTNULL(item);
*item = (cbor_item_t){
.type = CBOR_TYPE_FLOAT_CTRL,
- .data = (unsigned char *)item + sizeof(cbor_item_t),
+ .data = (unsigned char*)item + sizeof(cbor_item_t),
.refcount = 1,
.metadata = {.float_ctrl_metadata = {.width = CBOR_FLOAT_16}}};
return item;
}
-cbor_item_t *cbor_new_float4(void) {
- cbor_item_t *item = _cbor_malloc(sizeof(cbor_item_t) + 4);
+cbor_item_t* cbor_new_float4(void) {
+ cbor_item_t* item = _cbor_malloc(sizeof(cbor_item_t) + 4);
_CBOR_NOTNULL(item);
*item = (cbor_item_t){
.type = CBOR_TYPE_FLOAT_CTRL,
- .data = (unsigned char *)item + sizeof(cbor_item_t),
+ .data = (unsigned char*)item + sizeof(cbor_item_t),
.refcount = 1,
.metadata = {.float_ctrl_metadata = {.width = CBOR_FLOAT_32}}};
return item;
}
-cbor_item_t *cbor_new_float8(void) {
- cbor_item_t *item = _cbor_malloc(sizeof(cbor_item_t) + 8);
+cbor_item_t* cbor_new_float8(void) {
+ cbor_item_t* item = _cbor_malloc(sizeof(cbor_item_t) + 8);
_CBOR_NOTNULL(item);
*item = (cbor_item_t){
.type = CBOR_TYPE_FLOAT_CTRL,
- .data = (unsigned char *)item + sizeof(cbor_item_t),
+ .data = (unsigned char*)item + sizeof(cbor_item_t),
.refcount = 1,
.metadata = {.float_ctrl_metadata = {.width = CBOR_FLOAT_64}}};
return item;
}
-cbor_item_t *cbor_new_null(void) {
- cbor_item_t *item = cbor_new_ctrl();
+cbor_item_t* cbor_new_null(void) {
+ cbor_item_t* item = cbor_new_ctrl();
_CBOR_NOTNULL(item);
cbor_set_ctrl(item, CBOR_CTRL_NULL);
return item;
}
-cbor_item_t *cbor_new_undef(void) {
- cbor_item_t *item = cbor_new_ctrl();
+cbor_item_t* cbor_new_undef(void) {
+ cbor_item_t* item = cbor_new_ctrl();
_CBOR_NOTNULL(item);
cbor_set_ctrl(item, CBOR_CTRL_UNDEF);
return item;
}
-cbor_item_t *cbor_build_bool(bool value) {
+cbor_item_t* cbor_build_bool(bool value) {
return cbor_build_ctrl(value ? CBOR_CTRL_TRUE : CBOR_CTRL_FALSE);
}
-cbor_item_t *cbor_build_float2(float value) {
- cbor_item_t *item = cbor_new_float2();
+cbor_item_t* cbor_build_float2(float value) {
+ cbor_item_t* item = cbor_new_float2();
_CBOR_NOTNULL(item);
cbor_set_float2(item, value);
return item;
}
-cbor_item_t *cbor_build_float4(float value) {
- cbor_item_t *item = cbor_new_float4();
+cbor_item_t* cbor_build_float4(float value) {
+ cbor_item_t* item = cbor_new_float4();
_CBOR_NOTNULL(item);
cbor_set_float4(item, value);
return item;
}
-cbor_item_t *cbor_build_float8(double value) {
- cbor_item_t *item = cbor_new_float8();
+cbor_item_t* cbor_build_float8(double value) {
+ cbor_item_t* item = cbor_new_float8();
_CBOR_NOTNULL(item);
cbor_set_float8(item, value);
return item;
}
-cbor_item_t *cbor_build_ctrl(uint8_t value) {
- cbor_item_t *item = cbor_new_ctrl();
+cbor_item_t* cbor_build_ctrl(uint8_t value) {
+ cbor_item_t* item = cbor_new_ctrl();
_CBOR_NOTNULL(item);
cbor_set_ctrl(item, value);
return item;
diff --git a/src/cbor/floats_ctrls.h b/src/cbor/floats_ctrls.h
index 335eab8328be..6a7925346951 100644
--- a/src/cbor/floats_ctrls.h
+++ b/src/cbor/floats_ctrls.h
@@ -27,7 +27,7 @@ extern "C" {
* @return Is this a ctrl value?
*/
_CBOR_NODISCARD CBOR_EXPORT bool cbor_float_ctrl_is_ctrl(
- const cbor_item_t *item);
+ const cbor_item_t* item);
/** Get the float width
*
@@ -35,7 +35,7 @@ _CBOR_NODISCARD CBOR_EXPORT bool cbor_float_ctrl_is_ctrl(
* @return The width.
*/
_CBOR_NODISCARD CBOR_EXPORT cbor_float_width
-cbor_float_get_width(const cbor_item_t *item);
+cbor_float_get_width(const cbor_item_t* item);
/** Get a half precision float
*
@@ -45,7 +45,7 @@ cbor_float_get_width(const cbor_item_t *item);
* @return half precision value
*/
_CBOR_NODISCARD CBOR_EXPORT float cbor_float_get_float2(
- const cbor_item_t *item);
+ const cbor_item_t* item);
/** Get a single precision float
*
@@ -55,7 +55,7 @@ _CBOR_NODISCARD CBOR_EXPORT float cbor_float_get_float2(
* @return single precision value
*/
_CBOR_NODISCARD CBOR_EXPORT float cbor_float_get_float4(
- const cbor_item_t *item);
+ const cbor_item_t* item);
/** Get a double precision float
*
@@ -65,7 +65,7 @@ _CBOR_NODISCARD CBOR_EXPORT float cbor_float_get_float4(
* @return double precision value
*/
_CBOR_NODISCARD CBOR_EXPORT double cbor_float_get_float8(
- const cbor_item_t *item);
+ const cbor_item_t* item);
/** Get the float value represented as double
*
@@ -75,14 +75,14 @@ _CBOR_NODISCARD CBOR_EXPORT double cbor_float_get_float8(
* @return double precision value
*/
_CBOR_NODISCARD CBOR_EXPORT double cbor_float_get_float(
- const cbor_item_t *item);
+ const cbor_item_t* item);
/** Get value from a boolean ctrl item
*
* @param item A ctrl item
* @return boolean value
*/
-_CBOR_NODISCARD CBOR_EXPORT bool cbor_get_bool(const cbor_item_t *item);
+_CBOR_NODISCARD CBOR_EXPORT bool cbor_get_bool(const cbor_item_t* item);
/** Constructs a new ctrl item
*
@@ -92,7 +92,7 @@ _CBOR_NODISCARD CBOR_EXPORT bool cbor_get_bool(const cbor_item_t *item);
* initialized to one.
* @return `NULL` if memory allocation fails
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_ctrl(void);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_new_ctrl(void);
/** Constructs a new float item
*
@@ -102,7 +102,7 @@ _CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_ctrl(void);
* initialized to one.
* @return `NULL` if memory allocation fails
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_float2(void);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_new_float2(void);
/** Constructs a new float item
*
@@ -112,7 +112,7 @@ _CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_float2(void);
* initialized to one.
* @return `NULL` if memory allocation fails
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_float4(void);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_new_float4(void);
/** Constructs a new float item
*
@@ -122,7 +122,7 @@ _CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_float4(void);
* initialized to one.
* @return `NULL` if memory allocation fails
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_float8(void);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_new_float8(void);
/** Constructs new null ctrl item
*
@@ -130,7 +130,7 @@ _CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_float8(void);
* initialized to one.
* @return `NULL` if memory allocation fails
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_null(void);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_new_null(void);
/** Constructs new undef ctrl item
*
@@ -138,7 +138,7 @@ _CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_null(void);
* initialized to one.
* @return `NULL` if memory allocation fails
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_undef(void);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_new_undef(void);
/** Constructs new boolean ctrl item
*
@@ -147,7 +147,7 @@ _CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_undef(void);
* initialized to one.
* @return `NULL` if memory allocation fails
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_build_bool(bool value);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_build_bool(bool value);
/** Assign a control value
*
@@ -160,42 +160,42 @@ _CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_build_bool(bool value);
* @param value The simple value to assign. Please consult the standard for
* allowed values
*/
-CBOR_EXPORT void cbor_set_ctrl(cbor_item_t *item, uint8_t value);
+CBOR_EXPORT void cbor_set_ctrl(cbor_item_t* item, uint8_t value);
/** Assign a boolean value to a boolean ctrl item
*
* @param item A ctrl item
* @param value The simple value to assign.
*/
-CBOR_EXPORT void cbor_set_bool(cbor_item_t *item, bool value);
+CBOR_EXPORT void cbor_set_bool(cbor_item_t* item, bool value);
/** Assigns a float value
*
* @param item A half precision float
* @param value The value to assign
*/
-CBOR_EXPORT void cbor_set_float2(cbor_item_t *item, float value);
+CBOR_EXPORT void cbor_set_float2(cbor_item_t* item, float value);
/** Assigns a float value
*
* @param item A single precision float
* @param value The value to assign
*/
-CBOR_EXPORT void cbor_set_float4(cbor_item_t *item, float value);
+CBOR_EXPORT void cbor_set_float4(cbor_item_t* item, float value);
/** Assigns a float value
*
* @param item A double precision float
* @param value The value to assign
*/
-CBOR_EXPORT void cbor_set_float8(cbor_item_t *item, double value);
+CBOR_EXPORT void cbor_set_float8(cbor_item_t* item, double value);
/** Reads the control value
*
* @param item A ctrl item
* @return the simple value
*/
-_CBOR_NODISCARD CBOR_EXPORT uint8_t cbor_ctrl_value(const cbor_item_t *item);
+_CBOR_NODISCARD CBOR_EXPORT uint8_t cbor_ctrl_value(const cbor_item_t* item);
/** Constructs a new float
*
@@ -204,7 +204,7 @@ _CBOR_NODISCARD CBOR_EXPORT uint8_t cbor_ctrl_value(const cbor_item_t *item);
* initialized to one.
* @return `NULL` if memory allocation fails
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_build_float2(float value);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_build_float2(float value);
/** Constructs a new float
*
@@ -213,7 +213,7 @@ _CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_build_float2(float value);
* initialized to one.
* @return `NULL` if memory allocation fails
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_build_float4(float value);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_build_float4(float value);
/** Constructs a new float
*
@@ -222,7 +222,7 @@ _CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_build_float4(float value);
* initialized to one.
* @return `NULL` if memory allocation fails
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_build_float8(double value);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_build_float8(double value);
/** Constructs a ctrl item
*
@@ -231,7 +231,7 @@ _CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_build_float8(double value);
* initialized to one.
* @return `NULL` if memory allocation fails
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_build_ctrl(uint8_t value);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_build_ctrl(uint8_t value);
#ifdef __cplusplus
}
diff --git a/src/cbor/internal/builder_callbacks.c b/src/cbor/internal/builder_callbacks.c
index 257cef3adbd1..24e7708da3e5 100644
--- a/src/cbor/internal/builder_callbacks.c
+++ b/src/cbor/internal/builder_callbacks.c
@@ -21,8 +21,8 @@
// `_cbor_builder_append` takes ownership of `item`. If adding the item to
// parent container fails, `item` will be deallocated to prevent memory.
-void _cbor_builder_append(cbor_item_t *item,
- struct _cbor_decoder_context *ctx) {
+void _cbor_builder_append(cbor_item_t* item,
+ struct _cbor_decoder_context* ctx) {
if (ctx->stack->size == 0) {
/* Top level item */
ctx->root = item;
@@ -49,7 +49,7 @@ void _cbor_builder_append(cbor_item_t *item,
cbor_decref(&item);
ctx->stack->top->subitems--;
if (ctx->stack->top->subitems == 0) {
- cbor_item_t *stack_item = ctx->stack->top->item;
+ cbor_item_t* stack_item = ctx->stack->top->item;
_cbor_stack_pop(ctx->stack);
_cbor_builder_append(stack_item, ctx);
}
@@ -86,7 +86,7 @@ void _cbor_builder_append(cbor_item_t *item,
CBOR_ASSERT(ctx->stack->top->subitems > 0);
ctx->stack->top->subitems--;
if (ctx->stack->top->subitems == 0) {
- cbor_item_t *map_entry = ctx->stack->top->item;
+ cbor_item_t* map_entry = ctx->stack->top->item;
_cbor_stack_pop(ctx->stack);
_cbor_builder_append(map_entry, ctx);
}
@@ -100,7 +100,7 @@ void _cbor_builder_append(cbor_item_t *item,
CBOR_ASSERT(ctx->stack->top->subitems == 1);
cbor_tag_set_item(ctx->stack->top->item, item);
cbor_decref(&item); /* Give up on our reference */
- cbor_item_t *tagged_item = ctx->stack->top->item;
+ cbor_item_t* tagged_item = ctx->stack->top->item;
_cbor_stack_pop(ctx->stack);
_cbor_builder_append(tagged_item, ctx);
break;
@@ -139,90 +139,90 @@ void _cbor_builder_append(cbor_item_t *item,
} \
} 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();
+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(ctx, res);
cbor_mark_uint(res);
cbor_set_uint8(res, value);
_cbor_builder_append(res, ctx);
}
-void cbor_builder_uint16_callback(void *context, uint16_t value) {
- struct _cbor_decoder_context *ctx = context;
- cbor_item_t *res = cbor_new_int16();
+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(ctx, res);
cbor_mark_uint(res);
cbor_set_uint16(res, value);
_cbor_builder_append(res, ctx);
}
-void cbor_builder_uint32_callback(void *context, uint32_t value) {
- struct _cbor_decoder_context *ctx = context;
- cbor_item_t *res = cbor_new_int32();
+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(ctx, res);
cbor_mark_uint(res);
cbor_set_uint32(res, value);
_cbor_builder_append(res, ctx);
}
-void cbor_builder_uint64_callback(void *context, uint64_t value) {
- struct _cbor_decoder_context *ctx = context;
- cbor_item_t *res = cbor_new_int64();
+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(ctx, res);
cbor_mark_uint(res);
cbor_set_uint64(res, value);
_cbor_builder_append(res, ctx);
}
-void cbor_builder_negint8_callback(void *context, uint8_t value) {
- struct _cbor_decoder_context *ctx = context;
- cbor_item_t *res = cbor_new_int8();
+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(ctx, res);
cbor_mark_negint(res);
cbor_set_uint8(res, value);
_cbor_builder_append(res, ctx);
}
-void cbor_builder_negint16_callback(void *context, uint16_t value) {
- struct _cbor_decoder_context *ctx = context;
- cbor_item_t *res = cbor_new_int16();
+void cbor_builder_negint16_callback(void* context, uint16_t value) {
+ struct _cbor_decoder_context* ctx = context;
+ cbor_item_t* res = cbor_new_int16();
CHECK_RES(ctx, res);
cbor_mark_negint(res);
cbor_set_uint16(res, value);
_cbor_builder_append(res, ctx);
}
-void cbor_builder_negint32_callback(void *context, uint32_t value) {
- struct _cbor_decoder_context *ctx = context;
- cbor_item_t *res = cbor_new_int32();
+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(ctx, res);
cbor_mark_negint(res);
cbor_set_uint32(res, value);
_cbor_builder_append(res, ctx);
}
-void cbor_builder_negint64_callback(void *context, uint64_t value) {
- struct _cbor_decoder_context *ctx = context;
- cbor_item_t *res = cbor_new_int64();
+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(ctx, res);
cbor_mark_negint(res);
cbor_set_uint64(res, value);
_cbor_builder_append(res, ctx);
}
-void cbor_builder_byte_string_callback(void *context, cbor_data data,
+void cbor_builder_byte_string_callback(void* context, cbor_data data,
uint64_t length) {
- struct _cbor_decoder_context *ctx = context;
+ struct _cbor_decoder_context* ctx = context;
CHECK_LENGTH(ctx, length);
- unsigned char *new_handle = _cbor_malloc(length);
+ unsigned char* new_handle = _cbor_malloc(length);
if (new_handle == NULL) {
ctx->creation_failed = true;
return;
}
memcpy(new_handle, data, length);
- cbor_item_t *new_chunk = cbor_new_definite_bytestring();
+ cbor_item_t* new_chunk = cbor_new_definite_bytestring();
if (new_chunk == NULL) {
_cbor_free(new_handle);
@@ -245,26 +245,26 @@ 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();
+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(ctx, res);
PUSH_CTX_STACK(ctx, res, 0);
}
-void cbor_builder_string_callback(void *context, cbor_data data,
+void cbor_builder_string_callback(void* context, cbor_data data,
uint64_t length) {
- struct _cbor_decoder_context *ctx = context;
+ struct _cbor_decoder_context* ctx = context;
CHECK_LENGTH(ctx, length);
- unsigned char *new_handle = _cbor_malloc(length);
+ unsigned char* new_handle = _cbor_malloc(length);
if (new_handle == NULL) {
ctx->creation_failed = true;
return;
}
memcpy(new_handle, data, length);
- cbor_item_t *new_chunk = cbor_new_definite_string();
+ cbor_item_t* new_chunk = cbor_new_definite_string();
if (new_chunk == NULL) {
_cbor_free(new_handle);
ctx->creation_failed = true;
@@ -285,17 +285,17 @@ 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();
+void cbor_builder_string_start_callback(void* context) {
+ struct _cbor_decoder_context* ctx = context;
+ cbor_item_t* res = cbor_new_indefinite_string();
CHECK_RES(ctx, res);
PUSH_CTX_STACK(ctx, res, 0);
}
-void cbor_builder_array_start_callback(void *context, uint64_t size) {
- struct _cbor_decoder_context *ctx = context;
+void cbor_builder_array_start_callback(void* context, uint64_t size) {
+ struct _cbor_decoder_context* ctx = context;
CHECK_LENGTH(ctx, size);
- cbor_item_t *res = cbor_new_definite_array(size);
+ cbor_item_t* res = cbor_new_definite_array(size);
CHECK_RES(ctx, res);
if (size > 0) {
PUSH_CTX_STACK(ctx, res, size);
@@ -304,24 +304,24 @@ void cbor_builder_array_start_callback(void *context, uint64_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();
+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(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();
+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(ctx, res);
PUSH_CTX_STACK(ctx, res, 0);
}
-void cbor_builder_map_start_callback(void *context, uint64_t size) {
- struct _cbor_decoder_context *ctx = context;
+void cbor_builder_map_start_callback(void* context, uint64_t size) {
+ struct _cbor_decoder_context* ctx = context;
CHECK_LENGTH(ctx, size);
- cbor_item_t *res = cbor_new_definite_map(size);
+ cbor_item_t* res = cbor_new_definite_map(size);
CHECK_RES(ctx, res);
if (size > 0) {
PUSH_CTX_STACK(ctx, res, size * 2);
@@ -333,7 +333,7 @@ void cbor_builder_map_start_callback(void *context, uint64_t size) {
/**
* Is the (partially constructed) item indefinite?
*/
-bool _cbor_is_indefinite(cbor_item_t *item) {
+bool _cbor_is_indefinite(cbor_item_t* item) {
switch (item->type) {
case CBOR_TYPE_BYTESTRING:
return cbor_bytestring_is_indefinite(item);
@@ -350,11 +350,11 @@ bool _cbor_is_indefinite(cbor_item_t *item) {
}
}
-void cbor_builder_indef_break_callback(void *context) {
- struct _cbor_decoder_context *ctx = context;
+void cbor_builder_indef_break_callback(void* context) {
+ struct _cbor_decoder_context* ctx = context;
/* There must be an item to break out of*/
if (ctx->stack->size > 0) {
- cbor_item_t *item = ctx->stack->top->item;
+ cbor_item_t* item = ctx->stack->top->item;
if (_cbor_is_indefinite(
item) && /* Only indefinite items can be terminated by 0xFF */
/* Special case: we cannot append up if an indefinite map is incomplete
@@ -369,54 +369,54 @@ void cbor_builder_indef_break_callback(void *context) {
ctx->syntax_error = true;
}
-void cbor_builder_float2_callback(void *context, float value) {
- struct _cbor_decoder_context *ctx = context;
- cbor_item_t *res = cbor_new_float2();
+void cbor_builder_float2_callback(void* context, float value) {
+ struct _cbor_decoder_context* ctx = context;
+ cbor_item_t* res = cbor_new_float2();
CHECK_RES(ctx, res);
cbor_set_float2(res, value);
_cbor_builder_append(res, ctx);
}
-void cbor_builder_float4_callback(void *context, float value) {
- struct _cbor_decoder_context *ctx = context;
- cbor_item_t *res = cbor_new_float4();
+void cbor_builder_float4_callback(void* context, float value) {
+ struct _cbor_decoder_context* ctx = context;
+ cbor_item_t* res = cbor_new_float4();
CHECK_RES(ctx, res);
cbor_set_float4(res, value);
_cbor_builder_append(res, ctx);
}
-void cbor_builder_float8_callback(void *context, double value) {
- struct _cbor_decoder_context *ctx = context;
- cbor_item_t *res = cbor_new_float8();
+void cbor_builder_float8_callback(void* context, double value) {
+ struct _cbor_decoder_context* ctx = context;
+ cbor_item_t* res = cbor_new_float8();
CHECK_RES(ctx, res);
cbor_set_float8(res, value);
_cbor_builder_append(res, ctx);
}
-void cbor_builder_null_callback(void *context) {
- struct _cbor_decoder_context *ctx = context;
- cbor_item_t *res = cbor_new_null();
+void cbor_builder_null_callback(void* context) {
+ struct _cbor_decoder_context* ctx = context;
+ cbor_item_t* res = cbor_new_null();
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();
+void cbor_builder_undefined_callback(void* context) {
+ struct _cbor_decoder_context* ctx = context;
+ cbor_item_t* res = cbor_new_undef();
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);
+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(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);
+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(ctx, res);
PUSH_CTX_STACK(ctx, res, 1);
}
diff --git a/src/cbor/internal/builder_callbacks.h b/src/cbor/internal/builder_callbacks.h
index 7893960e4131..0e034306952b 100644
--- a/src/cbor/internal/builder_callbacks.h
+++ b/src/cbor/internal/builder_callbacks.h
@@ -22,61 +22,61 @@ struct _cbor_decoder_context {
bool creation_failed;
/** Stack expectation mismatch */
bool syntax_error;
- cbor_item_t *root;
- struct _cbor_stack *stack;
+ cbor_item_t* root;
+ struct _cbor_stack* stack;
};
/** Internal helper: Append item to the top of the stack while handling errors.
*/
-void _cbor_builder_append(cbor_item_t *item, struct _cbor_decoder_context *ctx);
+void _cbor_builder_append(cbor_item_t* item, struct _cbor_decoder_context* ctx);
-void cbor_builder_uint8_callback(void *, uint8_t);
+void cbor_builder_uint8_callback(void*, uint8_t);
-void cbor_builder_uint16_callback(void *, uint16_t);
+void cbor_builder_uint16_callback(void*, uint16_t);
-void cbor_builder_uint32_callback(void *, uint32_t);
+void cbor_builder_uint32_callback(void*, uint32_t);
-void cbor_builder_uint64_callback(void *, uint64_t);
+void cbor_builder_uint64_callback(void*, uint64_t);
-void cbor_builder_negint8_callback(void *, uint8_t);
+void cbor_builder_negint8_callback(void*, uint8_t);
-void cbor_builder_negint16_callback(void *, uint16_t);
+void cbor_builder_negint16_callback(void*, uint16_t);
-void cbor_builder_negint32_callback(void *, uint32_t);
+void cbor_builder_negint32_callback(void*, uint32_t);
-void cbor_builder_negint64_callback(void *, uint64_t);
+void cbor_builder_negint64_callback(void*, uint64_t);
-void cbor_builder_string_callback(void *, cbor_data, uint64_t);
+void cbor_builder_string_callback(void*, cbor_data, uint64_t);
-void cbor_builder_string_start_callback(void *);
+void cbor_builder_string_start_callback(void*);
-void cbor_builder_byte_string_callback(void *, cbor_data, uint64_t);
+void cbor_builder_byte_string_callback(void*, cbor_data, uint64_t);
-void cbor_builder_byte_string_start_callback(void *);
+void cbor_builder_byte_string_start_callback(void*);
-void cbor_builder_array_start_callback(void *, uint64_t);
+void cbor_builder_array_start_callback(void*, uint64_t);
-void cbor_builder_indef_array_start_callback(void *);
+void cbor_builder_indef_array_start_callback(void*);
-void cbor_builder_map_start_callback(void *, uint64_t);
+void cbor_builder_map_start_callback(void*, uint64_t);
-void cbor_builder_indef_map_start_callback(void *);
+void cbor_builder_indef_map_start_callback(void*);
-void cbor_builder_tag_callback(void *, uint64_t);
+void cbor_builder_tag_callback(void*, uint64_t);
-void cbor_builder_float2_callback(void *, float);
+void cbor_builder_float2_callback(void*, float);
-void cbor_builder_float4_callback(void *, float);
+void cbor_builder_float4_callback(void*, float);
-void cbor_builder_float8_callback(void *, double);
+void cbor_builder_float8_callback(void*, double);
-void cbor_builder_null_callback(void *);
+void cbor_builder_null_callback(void*);
-void cbor_builder_undefined_callback(void *);
+void cbor_builder_undefined_callback(void*);
-void cbor_builder_boolean_callback(void *, bool);
+void cbor_builder_boolean_callback(void*, bool);
-void cbor_builder_indef_break_callback(void *);
+void cbor_builder_indef_break_callback(void*);
#ifdef __cplusplus
}
diff --git a/src/cbor/internal/encoders.c b/src/cbor/internal/encoders.c
index 49d4d7f33d2b..773df7970c29 100644
--- a/src/cbor/internal/encoders.c
+++ b/src/cbor/internal/encoders.c
@@ -6,9 +6,10 @@
*/
#include "encoders.h"
+
#include <string.h>
-size_t _cbor_encode_uint8(uint8_t value, unsigned char *buffer,
+size_t _cbor_encode_uint8(uint8_t value, unsigned char* buffer,
size_t buffer_size, uint8_t offset) {
if (value <= 23) {
if (buffer_size >= 1) {
@@ -25,43 +26,43 @@ size_t _cbor_encode_uint8(uint8_t value, unsigned char *buffer,
return 0;
}
-size_t _cbor_encode_uint16(uint16_t value, unsigned char *buffer,
+size_t _cbor_encode_uint16(uint16_t value, unsigned char* buffer,
size_t buffer_size, uint8_t offset) {
- if (buffer_size >= 3) {
- buffer[0] = 0x19 + offset;
+ if (buffer_size < 3) {
+ return 0;
+ }
+ buffer[0] = 0x19 + offset;
#ifdef IS_BIG_ENDIAN
- memcpy(buffer + 1, &value, 2);
+ memcpy(buffer + 1, &value, 2);
#else
- buffer[1] = (unsigned char)(value >> 8);
- buffer[2] = (unsigned char)value;
+ buffer[1] = (unsigned char)(value >> 8);
+ buffer[2] = (unsigned char)value;
#endif
- return 3;
- } else
- return 0;
+ return 3;
}
-size_t _cbor_encode_uint32(uint32_t value, unsigned char *buffer,
+size_t _cbor_encode_uint32(uint32_t value, unsigned char* buffer,
size_t buffer_size, uint8_t offset) {
- if (buffer_size >= 5) {
- buffer[0] = 0x1A + offset;
+ if (buffer_size < 5) {
+ return 0;
+ }
+ buffer[0] = 0x1A + offset;
#ifdef IS_BIG_ENDIAN
- memcpy(buffer + 1, &value, 4);
+ memcpy(buffer + 1, &value, 4);
#else
- buffer[1] = (unsigned char)(value >> 24);
- buffer[2] = (unsigned char)(value >> 16);
- buffer[3] = (unsigned char)(value >> 8);
- buffer[4] = (unsigned char)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;
- } else
- return 0;
+ return 5;
}
-size_t _cbor_encode_uint64(uint64_t value, unsigned char *buffer,
+size_t _cbor_encode_uint64(uint64_t value, unsigned char* buffer,
size_t buffer_size, uint8_t offset) {
if (buffer_size >= 9) {
buffer[0] = 0x1B + offset;
@@ -84,7 +85,7 @@ size_t _cbor_encode_uint64(uint64_t value, unsigned char *buffer,
return 0;
}
-size_t _cbor_encode_uint(uint64_t value, unsigned char *buffer,
+size_t _cbor_encode_uint(uint64_t value, unsigned char* buffer,
size_t buffer_size, uint8_t offset) {
if (value <= UINT16_MAX)
if (value <= UINT8_MAX)
diff --git a/src/cbor/internal/encoders.h b/src/cbor/internal/encoders.h
index 7eadb7121646..162b0bad2c13 100644
--- a/src/cbor/internal/encoders.h
+++ b/src/cbor/internal/encoders.h
@@ -15,23 +15,23 @@ extern "C" {
#endif
_CBOR_NODISCARD
-size_t _cbor_encode_uint8(uint8_t value, unsigned char *buffer,
+size_t _cbor_encode_uint8(uint8_t value, unsigned char* buffer,
size_t buffer_size, uint8_t offset);
_CBOR_NODISCARD
-size_t _cbor_encode_uint16(uint16_t value, unsigned char *buffer,
+size_t _cbor_encode_uint16(uint16_t value, unsigned char* buffer,
size_t buffer_size, uint8_t offset);
_CBOR_NODISCARD
-size_t _cbor_encode_uint32(uint32_t value, unsigned char *buffer,
+size_t _cbor_encode_uint32(uint32_t value, unsigned char* buffer,
size_t buffer_size, uint8_t offset);
_CBOR_NODISCARD
-size_t _cbor_encode_uint64(uint64_t value, unsigned char *buffer,
+size_t _cbor_encode_uint64(uint64_t value, unsigned char* buffer,
size_t buffer_size, uint8_t offset);
_CBOR_NODISCARD
-size_t _cbor_encode_uint(uint64_t value, unsigned char *buffer,
+size_t _cbor_encode_uint(uint64_t value, unsigned char* buffer,
size_t buffer_size, uint8_t offset);
#ifdef __cplusplus
diff --git a/src/cbor/internal/loaders.c b/src/cbor/internal/loaders.c
index cfa173de7905..b89cf72235c6 100644
--- a/src/cbor/internal/loaders.c
+++ b/src/cbor/internal/loaders.c
@@ -11,7 +11,7 @@
uint8_t _cbor_load_uint8(cbor_data source) { return (uint8_t)*source; }
-uint16_t _cbor_load_uint16(const unsigned char *source) {
+uint16_t _cbor_load_uint16(const unsigned char* source) {
#ifdef IS_BIG_ENDIAN
uint16_t result;
memcpy(&result, source, 2);
@@ -21,7 +21,7 @@ uint16_t _cbor_load_uint16(const unsigned char *source) {
#endif
}
-uint32_t _cbor_load_uint32(const unsigned char *source) {
+uint32_t _cbor_load_uint32(const unsigned char* source) {
#ifdef IS_BIG_ENDIAN
uint32_t result;
memcpy(&result, source, 4);
@@ -33,7 +33,7 @@ uint32_t _cbor_load_uint32(const unsigned char *source) {
#endif
}
-uint64_t _cbor_load_uint64(const unsigned char *source) {
+uint64_t _cbor_load_uint64(const unsigned char* source) {
#ifdef IS_BIG_ENDIAN
uint64_t result;
memcpy(&result, source, 8);
@@ -50,7 +50,9 @@ uint64_t _cbor_load_uint64(const unsigned char *source) {
}
/* As per https://www.rfc-editor.org/rfc/rfc8949.html#name-half-precision */
-float _cbor_decode_half(unsigned char *halfp) {
+float _cbor_decode_half(unsigned char* halfp) {
+ // TODO: Broken if we are not on IEEE 754
+ // (https://github.com/PJK/libcbor/issues/336)
int half = (halfp[0] << 8) + halfp[1];
int exp = (half >> 10) & 0x1f;
int mant = half & 0x3ff;
@@ -66,15 +68,19 @@ float _cbor_decode_half(unsigned char *halfp) {
float _cbor_load_half(cbor_data source) {
/* Discard const */
- return _cbor_decode_half((unsigned char *)source);
+ return _cbor_decode_half((unsigned char*)source);
}
float _cbor_load_float(cbor_data source) {
+ // TODO: Broken if we are not on IEEE 754
+ // (https://github.com/PJK/libcbor/issues/336)
union _cbor_float_helper helper = {.as_uint = _cbor_load_uint32(source)};
return helper.as_float;
}
double _cbor_load_double(cbor_data source) {
+ // TODO: Broken if we are not on IEEE 754
+ // (https://github.com/PJK/libcbor/issues/336)
union _cbor_double_helper helper = {.as_uint = _cbor_load_uint64(source)};
return helper.as_double;
}
diff --git a/src/cbor/internal/loaders.h b/src/cbor/internal/loaders.h
index ce37563a3d80..9e8eb68e29a2 100644
--- a/src/cbor/internal/loaders.h
+++ b/src/cbor/internal/loaders.h
@@ -16,16 +16,16 @@ extern "C" {
/* Read the given uint from the given location, no questions asked */
_CBOR_NODISCARD
-uint8_t _cbor_load_uint8(const unsigned char *source);
+uint8_t _cbor_load_uint8(const unsigned char* source);
_CBOR_NODISCARD
-uint16_t _cbor_load_uint16(const unsigned char *source);
+uint16_t _cbor_load_uint16(const unsigned char* source);
_CBOR_NODISCARD
-uint32_t _cbor_load_uint32(const unsigned char *source);
+uint32_t _cbor_load_uint32(const unsigned char* source);
_CBOR_NODISCARD
-uint64_t _cbor_load_uint64(const unsigned char *source);
+uint64_t _cbor_load_uint64(const unsigned char* source);
_CBOR_NODISCARD
float _cbor_load_half(cbor_data source);
diff --git a/src/cbor/internal/stack.c b/src/cbor/internal/stack.c
index 2db03cbbf081..00e6aed52376 100644
--- a/src/cbor/internal/stack.c
+++ b/src/cbor/internal/stack.c
@@ -11,18 +11,18 @@ struct _cbor_stack _cbor_stack_init(void) {
return (struct _cbor_stack){.top = NULL, .size = 0};
}
-void _cbor_stack_pop(struct _cbor_stack *stack) {
- struct _cbor_stack_record *top = stack->top;
+void _cbor_stack_pop(struct _cbor_stack* stack) {
+ struct _cbor_stack_record* top = stack->top;
stack->top = stack->top->lower;
_cbor_free(top);
stack->size--;
}
-struct _cbor_stack_record *_cbor_stack_push(struct _cbor_stack *stack,
- cbor_item_t *item,
+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 =
+ struct _cbor_stack_record* new_top =
_cbor_malloc(sizeof(struct _cbor_stack_record));
if (new_top == NULL) return NULL;
diff --git a/src/cbor/internal/stack.h b/src/cbor/internal/stack.h
index cf2206b40e58..7bc43ac09f9b 100644
--- a/src/cbor/internal/stack.h
+++ b/src/cbor/internal/stack.h
@@ -17,9 +17,9 @@ extern "C" {
/** Simple stack record for the parser */
struct _cbor_stack_record {
/** Pointer to the parent stack frame */
- struct _cbor_stack_record *lower;
+ struct _cbor_stack_record* lower;
/** Item under construction */
- cbor_item_t *item;
+ cbor_item_t* item;
/**
* How many outstanding subitems are expected.
*
@@ -33,17 +33,17 @@ struct _cbor_stack_record {
/** Stack handle - contents and size */
struct _cbor_stack {
- struct _cbor_stack_record *top;
+ struct _cbor_stack_record* top;
size_t size;
};
_CBOR_NODISCARD
struct _cbor_stack _cbor_stack_init(void);
-void _cbor_stack_pop(struct _cbor_stack *);
+void _cbor_stack_pop(struct _cbor_stack*);
_CBOR_NODISCARD
-struct _cbor_stack_record *_cbor_stack_push(struct _cbor_stack *, cbor_item_t *,
+struct _cbor_stack_record* _cbor_stack_push(struct _cbor_stack*, cbor_item_t*,
size_t);
#ifdef __cplusplus
diff --git a/src/cbor/ints.c b/src/cbor/ints.c
index b4d035a1897e..272d82550c48 100644
--- a/src/cbor/ints.c
+++ b/src/cbor/ints.c
@@ -7,36 +7,36 @@
#include "ints.h"
-cbor_int_width cbor_int_get_width(const cbor_item_t *item) {
+cbor_int_width cbor_int_get_width(const cbor_item_t* item) {
CBOR_ASSERT(cbor_is_int(item));
return item->metadata.int_metadata.width;
}
-uint8_t cbor_get_uint8(const cbor_item_t *item) {
+uint8_t cbor_get_uint8(const cbor_item_t* item) {
CBOR_ASSERT(cbor_is_int(item));
CBOR_ASSERT(cbor_int_get_width(item) == CBOR_INT_8);
return *item->data;
}
-uint16_t cbor_get_uint16(const cbor_item_t *item) {
+uint16_t cbor_get_uint16(const cbor_item_t* item) {
CBOR_ASSERT(cbor_is_int(item));
CBOR_ASSERT(cbor_int_get_width(item) == CBOR_INT_16);
- return *(uint16_t *)item->data;
+ return *(uint16_t*)item->data;
}
-uint32_t cbor_get_uint32(const cbor_item_t *item) {
+uint32_t cbor_get_uint32(const cbor_item_t* item) {
CBOR_ASSERT(cbor_is_int(item));
CBOR_ASSERT(cbor_int_get_width(item) == CBOR_INT_32);
- return *(uint32_t *)item->data;
+ return *(uint32_t*)item->data;
}
-uint64_t cbor_get_uint64(const cbor_item_t *item) {
+uint64_t cbor_get_uint64(const cbor_item_t* item) {
CBOR_ASSERT(cbor_is_int(item));
CBOR_ASSERT(cbor_int_get_width(item) == CBOR_INT_64);
- return *(uint64_t *)item->data;
+ return *(uint64_t*)item->data;
}
-uint64_t cbor_get_int(const cbor_item_t *item) {
+uint64_t cbor_get_int(const cbor_item_t* item) {
CBOR_ASSERT(cbor_is_int(item));
// cppcheck-suppress missingReturn
switch (cbor_int_get_width(item)) {
@@ -48,141 +48,144 @@ uint64_t cbor_get_int(const cbor_item_t *item) {
return cbor_get_uint32(item);
case CBOR_INT_64:
return cbor_get_uint64(item);
+ default:
+ _CBOR_UNREACHABLE;
+ return 0;
}
}
-void cbor_set_uint8(cbor_item_t *item, uint8_t value) {
+void cbor_set_uint8(cbor_item_t* item, uint8_t value) {
CBOR_ASSERT(cbor_is_int(item));
CBOR_ASSERT(cbor_int_get_width(item) == CBOR_INT_8);
*item->data = value;
}
-void cbor_set_uint16(cbor_item_t *item, uint16_t value) {
+void cbor_set_uint16(cbor_item_t* item, uint16_t value) {
CBOR_ASSERT(cbor_is_int(item));
CBOR_ASSERT(cbor_int_get_width(item) == CBOR_INT_16);
- *(uint16_t *)item->data = value;
+ *(uint16_t*)item->data = value;
}
-void cbor_set_uint32(cbor_item_t *item, uint32_t value) {
+void cbor_set_uint32(cbor_item_t* item, uint32_t value) {
CBOR_ASSERT(cbor_is_int(item));
CBOR_ASSERT(cbor_int_get_width(item) == CBOR_INT_32);
- *(uint32_t *)item->data = value;
+ *(uint32_t*)item->data = value;
}
-void cbor_set_uint64(cbor_item_t *item, uint64_t value) {
+void cbor_set_uint64(cbor_item_t* item, uint64_t value) {
CBOR_ASSERT(cbor_is_int(item));
CBOR_ASSERT(cbor_int_get_width(item) == CBOR_INT_64);
- *(uint64_t *)item->data = value;
+ *(uint64_t*)item->data = value;
}
-void cbor_mark_uint(cbor_item_t *item) {
+void cbor_mark_uint(cbor_item_t* item) {
CBOR_ASSERT(cbor_is_int(item));
item->type = CBOR_TYPE_UINT;
}
-void cbor_mark_negint(cbor_item_t *item) {
+void cbor_mark_negint(cbor_item_t* item) {
CBOR_ASSERT(cbor_is_int(item));
item->type = CBOR_TYPE_NEGINT;
}
-cbor_item_t *cbor_new_int8(void) {
- cbor_item_t *item = _cbor_malloc(sizeof(cbor_item_t) + 1);
+cbor_item_t* cbor_new_int8(void) {
+ cbor_item_t* item = _cbor_malloc(sizeof(cbor_item_t) + 1);
_CBOR_NOTNULL(item);
- *item = (cbor_item_t){.data = (unsigned char *)item + sizeof(cbor_item_t),
+ *item = (cbor_item_t){.data = (unsigned char*)item + sizeof(cbor_item_t),
.refcount = 1,
.metadata = {.int_metadata = {.width = CBOR_INT_8}},
.type = CBOR_TYPE_UINT};
return item;
}
-cbor_item_t *cbor_new_int16(void) {
- cbor_item_t *item = _cbor_malloc(sizeof(cbor_item_t) + 2);
+cbor_item_t* cbor_new_int16(void) {
+ cbor_item_t* item = _cbor_malloc(sizeof(cbor_item_t) + 2);
_CBOR_NOTNULL(item);
- *item = (cbor_item_t){.data = (unsigned char *)item + sizeof(cbor_item_t),
+ *item = (cbor_item_t){.data = (unsigned char*)item + sizeof(cbor_item_t),
.refcount = 1,
.metadata = {.int_metadata = {.width = CBOR_INT_16}},
.type = CBOR_TYPE_UINT};
return item;
}
-cbor_item_t *cbor_new_int32(void) {
- cbor_item_t *item = _cbor_malloc(sizeof(cbor_item_t) + 4);
+cbor_item_t* cbor_new_int32(void) {
+ cbor_item_t* item = _cbor_malloc(sizeof(cbor_item_t) + 4);
_CBOR_NOTNULL(item);
- *item = (cbor_item_t){.data = (unsigned char *)item + sizeof(cbor_item_t),
+ *item = (cbor_item_t){.data = (unsigned char*)item + sizeof(cbor_item_t),
.refcount = 1,
.metadata = {.int_metadata = {.width = CBOR_INT_32}},
.type = CBOR_TYPE_UINT};
return item;
}
-cbor_item_t *cbor_new_int64(void) {
- cbor_item_t *item = _cbor_malloc(sizeof(cbor_item_t) + 8);
+cbor_item_t* cbor_new_int64(void) {
+ cbor_item_t* item = _cbor_malloc(sizeof(cbor_item_t) + 8);
_CBOR_NOTNULL(item);
- *item = (cbor_item_t){.data = (unsigned char *)item + sizeof(cbor_item_t),
+ *item = (cbor_item_t){.data = (unsigned char*)item + sizeof(cbor_item_t),
.refcount = 1,
.metadata = {.int_metadata = {.width = CBOR_INT_64}},
.type = CBOR_TYPE_UINT};
return item;
}
-cbor_item_t *cbor_build_uint8(uint8_t value) {
- cbor_item_t *item = cbor_new_int8();
+cbor_item_t* cbor_build_uint8(uint8_t value) {
+ cbor_item_t* item = cbor_new_int8();
_CBOR_NOTNULL(item);
cbor_set_uint8(item, value);
cbor_mark_uint(item);
return item;
}
-cbor_item_t *cbor_build_uint16(uint16_t value) {
- cbor_item_t *item = cbor_new_int16();
+cbor_item_t* cbor_build_uint16(uint16_t value) {
+ cbor_item_t* item = cbor_new_int16();
_CBOR_NOTNULL(item);
cbor_set_uint16(item, value);
cbor_mark_uint(item);
return item;
}
-cbor_item_t *cbor_build_uint32(uint32_t value) {
- cbor_item_t *item = cbor_new_int32();
+cbor_item_t* cbor_build_uint32(uint32_t value) {
+ cbor_item_t* item = cbor_new_int32();
_CBOR_NOTNULL(item);
cbor_set_uint32(item, value);
cbor_mark_uint(item);
return item;
}
-cbor_item_t *cbor_build_uint64(uint64_t value) {
- cbor_item_t *item = cbor_new_int64();
+cbor_item_t* cbor_build_uint64(uint64_t value) {
+ cbor_item_t* item = cbor_new_int64();
_CBOR_NOTNULL(item);
cbor_set_uint64(item, value);
cbor_mark_uint(item);
return item;
}
-cbor_item_t *cbor_build_negint8(uint8_t value) {
- cbor_item_t *item = cbor_new_int8();
+cbor_item_t* cbor_build_negint8(uint8_t value) {
+ cbor_item_t* item = cbor_new_int8();
_CBOR_NOTNULL(item);
cbor_set_uint8(item, value);
cbor_mark_negint(item);
return item;
}
-cbor_item_t *cbor_build_negint16(uint16_t value) {
- cbor_item_t *item = cbor_new_int16();
+cbor_item_t* cbor_build_negint16(uint16_t value) {
+ cbor_item_t* item = cbor_new_int16();
_CBOR_NOTNULL(item);
cbor_set_uint16(item, value);
cbor_mark_negint(item);
return item;
}
-cbor_item_t *cbor_build_negint32(uint32_t value) {
- cbor_item_t *item = cbor_new_int32();
+cbor_item_t* cbor_build_negint32(uint32_t value) {
+ cbor_item_t* item = cbor_new_int32();
_CBOR_NOTNULL(item);
cbor_set_uint32(item, value);
cbor_mark_negint(item);
return item;
}
-cbor_item_t *cbor_build_negint64(uint64_t value) {
- cbor_item_t *item = cbor_new_int64();
+cbor_item_t* cbor_build_negint64(uint64_t value) {
+ cbor_item_t* item = cbor_new_int64();
_CBOR_NOTNULL(item);
cbor_set_uint64(item, value);
cbor_mark_negint(item);
diff --git a/src/cbor/ints.h b/src/cbor/ints.h
index 006aa428e0a5..30d061035fe0 100644
--- a/src/cbor/ints.h
+++ b/src/cbor/ints.h
@@ -26,35 +26,35 @@ extern "C" {
* @param item positive or negative integer
* @return the value
*/
-_CBOR_NODISCARD CBOR_EXPORT uint8_t cbor_get_uint8(const cbor_item_t *item);
+_CBOR_NODISCARD CBOR_EXPORT uint8_t cbor_get_uint8(const cbor_item_t* item);
/** Extracts the integer value
*
* @param item positive or negative integer
* @return the value
*/
-_CBOR_NODISCARD CBOR_EXPORT uint16_t cbor_get_uint16(const cbor_item_t *item);
+_CBOR_NODISCARD CBOR_EXPORT uint16_t cbor_get_uint16(const cbor_item_t* item);
/** Extracts the integer value
*
* @param item positive or negative integer
* @return the value
*/
-_CBOR_NODISCARD CBOR_EXPORT uint32_t cbor_get_uint32(const cbor_item_t *item);
+_CBOR_NODISCARD CBOR_EXPORT uint32_t cbor_get_uint32(const cbor_item_t* item);
/** Extracts the integer value
*
* @param item positive or negative integer
* @return the value
*/
-_CBOR_NODISCARD CBOR_EXPORT uint64_t cbor_get_uint64(const cbor_item_t *item);
+_CBOR_NODISCARD CBOR_EXPORT uint64_t cbor_get_uint64(const cbor_item_t* item);
/** Extracts the integer value
*
* @param item positive or negative integer
* @return the value, extended to `uint64_t`
*/
-_CBOR_NODISCARD CBOR_EXPORT uint64_t cbor_get_int(const cbor_item_t *item);
+_CBOR_NODISCARD CBOR_EXPORT uint64_t cbor_get_int(const cbor_item_t* item);
/** Assigns the integer value
*
@@ -62,7 +62,7 @@ _CBOR_NODISCARD CBOR_EXPORT uint64_t cbor_get_int(const cbor_item_t *item);
* @param value the value to assign. For negative integer, the logical value is
* `-value - 1`
*/
-CBOR_EXPORT void cbor_set_uint8(cbor_item_t *item, uint8_t value);
+CBOR_EXPORT void cbor_set_uint8(cbor_item_t* item, uint8_t value);
/** Assigns the integer value
*
@@ -70,7 +70,7 @@ CBOR_EXPORT void cbor_set_uint8(cbor_item_t *item, uint8_t value);
* @param value the value to assign. For negative integer, the logical value is
* `-value - 1`
*/
-CBOR_EXPORT void cbor_set_uint16(cbor_item_t *item, uint16_t value);
+CBOR_EXPORT void cbor_set_uint16(cbor_item_t* item, uint16_t value);
/** Assigns the integer value
*
@@ -78,7 +78,7 @@ CBOR_EXPORT void cbor_set_uint16(cbor_item_t *item, uint16_t value);
* @param value the value to assign. For negative integer, the logical value is
* `-value - 1`
*/
-CBOR_EXPORT void cbor_set_uint32(cbor_item_t *item, uint32_t value);
+CBOR_EXPORT void cbor_set_uint32(cbor_item_t* item, uint32_t value);
/** Assigns the integer value
*
@@ -86,7 +86,7 @@ CBOR_EXPORT void cbor_set_uint32(cbor_item_t *item, uint32_t value);
* @param value the value to assign. For negative integer, the logical value is
* `-value - 1`
*/
-CBOR_EXPORT void cbor_set_uint64(cbor_item_t *item, uint64_t value);
+CBOR_EXPORT void cbor_set_uint64(cbor_item_t* item, uint64_t value);
/** Queries the integer width
*
@@ -94,7 +94,7 @@ CBOR_EXPORT void cbor_set_uint64(cbor_item_t *item, uint64_t value);
* @return the width
*/
_CBOR_NODISCARD CBOR_EXPORT cbor_int_width
-cbor_int_get_width(const cbor_item_t *item);
+cbor_int_get_width(const cbor_item_t* item);
/** Marks the integer item as a positive integer
*
@@ -102,7 +102,7 @@ cbor_int_get_width(const cbor_item_t *item);
*
* @param item positive or negative integer item
*/
-CBOR_EXPORT void cbor_mark_uint(cbor_item_t *item);
+CBOR_EXPORT void cbor_mark_uint(cbor_item_t* item);
/** Marks the integer item as a negative integer
*
@@ -110,7 +110,7 @@ CBOR_EXPORT void cbor_mark_uint(cbor_item_t *item);
*
* @param item positive or negative integer item
*/
-CBOR_EXPORT void cbor_mark_negint(cbor_item_t *item);
+CBOR_EXPORT void cbor_mark_negint(cbor_item_t* item);
/** Allocates new integer with 1B width
*
@@ -119,7 +119,7 @@ CBOR_EXPORT void cbor_mark_negint(cbor_item_t *item);
* @return **new** positive integer or `NULL` on memory allocation failure. The
* value is not initialized
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_int8(void);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_new_int8(void);
/** Allocates new integer with 2B width
*
@@ -128,7 +128,7 @@ _CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_int8(void);
* @return **new** positive integer or `NULL` on memory allocation failure. The
* value is not initialized
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_int16(void);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_new_int16(void);
/** Allocates new integer with 4B width
*
@@ -137,7 +137,7 @@ _CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_int16(void);
* @return **new** positive integer or `NULL` on memory allocation failure. The
* value is not initialized
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_int32(void);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_new_int32(void);
/** Allocates new integer with 8B width
*
@@ -146,63 +146,63 @@ _CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_int32(void);
* @return **new** positive integer or `NULL` on memory allocation failure. The
* value is not initialized
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_int64(void);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_new_int64(void);
/** Constructs a new positive integer
*
* @param value the value to use
* @return **new** positive integer or `NULL` on memory allocation failure
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_build_uint8(uint8_t value);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_build_uint8(uint8_t value);
/** Constructs a new positive integer
*
* @param value the value to use
* @return **new** positive integer or `NULL` on memory allocation failure
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_build_uint16(uint16_t value);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_build_uint16(uint16_t value);
/** Constructs a new positive integer
*
* @param value the value to use
* @return **new** positive integer or `NULL` on memory allocation failure
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_build_uint32(uint32_t value);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_build_uint32(uint32_t value);
/** Constructs a new positive integer
*
* @param value the value to use
* @return **new** positive integer or `NULL` on memory allocation failure
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_build_uint64(uint64_t value);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_build_uint64(uint64_t value);
/** Constructs a new negative integer
*
* @param value the value to use
* @return **new** negative integer or `NULL` on memory allocation failure
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_build_negint8(uint8_t value);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_build_negint8(uint8_t value);
/** Constructs a new negative integer
*
* @param value the value to use
* @return **new** negative integer or `NULL` on memory allocation failure
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_build_negint16(uint16_t value);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_build_negint16(uint16_t value);
/** Constructs a new negative integer
*
* @param value the value to use
* @return **new** negative integer or `NULL` on memory allocation failure
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_build_negint32(uint32_t value);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_build_negint32(uint32_t value);
/** Constructs a new negative integer
*
* @param value the value to use
* @return **new** negative integer or `NULL` on memory allocation failure
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_build_negint64(uint64_t value);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_build_negint64(uint64_t value);
#ifdef __cplusplus
}
diff --git a/src/cbor/maps.c b/src/cbor/maps.c
index 8a3bd6075681..7ce168a1ed7c 100644
--- a/src/cbor/maps.c
+++ b/src/cbor/maps.c
@@ -8,18 +8,18 @@
#include "maps.h"
#include "internal/memory_utils.h"
-size_t cbor_map_size(const cbor_item_t *item) {
+size_t cbor_map_size(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_map(item));
return item->metadata.map_metadata.end_ptr;
}
-size_t cbor_map_allocated(const cbor_item_t *item) {
+size_t cbor_map_allocated(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_map(item));
return item->metadata.map_metadata.allocated;
}
-cbor_item_t *cbor_new_definite_map(size_t size) {
- cbor_item_t *item = _cbor_malloc(sizeof(cbor_item_t));
+cbor_item_t* cbor_new_definite_map(size_t size) {
+ cbor_item_t* item = _cbor_malloc(sizeof(cbor_item_t));
_CBOR_NOTNULL(item);
*item = (cbor_item_t){
@@ -34,8 +34,8 @@ cbor_item_t *cbor_new_definite_map(size_t size) {
return item;
}
-cbor_item_t *cbor_new_indefinite_map(void) {
- cbor_item_t *item = _cbor_malloc(sizeof(cbor_item_t));
+cbor_item_t* cbor_new_indefinite_map(void) {
+ cbor_item_t* item = _cbor_malloc(sizeof(cbor_item_t));
_CBOR_NOTNULL(item);
*item = (cbor_item_t){
@@ -49,12 +49,12 @@ cbor_item_t *cbor_new_indefinite_map(void) {
return item;
}
-bool _cbor_map_add_key(cbor_item_t *item, cbor_item_t *key) {
+bool _cbor_map_add_key(cbor_item_t* item, cbor_item_t* key) {
CBOR_ASSERT(cbor_isa_map(item));
- struct _cbor_map_metadata *metadata =
- (struct _cbor_map_metadata *)&item->metadata;
+ struct _cbor_map_metadata* metadata =
+ (struct _cbor_map_metadata*)&item->metadata;
if (cbor_map_is_definite(item)) {
- struct cbor_pair *data = cbor_map_handle(item);
+ struct cbor_pair* data = cbor_map_handle(item);
if (metadata->end_ptr >= metadata->allocated) {
/* Don't realloc definite preallocated map */
return false;
@@ -74,7 +74,7 @@ bool _cbor_map_add_key(cbor_item_t *item, cbor_item_t *key) {
? 1
: CBOR_BUFFER_GROWTH * metadata->allocated;
- unsigned char *new_data = _cbor_realloc_multiple(
+ unsigned char* new_data = _cbor_realloc_multiple(
item->data, sizeof(struct cbor_pair), new_allocation);
if (new_data == NULL) {
@@ -84,7 +84,7 @@ bool _cbor_map_add_key(cbor_item_t *item, cbor_item_t *key) {
item->data = new_data;
metadata->allocated = new_allocation;
}
- struct cbor_pair *data = cbor_map_handle(item);
+ struct cbor_pair* data = cbor_map_handle(item);
data[metadata->end_ptr].key = key;
data[metadata->end_ptr++].value = NULL;
}
@@ -92,7 +92,7 @@ bool _cbor_map_add_key(cbor_item_t *item, cbor_item_t *key) {
return true;
}
-bool _cbor_map_add_value(cbor_item_t *item, cbor_item_t *value) {
+bool _cbor_map_add_value(cbor_item_t* item, cbor_item_t* value) {
CBOR_ASSERT(cbor_isa_map(item));
cbor_incref(value);
cbor_map_handle(item)[
@@ -104,22 +104,22 @@ bool _cbor_map_add_value(cbor_item_t *item, cbor_item_t *value) {
}
// TODO: Add a more convenient API like add(item, key, val)
-bool cbor_map_add(cbor_item_t *item, struct cbor_pair pair) {
+bool cbor_map_add(cbor_item_t* item, struct cbor_pair pair) {
CBOR_ASSERT(cbor_isa_map(item));
if (!_cbor_map_add_key(item, pair.key)) return false;
return _cbor_map_add_value(item, pair.value);
}
-bool cbor_map_is_definite(const cbor_item_t *item) {
+bool cbor_map_is_definite(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_map(item));
return item->metadata.map_metadata.type == _CBOR_METADATA_DEFINITE;
}
-bool cbor_map_is_indefinite(const cbor_item_t *item) {
+bool cbor_map_is_indefinite(const cbor_item_t* item) {
return !cbor_map_is_definite(item);
}
-struct cbor_pair *cbor_map_handle(const cbor_item_t *item) {
+struct cbor_pair* cbor_map_handle(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_map(item));
- return (struct cbor_pair *)item->data;
+ return (struct cbor_pair*)item->data;
}
diff --git a/src/cbor/maps.h b/src/cbor/maps.h
index 5c05b542bd84..d8b5f53b9e2a 100644
--- a/src/cbor/maps.h
+++ b/src/cbor/maps.h
@@ -26,14 +26,14 @@ extern "C" {
* @param item A map
* @return The number of pairs
*/
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_map_size(const cbor_item_t *item);
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_map_size(const cbor_item_t* item);
/** Get the size of the allocated storage
*
* @param item A map
* @return Allocated storage size (as the number of #cbor_pair items)
*/
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_map_allocated(const cbor_item_t *item);
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_map_allocated(const cbor_item_t* item);
/** Create a new definite map
*
@@ -42,7 +42,7 @@ _CBOR_NODISCARD CBOR_EXPORT size_t cbor_map_allocated(const cbor_item_t *item);
* initialized to one.
* @return `NULL` if memory allocation fails
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_definite_map(size_t size);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_new_definite_map(size_t size);
/** Create a new indefinite map
*
@@ -50,7 +50,7 @@ _CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_definite_map(size_t size);
* initialized to one.
* @return `NULL` if memory allocation fails
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_indefinite_map(void);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_new_indefinite_map(void);
/** Add a pair to the map
*
@@ -63,7 +63,7 @@ _CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_indefinite_map(void);
* @return `true` on success, `false` if memory allocation failed (indefinite
* maps) or the preallocated storage is full (definite maps)
*/
-_CBOR_NODISCARD CBOR_EXPORT bool cbor_map_add(cbor_item_t *item,
+_CBOR_NODISCARD CBOR_EXPORT bool cbor_map_add(cbor_item_t* item,
struct cbor_pair pair);
/** Add a key to the map
@@ -75,8 +75,8 @@ _CBOR_NODISCARD CBOR_EXPORT bool cbor_map_add(cbor_item_t *item,
* @return `true` on success, `false` if either reallocation failed or the
* preallocated storage is full
*/
-_CBOR_NODISCARD CBOR_EXPORT bool _cbor_map_add_key(cbor_item_t *item,
- cbor_item_t *key);
+_CBOR_NODISCARD CBOR_EXPORT bool _cbor_map_add_key(cbor_item_t* item,
+ cbor_item_t* key);
/** Add a value to the map
*
@@ -87,15 +87,15 @@ _CBOR_NODISCARD CBOR_EXPORT bool _cbor_map_add_key(cbor_item_t *item,
* @return `true` on success, `false` if either reallocation failed or the
* preallocated storage is full
*/
-_CBOR_NODISCARD CBOR_EXPORT bool _cbor_map_add_value(cbor_item_t *item,
- cbor_item_t *value);
+_CBOR_NODISCARD CBOR_EXPORT bool _cbor_map_add_value(cbor_item_t* item,
+ cbor_item_t* value);
/** Is this map definite?
*
* @param item A map
* @return Is this map definite?
*/
-_CBOR_NODISCARD CBOR_EXPORT bool cbor_map_is_definite(const cbor_item_t *item);
+_CBOR_NODISCARD CBOR_EXPORT bool cbor_map_is_definite(const cbor_item_t* item);
/** Is this map indefinite?
*
@@ -103,7 +103,7 @@ _CBOR_NODISCARD CBOR_EXPORT bool cbor_map_is_definite(const cbor_item_t *item);
* @return Is this map indefinite?
*/
_CBOR_NODISCARD CBOR_EXPORT bool cbor_map_is_indefinite(
- const cbor_item_t *item);
+ const cbor_item_t* item);
/** Get the pairs storage
*
@@ -111,8 +111,8 @@ _CBOR_NODISCARD CBOR_EXPORT bool cbor_map_is_indefinite(
* @return Array of #cbor_map_size pairs. Manipulation is possible as long as
* references remain valid.
*/
-_CBOR_NODISCARD CBOR_EXPORT struct cbor_pair *cbor_map_handle(
- const cbor_item_t *item);
+_CBOR_NODISCARD CBOR_EXPORT struct cbor_pair* cbor_map_handle(
+ const cbor_item_t* item);
#ifdef __cplusplus
}
diff --git a/src/cbor/serialization.c b/src/cbor/serialization.c
index 40f4c531d575..dbfc8c371382 100644
--- a/src/cbor/serialization.c
+++ b/src/cbor/serialization.c
@@ -17,9 +17,8 @@
#include "encoding.h"
#include "internal/memory_utils.h"
-size_t cbor_serialize(const cbor_item_t *item, unsigned char *buffer,
+size_t cbor_serialize(const cbor_item_t* item, unsigned char* buffer,
size_t buffer_size) {
- // cppcheck-suppress missingReturn
switch (cbor_typeof(item)) {
case CBOR_TYPE_UINT:
return cbor_serialize_uint(item, buffer, buffer_size);
@@ -37,6 +36,9 @@ size_t cbor_serialize(const cbor_item_t *item, unsigned char *buffer,
return cbor_serialize_tag(item, buffer, buffer_size);
case CBOR_TYPE_FLOAT_CTRL:
return cbor_serialize_float_ctrl(item, buffer, buffer_size);
+ default:
+ _CBOR_UNREACHABLE;
+ return 0;
}
}
@@ -58,8 +60,7 @@ size_t _cbor_encoded_header_size(uint64_t size) {
return 9;
}
-size_t cbor_serialized_size(const cbor_item_t *item) {
- // cppcheck-suppress missingReturn
+size_t cbor_serialized_size(const cbor_item_t* item) {
switch (cbor_typeof(item)) {
case CBOR_TYPE_UINT:
case CBOR_TYPE_NEGINT:
@@ -73,6 +74,9 @@ size_t cbor_serialized_size(const cbor_item_t *item) {
return 5;
case CBOR_INT_64:
return 9;
+ default:
+ _CBOR_UNREACHABLE;
+ return 0;
}
// Note: We do not _cbor_safe_signaling_add zero-length definite strings,
// they would cause zeroes to propagate. All other items are at least one
@@ -86,7 +90,7 @@ size_t cbor_serialized_size(const cbor_item_t *item) {
cbor_bytestring_length(item));
}
size_t indef_bytestring_size = 2; // Leading byte + break
- cbor_item_t **chunks = cbor_bytestring_chunks_handle(item);
+ cbor_item_t** chunks = cbor_bytestring_chunks_handle(item);
for (size_t i = 0; i < cbor_bytestring_chunk_count(item); i++) {
indef_bytestring_size = _cbor_safe_signaling_add(
indef_bytestring_size, cbor_serialized_size(chunks[i]));
@@ -101,7 +105,7 @@ size_t cbor_serialized_size(const cbor_item_t *item) {
return _cbor_safe_signaling_add(header_size, cbor_string_length(item));
}
size_t indef_string_size = 2; // Leading byte + break
- cbor_item_t **chunks = cbor_string_chunks_handle(item);
+ cbor_item_t** chunks = cbor_string_chunks_handle(item);
for (size_t i = 0; i < cbor_string_chunk_count(item); i++) {
indef_string_size = _cbor_safe_signaling_add(
indef_string_size, cbor_serialized_size(chunks[i]));
@@ -112,7 +116,7 @@ size_t cbor_serialized_size(const cbor_item_t *item) {
size_t array_size = cbor_array_is_definite(item)
? _cbor_encoded_header_size(cbor_array_size(item))
: 2; // Leading byte + break
- cbor_item_t **items = cbor_array_handle(item);
+ cbor_item_t** items = cbor_array_handle(item);
for (size_t i = 0; i < cbor_array_size(item); i++) {
array_size = _cbor_safe_signaling_add(array_size,
cbor_serialized_size(items[i]));
@@ -123,7 +127,7 @@ size_t cbor_serialized_size(const cbor_item_t *item) {
size_t map_size = cbor_map_is_definite(item)
? _cbor_encoded_header_size(cbor_map_size(item))
: 2; // Leading byte + break
- struct cbor_pair *items = cbor_map_handle(item);
+ struct cbor_pair* items = cbor_map_handle(item);
for (size_t i = 0; i < cbor_map_size(item); i++) {
map_size = _cbor_safe_signaling_add(
map_size,
@@ -147,12 +151,18 @@ size_t cbor_serialized_size(const cbor_item_t *item) {
return 5;
case CBOR_FLOAT_64:
return 9;
+ default:
+ _CBOR_UNREACHABLE;
+ return 0;
}
+ default:
+ _CBOR_UNREACHABLE;
+ return 0;
}
}
-size_t cbor_serialize_alloc(const cbor_item_t *item, unsigned char **buffer,
- size_t *buffer_size) {
+size_t cbor_serialize_alloc(const cbor_item_t* item, unsigned char** buffer,
+ size_t* buffer_size) {
*buffer = NULL;
size_t serialized_size = cbor_serialized_size(item);
if (serialized_size == 0) {
@@ -171,7 +181,7 @@ size_t cbor_serialize_alloc(const cbor_item_t *item, unsigned char **buffer,
return written;
}
-size_t cbor_serialize_uint(const cbor_item_t *item, unsigned char *buffer,
+size_t cbor_serialize_uint(const cbor_item_t* item, unsigned char* buffer,
size_t buffer_size) {
CBOR_ASSERT(cbor_isa_uint(item));
// cppcheck-suppress missingReturn
@@ -184,10 +194,13 @@ size_t cbor_serialize_uint(const cbor_item_t *item, unsigned char *buffer,
return cbor_encode_uint32(cbor_get_uint32(item), buffer, buffer_size);
case CBOR_INT_64:
return cbor_encode_uint64(cbor_get_uint64(item), buffer, buffer_size);
+ default:
+ _CBOR_UNREACHABLE;
+ return 0;
}
}
-size_t cbor_serialize_negint(const cbor_item_t *item, unsigned char *buffer,
+size_t cbor_serialize_negint(const cbor_item_t* item, unsigned char* buffer,
size_t buffer_size) {
CBOR_ASSERT(cbor_isa_negint(item));
// cppcheck-suppress missingReturn
@@ -200,10 +213,13 @@ size_t cbor_serialize_negint(const cbor_item_t *item, unsigned char *buffer,
return cbor_encode_negint32(cbor_get_uint32(item), buffer, buffer_size);
case CBOR_INT_64:
return cbor_encode_negint64(cbor_get_uint64(item), buffer, buffer_size);
+ default:
+ _CBOR_UNREACHABLE;
+ return 0;
}
}
-size_t cbor_serialize_bytestring(const cbor_item_t *item, unsigned char *buffer,
+size_t cbor_serialize_bytestring(const cbor_item_t* item, unsigned char* buffer,
size_t buffer_size) {
CBOR_ASSERT(cbor_isa_bytestring(item));
if (cbor_bytestring_is_definite(item)) {
@@ -220,7 +236,7 @@ size_t cbor_serialize_bytestring(const cbor_item_t *item, unsigned char *buffer,
size_t written = cbor_encode_indef_bytestring_start(buffer, buffer_size);
if (written == 0) return 0;
- cbor_item_t **chunks = cbor_bytestring_chunks_handle(item);
+ cbor_item_t** chunks = cbor_bytestring_chunks_handle(item);
for (size_t i = 0; i < chunk_count; i++) {
size_t chunk_written = cbor_serialize_bytestring(
chunks[i], buffer + written, buffer_size - written);
@@ -235,7 +251,7 @@ size_t cbor_serialize_bytestring(const cbor_item_t *item, unsigned char *buffer,
}
}
-size_t cbor_serialize_string(const cbor_item_t *item, unsigned char *buffer,
+size_t cbor_serialize_string(const cbor_item_t* item, unsigned char* buffer,
size_t buffer_size) {
CBOR_ASSERT(cbor_isa_string(item));
if (cbor_string_is_definite(item)) {
@@ -252,7 +268,7 @@ size_t cbor_serialize_string(const cbor_item_t *item, unsigned char *buffer,
size_t written = cbor_encode_indef_string_start(buffer, buffer_size);
if (written == 0) return 0;
- cbor_item_t **chunks = cbor_string_chunks_handle(item);
+ cbor_item_t** chunks = cbor_string_chunks_handle(item);
for (size_t i = 0; i < chunk_count; i++) {
size_t chunk_written = cbor_serialize_string(chunks[i], buffer + written,
buffer_size - written);
@@ -267,11 +283,11 @@ size_t cbor_serialize_string(const cbor_item_t *item, unsigned char *buffer,
}
}
-size_t cbor_serialize_array(const cbor_item_t *item, unsigned char *buffer,
+size_t cbor_serialize_array(const cbor_item_t* item, unsigned char* buffer,
size_t buffer_size) {
CBOR_ASSERT(cbor_isa_array(item));
size_t size = cbor_array_size(item), written = 0;
- cbor_item_t **handle = cbor_array_handle(item);
+ cbor_item_t** handle = cbor_array_handle(item);
if (cbor_array_is_definite(item)) {
written = cbor_encode_array_start(size, buffer, buffer_size);
} else {
@@ -298,11 +314,11 @@ size_t cbor_serialize_array(const cbor_item_t *item, unsigned char *buffer,
}
}
-size_t cbor_serialize_map(const cbor_item_t *item, unsigned char *buffer,
+size_t cbor_serialize_map(const cbor_item_t* item, unsigned char* buffer,
size_t buffer_size) {
CBOR_ASSERT(cbor_isa_map(item));
size_t size = cbor_map_size(item), written = 0;
- struct cbor_pair *handle = cbor_map_handle(item);
+ struct cbor_pair* handle = cbor_map_handle(item);
if (cbor_map_is_definite(item)) {
written = cbor_encode_map_start(size, buffer, buffer_size);
@@ -336,7 +352,7 @@ size_t cbor_serialize_map(const cbor_item_t *item, unsigned char *buffer,
}
}
-size_t cbor_serialize_tag(const cbor_item_t *item, unsigned char *buffer,
+size_t cbor_serialize_tag(const cbor_item_t* item, unsigned char* buffer,
size_t buffer_size) {
CBOR_ASSERT(cbor_isa_tag(item));
size_t written = cbor_encode_tag(cbor_tag_value(item), buffer, buffer_size);
@@ -348,7 +364,7 @@ size_t cbor_serialize_tag(const cbor_item_t *item, unsigned char *buffer,
return written + item_written;
}
-size_t cbor_serialize_float_ctrl(const cbor_item_t *item, unsigned char *buffer,
+size_t cbor_serialize_float_ctrl(const cbor_item_t* item, unsigned char* buffer,
size_t buffer_size) {
CBOR_ASSERT(cbor_isa_float_ctrl(item));
// cppcheck-suppress missingReturn
@@ -364,5 +380,8 @@ size_t cbor_serialize_float_ctrl(const cbor_item_t *item, unsigned char *buffer,
case CBOR_FLOAT_64:
return cbor_encode_double(cbor_float_get_float8(item), buffer,
buffer_size);
+ default:
+ _CBOR_UNREACHABLE;
+ return 0;
}
}
diff --git a/src/cbor/serialization.h b/src/cbor/serialization.h
index 228ae75d6011..10f5784a5b2f 100644
--- a/src/cbor/serialization.h
+++ b/src/cbor/serialization.h
@@ -28,7 +28,7 @@ extern "C" {
* @param buffer_size Size of the \p buffer
* @return Length of the result. 0 on failure.
*/
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_serialize(const cbor_item_t *item,
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_serialize(const cbor_item_t* item,
cbor_mutable_data buffer,
size_t buffer_size);
@@ -42,7 +42,7 @@ _CBOR_NODISCARD CBOR_EXPORT size_t cbor_serialize(const cbor_item_t *item,
* `size_t`.
*/
_CBOR_NODISCARD CBOR_EXPORT size_t
-cbor_serialized_size(const cbor_item_t *item);
+cbor_serialized_size(const cbor_item_t* item);
/** Serialize the given item, allocating buffers as needed
*
@@ -62,9 +62,9 @@ cbor_serialized_size(const cbor_item_t *item);
* @return Length of the result in bytes
* @return 0 on memory allocation failure, in which case \p buffer is `NULL`.
*/
-CBOR_EXPORT size_t cbor_serialize_alloc(const cbor_item_t *item,
- unsigned char **buffer,
- size_t *buffer_size);
+CBOR_EXPORT size_t cbor_serialize_alloc(const cbor_item_t* item,
+ unsigned char** buffer,
+ size_t* buffer_size);
/** Serialize an uint
*
@@ -74,7 +74,7 @@ CBOR_EXPORT size_t cbor_serialize_alloc(const cbor_item_t *item,
* @return Length of the result
* @return 0 if the \p buffer_size doesn't fit the result
*/
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_serialize_uint(const cbor_item_t *item,
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_serialize_uint(const cbor_item_t* item,
cbor_mutable_data buffer,
size_t buffer_size);
@@ -87,7 +87,7 @@ _CBOR_NODISCARD CBOR_EXPORT size_t cbor_serialize_uint(const cbor_item_t *item,
* @return 0 if the \p buffer_size doesn't fit the result
*/
_CBOR_NODISCARD CBOR_EXPORT size_t cbor_serialize_negint(
- const cbor_item_t *item, cbor_mutable_data buffer, size_t buffer_size);
+ const cbor_item_t* item, cbor_mutable_data buffer, size_t buffer_size);
/** Serialize a bytestring
*
@@ -99,7 +99,7 @@ _CBOR_NODISCARD CBOR_EXPORT size_t cbor_serialize_negint(
* still be modified
*/
_CBOR_NODISCARD CBOR_EXPORT size_t cbor_serialize_bytestring(
- const cbor_item_t *item, cbor_mutable_data buffer, size_t buffer_size);
+ const cbor_item_t* item, cbor_mutable_data buffer, size_t buffer_size);
/** Serialize a string
*
@@ -111,7 +111,7 @@ _CBOR_NODISCARD CBOR_EXPORT size_t cbor_serialize_bytestring(
* still be modified
*/
_CBOR_NODISCARD CBOR_EXPORT size_t cbor_serialize_string(
- const cbor_item_t *item, cbor_mutable_data buffer, size_t buffer_size);
+ const cbor_item_t* item, cbor_mutable_data buffer, size_t buffer_size);
/** Serialize an array
*
* @param item An array
@@ -122,7 +122,7 @@ _CBOR_NODISCARD CBOR_EXPORT size_t cbor_serialize_string(
* still be modified
*/
_CBOR_NODISCARD CBOR_EXPORT size_t cbor_serialize_array(
- const cbor_item_t *item, cbor_mutable_data buffer, size_t buffer_size);
+ const cbor_item_t* item, cbor_mutable_data buffer, size_t buffer_size);
/** Serialize a map
*
@@ -133,7 +133,7 @@ _CBOR_NODISCARD CBOR_EXPORT size_t cbor_serialize_array(
* @return 0 if the \p buffer_size doesn't fit the result. The \p buffer may
* still be modified
*/
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_serialize_map(const cbor_item_t *item,
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_serialize_map(const cbor_item_t* item,
cbor_mutable_data buffer,
size_t buffer_size);
@@ -146,7 +146,7 @@ _CBOR_NODISCARD CBOR_EXPORT size_t cbor_serialize_map(const cbor_item_t *item,
* @return 0 if the \p buffer_size doesn't fit the result. The \p buffer may
* still be modified
*/
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_serialize_tag(const cbor_item_t *item,
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_serialize_tag(const cbor_item_t* item,
cbor_mutable_data buffer,
size_t buffer_size);
@@ -159,7 +159,7 @@ _CBOR_NODISCARD CBOR_EXPORT size_t cbor_serialize_tag(const cbor_item_t *item,
* @return 0 if the \p buffer_size doesn't fit the result
*/
_CBOR_NODISCARD CBOR_EXPORT size_t cbor_serialize_float_ctrl(
- const cbor_item_t *item, cbor_mutable_data buffer, size_t buffer_size);
+ const cbor_item_t* item, cbor_mutable_data buffer, size_t buffer_size);
#ifdef __cplusplus
}
diff --git a/src/cbor/streaming.c b/src/cbor/streaming.c
index 4b37701143ab..595c85805f19 100644
--- a/src/cbor/streaming.c
+++ b/src/cbor/streaming.c
@@ -9,7 +9,7 @@
#include "internal/loaders.h"
static bool claim_bytes(size_t required, size_t provided,
- struct cbor_decoder_result *result) {
+ struct cbor_decoder_result* result) {
if (required > (provided - result->read)) {
result->required = required + result->read;
result->read = 0;
@@ -42,7 +42,7 @@ static bool claim_bytes(size_t required, size_t provided,
struct cbor_decoder_result cbor_stream_decode(
cbor_data source, size_t source_size,
- const struct cbor_callbacks *callbacks, void *context) {
+ const struct cbor_callbacks* callbacks, void* context) {
// Attempt to claim the initial MTB byte
struct cbor_decoder_result result = {.status = CBOR_DECODER_FINISHED};
if (!claim_bytes(1, source_size, &result)) {
@@ -592,9 +592,10 @@ struct cbor_decoder_result cbor_stream_decode(
case 0xFF:
/* Break */
callbacks->indef_break(context);
- // Never happens, the switch statement is exhaustive on the 1B range; make
- // compiler happy
+ return result;
default:
+ // Never happens, the switch statement is exhaustive on the 1B range
+ _CBOR_UNREACHABLE;
return result;
}
}
diff --git a/src/cbor/strings.c b/src/cbor/strings.c
index 6ae96545cfe3..4ef4fa3c9b73 100644
--- a/src/cbor/strings.c
+++ b/src/cbor/strings.c
@@ -10,18 +10,20 @@
#include "internal/memory_utils.h"
#include "internal/unicode.h"
-cbor_item_t *cbor_new_definite_string(void) {
- cbor_item_t *item = _cbor_malloc(sizeof(cbor_item_t));
+cbor_item_t* cbor_new_definite_string(void) {
+ cbor_item_t* item = _cbor_malloc(sizeof(cbor_item_t));
_CBOR_NOTNULL(item);
*item = (cbor_item_t){
.refcount = 1,
.type = CBOR_TYPE_STRING,
- .metadata = {.string_metadata = {_CBOR_METADATA_DEFINITE, 0}}};
+ .metadata = {.string_metadata = {.type = _CBOR_METADATA_DEFINITE,
+ .codepoint_count = 0,
+ .length = 0}}};
return item;
}
-cbor_item_t *cbor_new_indefinite_string(void) {
- cbor_item_t *item = _cbor_malloc(sizeof(cbor_item_t));
+cbor_item_t* cbor_new_indefinite_string(void) {
+ cbor_item_t* item = _cbor_malloc(sizeof(cbor_item_t));
_CBOR_NOTNULL(item);
*item = (cbor_item_t){
.refcount = 1,
@@ -30,7 +32,7 @@ cbor_item_t *cbor_new_indefinite_string(void) {
.length = 0}},
.data = _cbor_malloc(sizeof(struct cbor_indefinite_string_data))};
_CBOR_DEPENDENT_NOTNULL(item, item->data);
- *((struct cbor_indefinite_string_data *)item->data) =
+ *((struct cbor_indefinite_string_data*)item->data) =
(struct cbor_indefinite_string_data){
.chunk_count = 0,
.chunk_capacity = 0,
@@ -39,28 +41,28 @@ cbor_item_t *cbor_new_indefinite_string(void) {
return item;
}
-cbor_item_t *cbor_build_string(const char *val) {
- cbor_item_t *item = cbor_new_definite_string();
+cbor_item_t* cbor_build_string(const char* val) {
+ cbor_item_t* item = cbor_new_definite_string();
_CBOR_NOTNULL(item);
size_t len = strlen(val);
- unsigned char *handle = _cbor_malloc(len);
+ unsigned char* handle = _cbor_malloc(len);
_CBOR_DEPENDENT_NOTNULL(item, handle);
memcpy(handle, val, len);
cbor_string_set_handle(item, handle, len);
return item;
}
-cbor_item_t *cbor_build_stringn(const char *val, size_t length) {
- cbor_item_t *item = cbor_new_definite_string();
+cbor_item_t* cbor_build_stringn(const char* val, size_t length) {
+ cbor_item_t* item = cbor_new_definite_string();
_CBOR_NOTNULL(item);
- unsigned char *handle = _cbor_malloc(length);
+ unsigned char* handle = _cbor_malloc(length);
_CBOR_DEPENDENT_NOTNULL(item, handle);
memcpy(handle, val, length);
cbor_string_set_handle(item, handle, length);
return item;
}
-void cbor_string_set_handle(cbor_item_t *item,
+void cbor_string_set_handle(cbor_item_t* item,
cbor_mutable_data CBOR_RESTRICT_POINTER data,
size_t length) {
CBOR_ASSERT(cbor_isa_string(item));
@@ -78,23 +80,23 @@ void cbor_string_set_handle(cbor_item_t *item,
}
}
-cbor_item_t **cbor_string_chunks_handle(const cbor_item_t *item) {
+cbor_item_t** cbor_string_chunks_handle(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_string(item));
CBOR_ASSERT(cbor_string_is_indefinite(item));
- return ((struct cbor_indefinite_string_data *)item->data)->chunks;
+ return ((struct cbor_indefinite_string_data*)item->data)->chunks;
}
-size_t cbor_string_chunk_count(const cbor_item_t *item) {
+size_t cbor_string_chunk_count(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_string(item));
CBOR_ASSERT(cbor_string_is_indefinite(item));
- return ((struct cbor_indefinite_string_data *)item->data)->chunk_count;
+ return ((struct cbor_indefinite_string_data*)item->data)->chunk_count;
}
-bool cbor_string_add_chunk(cbor_item_t *item, cbor_item_t *chunk) {
+bool cbor_string_add_chunk(cbor_item_t* item, cbor_item_t* chunk) {
CBOR_ASSERT(cbor_isa_string(item));
CBOR_ASSERT(cbor_string_is_indefinite(item));
- struct cbor_indefinite_string_data *data =
- (struct cbor_indefinite_string_data *)item->data;
+ struct cbor_indefinite_string_data* data =
+ (struct cbor_indefinite_string_data*)item->data;
if (data->chunk_count == data->chunk_capacity) {
if (!_cbor_safe_to_multiply(CBOR_BUFFER_GROWTH, data->chunk_capacity)) {
return false;
@@ -103,8 +105,8 @@ bool cbor_string_add_chunk(cbor_item_t *item, cbor_item_t *chunk) {
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);
+ cbor_item_t** new_chunks_data = _cbor_realloc_multiple(
+ data->chunks, sizeof(cbor_item_t*), new_chunk_capacity);
if (new_chunks_data == NULL) {
return false;
@@ -117,26 +119,26 @@ bool cbor_string_add_chunk(cbor_item_t *item, cbor_item_t *chunk) {
return true;
}
-size_t cbor_string_length(const cbor_item_t *item) {
+size_t cbor_string_length(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_string(item));
return item->metadata.string_metadata.length;
}
-unsigned char *cbor_string_handle(const cbor_item_t *item) {
+unsigned char* cbor_string_handle(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_string(item));
return item->data;
}
-size_t cbor_string_codepoint_count(const cbor_item_t *item) {
+size_t cbor_string_codepoint_count(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_string(item));
return item->metadata.string_metadata.codepoint_count;
}
-bool cbor_string_is_definite(const cbor_item_t *item) {
+bool cbor_string_is_definite(const cbor_item_t* item) {
CBOR_ASSERT(cbor_isa_string(item));
return item->metadata.string_metadata.type == _CBOR_METADATA_DEFINITE;
}
-bool cbor_string_is_indefinite(const cbor_item_t *item) {
+bool cbor_string_is_indefinite(const cbor_item_t* item) {
return !cbor_string_is_definite(item);
}
diff --git a/src/cbor/strings.h b/src/cbor/strings.h
index 3e03f81385f0..a21133b30129 100644
--- a/src/cbor/strings.h
+++ b/src/cbor/strings.h
@@ -29,7 +29,7 @@ extern "C" {
* @param item a definite string
* @return length of the string. Zero if no chunk has been attached yet
*/
-_CBOR_NODISCARD CBOR_EXPORT size_t cbor_string_length(const cbor_item_t *item);
+_CBOR_NODISCARD CBOR_EXPORT size_t cbor_string_length(const cbor_item_t* item);
/** The number of codepoints in this string
*
@@ -40,7 +40,7 @@ _CBOR_NODISCARD CBOR_EXPORT size_t cbor_string_length(const cbor_item_t *item);
* @return The number of codepoints in this string
*/
_CBOR_NODISCARD CBOR_EXPORT size_t
-cbor_string_codepoint_count(const cbor_item_t *item);
+cbor_string_codepoint_count(const cbor_item_t* item);
/** Is the string definite?
*
@@ -48,7 +48,7 @@ cbor_string_codepoint_count(const cbor_item_t *item);
* @return Is the string definite?
*/
_CBOR_NODISCARD CBOR_EXPORT bool cbor_string_is_definite(
- const cbor_item_t *item);
+ const cbor_item_t* item);
/** Is the string indefinite?
*
@@ -56,7 +56,7 @@ _CBOR_NODISCARD CBOR_EXPORT bool cbor_string_is_definite(
* @return Is the string indefinite?
*/
_CBOR_NODISCARD CBOR_EXPORT bool cbor_string_is_indefinite(
- const cbor_item_t *item);
+ const cbor_item_t* item);
/** Get the handle to the underlying string
*
@@ -68,7 +68,7 @@ _CBOR_NODISCARD CBOR_EXPORT bool cbor_string_is_indefinite(
* @return `NULL` if no data have been assigned yet.
*/
_CBOR_NODISCARD CBOR_EXPORT cbor_mutable_data
-cbor_string_handle(const cbor_item_t *item);
+cbor_string_handle(const cbor_item_t* item);
/** Set the handle to the underlying string
*
@@ -87,7 +87,7 @@ cbor_string_handle(const cbor_item_t *item);
* @param length Length of the data block
*/
CBOR_EXPORT void cbor_string_set_handle(
- cbor_item_t *item, cbor_mutable_data CBOR_RESTRICT_POINTER data,
+ cbor_item_t* item, cbor_mutable_data CBOR_RESTRICT_POINTER data,
size_t length);
/** Get the handle to the array of chunks
@@ -98,8 +98,8 @@ CBOR_EXPORT void cbor_string_set_handle(
* @param item A indefinite string
* @return array of #cbor_string_chunk_count definite strings
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t **cbor_string_chunks_handle(
- const cbor_item_t *item);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t** cbor_string_chunks_handle(
+ const cbor_item_t* item);
/** Get the number of chunks this string consist of
*
@@ -107,7 +107,7 @@ _CBOR_NODISCARD CBOR_EXPORT cbor_item_t **cbor_string_chunks_handle(
* @return The chunk count. 0 for freshly created items.
*/
_CBOR_NODISCARD CBOR_EXPORT size_t
-cbor_string_chunk_count(const cbor_item_t *item);
+cbor_string_chunk_count(const cbor_item_t* item);
/** Appends a chunk to the string
*
@@ -122,8 +122,8 @@ cbor_string_chunk_count(const cbor_item_t *item);
* case, the refcount of @p `chunk` is not increased and the @p `item` is left
* intact.
*/
-_CBOR_NODISCARD CBOR_EXPORT bool cbor_string_add_chunk(cbor_item_t *item,
- cbor_item_t *chunk);
+_CBOR_NODISCARD CBOR_EXPORT bool cbor_string_add_chunk(cbor_item_t* item,
+ cbor_item_t* chunk);
/** Creates a new definite string
*
@@ -133,7 +133,7 @@ _CBOR_NODISCARD CBOR_EXPORT bool cbor_string_add_chunk(cbor_item_t *item,
* initialized to one.
* @return `NULL` if memory allocation fails
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_definite_string(void);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_new_definite_string(void);
/** Creates a new indefinite string
*
@@ -143,7 +143,7 @@ _CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_definite_string(void);
* initialized to one.
* @return `NULL` if memory allocation fails
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_indefinite_string(void);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_new_indefinite_string(void);
/** Creates a new string and initializes it
*
@@ -158,7 +158,7 @@ _CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_indefinite_string(void);
* initialized to one.
* @return `NULL` if memory allocation fails
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_build_string(const char *val);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_build_string(const char* val);
/** Creates a new string and initializes it
*
@@ -173,7 +173,7 @@ _CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_build_string(const char *val);
* initialized to one.
* @return `NULL` if memory allocation fails
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_build_stringn(const char *val,
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_build_stringn(const char* val,
size_t length);
#ifdef __cplusplus
diff --git a/src/cbor/tags.c b/src/cbor/tags.c
index 3f3edb0b0e1d..343a1cda5603 100644
--- a/src/cbor/tags.c
+++ b/src/cbor/tags.c
@@ -7,8 +7,8 @@
#include "tags.h"
-cbor_item_t *cbor_new_tag(uint64_t value) {
- cbor_item_t *item = _cbor_malloc(sizeof(cbor_item_t));
+cbor_item_t* cbor_new_tag(uint64_t value) {
+ cbor_item_t* item = _cbor_malloc(sizeof(cbor_item_t));
_CBOR_NOTNULL(item);
*item = (cbor_item_t){
@@ -20,24 +20,24 @@ cbor_item_t *cbor_new_tag(uint64_t value) {
return item;
}
-cbor_item_t *cbor_tag_item(const cbor_item_t *item) {
- CBOR_ASSERT(cbor_isa_tag(item));
- return cbor_incref(item->metadata.tag_metadata.tagged_item);
+cbor_item_t* cbor_tag_item(const cbor_item_t* tag) {
+ CBOR_ASSERT(cbor_isa_tag(tag));
+ return cbor_incref(tag->metadata.tag_metadata.tagged_item);
}
-uint64_t cbor_tag_value(const cbor_item_t *item) {
- CBOR_ASSERT(cbor_isa_tag(item));
- return item->metadata.tag_metadata.value;
+uint64_t cbor_tag_value(const cbor_item_t* tag) {
+ CBOR_ASSERT(cbor_isa_tag(tag));
+ return tag->metadata.tag_metadata.value;
}
-void cbor_tag_set_item(cbor_item_t *item, cbor_item_t *tagged_item) {
- CBOR_ASSERT(cbor_isa_tag(item));
+void cbor_tag_set_item(cbor_item_t* tag, cbor_item_t* tagged_item) {
+ CBOR_ASSERT(cbor_isa_tag(tag));
cbor_incref(tagged_item);
- item->metadata.tag_metadata.tagged_item = tagged_item;
+ tag->metadata.tag_metadata.tagged_item = tagged_item;
}
-cbor_item_t *cbor_build_tag(uint64_t value, cbor_item_t *item) {
- cbor_item_t *res = cbor_new_tag(value);
+cbor_item_t* cbor_build_tag(uint64_t value, cbor_item_t* item) {
+ cbor_item_t* res = cbor_new_tag(value);
if (res == NULL) {
return NULL;
}
diff --git a/src/cbor/tags.h b/src/cbor/tags.h
index a7365df10208..360cc861a53f 100644
--- a/src/cbor/tags.h
+++ b/src/cbor/tags.h
@@ -21,51 +21,55 @@ extern "C" {
* ============================================================================
*/
-/** Create a new tag
+/** Create a new tag.
*
- * @param value The tag value. Please consult the tag repository
- * @return Reference to the new tag item. The item's reference count is
- * initialized to one.
- * @return `NULL` if memory allocation fails
+ * @param value The tag value (number).
+ * @return Reference to the new tag. Its reference count is initialized to one
+ * and it points to a `NULL` item.
+ * @return `NULL` if memory allocation fails.
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_tag(uint64_t value);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_new_tag(uint64_t value);
-/** Get the tagged item
+/** Get the tagged item (what the tag points to).
*
- * @param item A tag
- * @return Reference to the tagged item
+ * @param tag A #CBOR_TYPE_TAG tag.
+ * @return Reference to the tagged item.
*
* Increases the reference count of the underlying item. The returned reference
* must be released using #cbor_decref.
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_tag_item(const cbor_item_t *item);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_tag_item(const cbor_item_t* tag);
-/** Get tag value
+/** Get the tag value.
*
- * @param item A tag
- * @return The tag value. Please consult the tag repository
+ * @param tag A #CBOR_TYPE_TAG tag.
+ * @return The tag value (number).
*/
-_CBOR_NODISCARD CBOR_EXPORT uint64_t cbor_tag_value(const cbor_item_t *item);
+_CBOR_NODISCARD CBOR_EXPORT uint64_t cbor_tag_value(const cbor_item_t* tag);
-/** Set the tagged item
+/** Assign a tag to an item.
*
- * @param item A tag
+ * @param tag A #CBOR_TYPE_TAG tag.
* @param tagged_item The item to tag. Its reference count will be increased
* by one.
+ *
+ * If the tag already points to an item, the pointer will be replaced, without a
+ * reference count change on the previous item.
+ * TODO: Should we release the reference automatically?
*/
-CBOR_EXPORT void cbor_tag_set_item(cbor_item_t *item, cbor_item_t *tagged_item);
+CBOR_EXPORT void cbor_tag_set_item(cbor_item_t* tag, cbor_item_t* tagged_item);
-/** Build a new tag
+/** Build a new tag.
*
* @param item The item to tag. Its reference count will be increased by
* one.
- * @param value Tag value
+ * @param value The tag value (number).
* @return Reference to the new tag item. The item's reference count is
* initialized to one.
- * @return `NULL` if memory allocation fails
+ * @return `NULL` if memory allocation fails.
*/
-_CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_build_tag(uint64_t value,
- cbor_item_t *item);
+_CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_build_tag(uint64_t value,
+ cbor_item_t* item);
#ifdef __cplusplus
}
diff --git a/src/libcborConfig.cmake.in b/src/libcborConfig.cmake.in
index 565bed365e24..5c8095c9d4bf 100644
--- a/src/libcborConfig.cmake.in
+++ b/src/libcborConfig.cmake.in
@@ -2,6 +2,9 @@ set(CBOR_VERSION @CBOR_VERSION@)
@PACKAGE_INIT@
+include("${CMAKE_CURRENT_LIST_DIR}/libcborTargets.cmake")
+
+# legacy
set_and_check(CBOR_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
set_and_check(CBOR_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 9721fd03a166..626266aeba90 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -6,26 +6,22 @@ message(STATUS "CMocka vars: ${CMOCKA_LIBRARIES} ${CMOCKA_INCLUDE_DIR}")
find_library(MATH_LIBRARY m)
-CHECK_INCLUDE_FILE("execinfo.h" HAS_EXECINFO)
+check_include_file("execinfo.h" HAS_EXECINFO)
-foreach (TEST ${TESTS})
- string(REGEX REPLACE ".*/([^/]+).c" "\\1" NAME ${TEST})
- message("Adding test ${NAME}")
- add_executable(${NAME} "${NAME}.c" assertions.c stream_expectations.c test_allocator.c)
- target_link_libraries(${NAME} ${CMOCKA_LIBRARIES})
- target_link_libraries(${NAME} cbor)
- if(MATH_LIBRARY)
- target_link_libraries(${NAME} ${MATH_LIBRARY})
- endif()
- target_include_directories(${NAME} PUBLIC ${CMOCKA_INCLUDE_DIR})
- # See https://stackoverflow.com/a/10824578/499521
- ADD_TEST(ctest_build_test_${NAME}
- "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target ${NAME})
- ADD_TEST(ctest_run_${NAME} ${NAME})
- SET_TESTS_PROPERTIES(ctest_run_${NAME}
- PROPERTIES DEPENDS ctest_build_test_${NAME})
- add_dependencies(coverage ${NAME})
-endforeach (TEST)
+foreach(test_file ${TESTS})
+ string(REGEX REPLACE ".*/([^/]+).c" "\\1" NAME ${test_file})
+ message("Adding test ${NAME}")
+ add_executable(${NAME} "${NAME}.c" assertions.c stream_expectations.c
+ test_allocator.c)
+ target_link_libraries(${NAME} ${CMOCKA_LIBRARIES})
+ target_link_libraries(${NAME} cbor)
+ if(MATH_LIBRARY)
+ target_link_libraries(${NAME} ${MATH_LIBRARY})
+ endif()
+ target_include_directories(${NAME} PUBLIC ${CMOCKA_INCLUDE_DIR})
+ add_test(NAME ${NAME} COMMAND ${NAME})
+ add_dependencies(coverage ${NAME})
+endforeach()
add_executable(cpp_linkage_test cpp_linkage_test.cpp)
-target_link_libraries(cpp_linkage_test cbor) \ No newline at end of file
+target_link_libraries(cpp_linkage_test cbor)
diff --git a/test/array_encoders_test.c b/test/array_encoders_test.c
index 54a28bd94c6b..baab0d54ff57 100644
--- a/test/array_encoders_test.c
+++ b/test/array_encoders_test.c
@@ -10,27 +10,27 @@
unsigned char buffer[512];
-static void test_embedded_array_start(void **_CBOR_UNUSED(_state)) {
+static void test_embedded_array_start(void** _state _CBOR_UNUSED) {
assert_size_equal(1, cbor_encode_array_start(1, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0x81}), 1);
}
-static void test_array_start(void **_CBOR_UNUSED(_state)) {
+static void test_array_start(void** _state _CBOR_UNUSED) {
assert_size_equal(5, cbor_encode_array_start(1000000, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0x9A, 0x00, 0x0F, 0x42, 0x40}),
5);
}
-static void test_indef_array_start(void **_CBOR_UNUSED(_state)) {
+static void test_indef_array_start(void** _state _CBOR_UNUSED) {
assert_size_equal(1, cbor_encode_indef_array_start(buffer, 512));
assert_size_equal(0, cbor_encode_indef_array_start(buffer, 0));
assert_memory_equal(buffer, ((unsigned char[]){0x9F}), 1);
}
-static void test_indef_array_encoding(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *array = cbor_new_indefinite_array();
- cbor_item_t *one = cbor_build_uint8(1);
- cbor_item_t *two = cbor_build_uint8(2);
+static void test_indef_array_encoding(void** _state _CBOR_UNUSED) {
+ cbor_item_t* array = cbor_new_indefinite_array();
+ cbor_item_t* one = cbor_build_uint8(1);
+ cbor_item_t* two = cbor_build_uint8(2);
assert_true(cbor_array_push(array, one));
assert_true(cbor_array_push(array, two));
diff --git a/test/array_test.c b/test/array_test.c
index 1a241c051f2c..20e51eea6d79 100644
--- a/test/array_test.c
+++ b/test/array_test.c
@@ -9,12 +9,12 @@
#include "cbor.h"
#include "test_allocator.h"
-cbor_item_t *arr;
+cbor_item_t* arr;
struct cbor_load_result res;
unsigned char data1[] = {0x80, 0xFF};
-static void test_empty_array(void **_CBOR_UNUSED(_state)) {
+static void test_empty_array(void** _state _CBOR_UNUSED) {
arr = cbor_load(data1, 2, &res);
assert_non_null(arr);
assert_true(cbor_typeof(arr) == CBOR_TYPE_ARRAY);
@@ -27,7 +27,7 @@ static void test_empty_array(void **_CBOR_UNUSED(_state)) {
unsigned char data2[] = {0x81, 0x01, 0xFF};
-static void test_simple_array(void **_CBOR_UNUSED(_state)) {
+static void test_simple_array(void** _state _CBOR_UNUSED) {
arr = cbor_load(data2, 3, &res);
assert_non_null(arr);
assert_true(cbor_typeof(arr) == CBOR_TYPE_ARRAY);
@@ -37,10 +37,10 @@ static void test_simple_array(void **_CBOR_UNUSED(_state)) {
assert_size_equal(cbor_array_allocated(arr), 1);
/* Check the values */
assert_uint8(cbor_array_handle(arr)[0], 1);
- cbor_item_t *intermediate = cbor_array_get(arr, 0);
+ cbor_item_t* intermediate = cbor_array_get(arr, 0);
assert_uint8(intermediate, 1);
- cbor_item_t *new_val = cbor_build_uint8(10);
+ cbor_item_t* new_val = cbor_build_uint8(10);
assert_false(cbor_array_set(arr, 1, new_val));
assert_false(cbor_array_set(arr, 3, new_val));
cbor_decref(&new_val);
@@ -53,7 +53,7 @@ static void test_simple_array(void **_CBOR_UNUSED(_state)) {
unsigned char data3[] = {0x82, 0x01, 0x81, 0x01, 0xFF};
-static void test_nested_arrays(void **_CBOR_UNUSED(_state)) {
+static void test_nested_arrays(void** _state _CBOR_UNUSED) {
arr = cbor_load(data3, 5, &res);
assert_non_null(arr);
assert_true(cbor_typeof(arr) == CBOR_TYPE_ARRAY);
@@ -63,7 +63,7 @@ static void test_nested_arrays(void **_CBOR_UNUSED(_state)) {
/* Check the values */
assert_uint8(cbor_array_handle(arr)[0], 1);
- cbor_item_t *nested = cbor_array_handle(arr)[1];
+ cbor_item_t* nested = cbor_array_handle(arr)[1];
assert_true(cbor_isa_array(nested));
assert_true(cbor_array_size(nested) == 1);
assert_uint8(cbor_array_handle(nested)[0], 1);
@@ -74,7 +74,7 @@ static void test_nested_arrays(void **_CBOR_UNUSED(_state)) {
unsigned char test_indef_arrays_data[] = {0x9f, 0x01, 0x02, 0xFF};
-static void test_indef_arrays(void **_CBOR_UNUSED(_state)) {
+static void test_indef_arrays(void** _state _CBOR_UNUSED) {
arr = cbor_load(test_indef_arrays_data, 4, &res);
assert_non_null(arr);
assert_true(cbor_typeof(arr) == CBOR_TYPE_ARRAY);
@@ -94,7 +94,7 @@ static void test_indef_arrays(void **_CBOR_UNUSED(_state)) {
unsigned char test_nested_indef_arrays_data[] = {0x9f, 0x01, 0x9f, 0x02,
0xFF, 0x03, 0xFF};
-static void test_nested_indef_arrays(void **_CBOR_UNUSED(_state)) {
+static void test_nested_indef_arrays(void** _state _CBOR_UNUSED) {
arr = cbor_load(test_nested_indef_arrays_data, 7, &res);
assert_non_null(arr);
assert_true(cbor_typeof(arr) == CBOR_TYPE_ARRAY);
@@ -104,7 +104,7 @@ static void test_nested_indef_arrays(void **_CBOR_UNUSED(_state)) {
/* Check the values */
assert_uint8(cbor_array_handle(arr)[0], 1);
- cbor_item_t *nested = cbor_array_handle(arr)[1];
+ cbor_item_t* nested = cbor_array_handle(arr)[1];
assert_true(cbor_isa_array(nested));
assert_true(cbor_array_size(nested) == 1);
assert_uint8(cbor_array_handle(nested)[0], 2);
@@ -113,11 +113,11 @@ static void test_nested_indef_arrays(void **_CBOR_UNUSED(_state)) {
assert_null(arr);
}
-static void test_array_replace(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *array = cbor_new_definite_array(2);
+static void test_array_replace(void** _state _CBOR_UNUSED) {
+ cbor_item_t* array = cbor_new_definite_array(2);
assert_size_equal(cbor_array_size(array), 0);
- cbor_item_t *one = cbor_build_uint8(1);
- cbor_item_t *three = cbor_build_uint8(3);
+ cbor_item_t* one = cbor_build_uint8(1);
+ cbor_item_t* three = cbor_build_uint8(3);
assert_size_equal(cbor_refcount(one), 1);
assert_size_equal(cbor_refcount(three), 1);
@@ -147,11 +147,11 @@ static void test_array_replace(void **_CBOR_UNUSED(_state)) {
cbor_decref(&array);
}
-static void test_array_push_overflow(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *array = cbor_new_indefinite_array();
- cbor_item_t *one = cbor_build_uint8(1);
- struct _cbor_array_metadata *metadata =
- (struct _cbor_array_metadata *)&array->metadata;
+static void test_array_push_overflow(void** _state _CBOR_UNUSED) {
+ cbor_item_t* array = cbor_new_indefinite_array();
+ cbor_item_t* one = cbor_build_uint8(1);
+ struct _cbor_array_metadata* metadata =
+ (struct _cbor_array_metadata*)&array->metadata;
// Pretend we already have a huge block allocated
metadata->allocated = SIZE_MAX;
metadata->end_ptr = SIZE_MAX;
@@ -165,7 +165,7 @@ static void test_array_push_overflow(void **_CBOR_UNUSED(_state)) {
cbor_decref(&array);
}
-static void test_array_creation(void **_CBOR_UNUSED(_state)) {
+static void test_array_creation(void** _state _CBOR_UNUSED) {
WITH_FAILING_MALLOC({ assert_null(cbor_new_definite_array(42)); });
WITH_MOCK_MALLOC({ assert_null(cbor_new_definite_array(42)); }, 2, MALLOC,
MALLOC_FAIL);
@@ -173,11 +173,11 @@ static void test_array_creation(void **_CBOR_UNUSED(_state)) {
WITH_FAILING_MALLOC({ assert_null(cbor_new_indefinite_array()); });
}
-static void test_array_push(void **_CBOR_UNUSED(_state)) {
+static void test_array_push(void** _state _CBOR_UNUSED) {
WITH_MOCK_MALLOC(
{
- cbor_item_t *array = cbor_new_indefinite_array();
- cbor_item_t *string = cbor_build_string("Hello!");
+ cbor_item_t* array = cbor_new_indefinite_array();
+ cbor_item_t* string = cbor_build_string("Hello!");
assert_false(cbor_array_push(array, string));
assert_size_equal(cbor_array_allocated(array), 0);
@@ -191,10 +191,10 @@ static void test_array_push(void **_CBOR_UNUSED(_state)) {
}
static unsigned char simple_indef_array[] = {0x9F, 0x01, 0x02, 0xFF};
-static void test_indef_array_decode(void **_CBOR_UNUSED(_state)) {
+static void test_indef_array_decode(void** _state _CBOR_UNUSED) {
WITH_MOCK_MALLOC(
{
- cbor_item_t *array;
+ cbor_item_t* array;
struct cbor_load_result res;
array = cbor_load(simple_indef_array, 4, &res);
diff --git a/test/bad_inputs_test.c b/test/bad_inputs_test.c
index de7bdab95231..e3cf02f01680 100644
--- a/test/bad_inputs_test.c
+++ b/test/bad_inputs_test.c
@@ -11,12 +11,12 @@
/* These tests verify behavior on interesting randomly generated inputs from the
* fuzzer */
-cbor_item_t *item;
+cbor_item_t* item;
struct cbor_load_result res;
/* Map start + array with embedded length */
unsigned char data1[] = {0xA9, 0x85};
-static void test_1(void **_CBOR_UNUSED(_state)) {
+static void test_1(void** _state _CBOR_UNUSED) {
item = cbor_load(data1, 2, &res);
assert_null(item);
assert_true(res.error.code == CBOR_ERR_NOTENOUGHDATA);
@@ -24,7 +24,7 @@ static void test_1(void **_CBOR_UNUSED(_state)) {
}
unsigned char data2[] = {0x9D};
-static void test_2(void **_CBOR_UNUSED(_state)) {
+static void test_2(void** _state _CBOR_UNUSED) {
item = cbor_load(data2, 1, &res);
assert_null(item);
assert_true(res.error.code == CBOR_ERR_MALFORMATED);
@@ -32,7 +32,7 @@ static void test_2(void **_CBOR_UNUSED(_state)) {
}
unsigned char data3[] = {0xD6};
-static void test_3(void **_CBOR_UNUSED(_state)) {
+static void test_3(void** _state _CBOR_UNUSED) {
item = cbor_load(data3, 1, &res);
assert_null(item);
assert_true(res.error.code == CBOR_ERR_NOTENOUGHDATA);
@@ -41,7 +41,7 @@ static void test_3(void **_CBOR_UNUSED(_state)) {
#ifdef SANE_MALLOC
unsigned char data4[] = {0xBA, 0xC1, 0xE8, 0x3E, 0xE7, 0x20, 0xA8};
-static void test_4(void **_CBOR_UNUSED(_state)) {
+static void test_4(void** _state _CBOR_UNUSED) {
item = cbor_load(data4, 7, &res);
assert_null(item);
assert_true(res.error.code == CBOR_ERR_MEMERROR);
@@ -49,7 +49,7 @@ static void test_4(void **_CBOR_UNUSED(_state)) {
}
unsigned char data5[] = {0x9A, 0xDA, 0x3A, 0xB2, 0x7F, 0x29};
-static void test_5(void **_CBOR_UNUSED(_state)) {
+static void test_5(void** _state _CBOR_UNUSED) {
assert_true(res.error.code == CBOR_ERR_MEMERROR);
item = cbor_load(data5, 6, &res);
assert_null(item);
@@ -59,7 +59,7 @@ static void test_5(void **_CBOR_UNUSED(_state)) {
#endif
unsigned char data6[] = {0x7F, 0x21, 0x4C, 0x02, 0x40};
-static void test_6(void **_CBOR_UNUSED(_state)) {
+static void test_6(void** _state _CBOR_UNUSED) {
item = cbor_load(data6, 5, &res);
assert_null(item);
assert_true(res.error.code == CBOR_ERR_SYNTAXERROR);
@@ -71,7 +71,7 @@ static void test_6(void **_CBOR_UNUSED(_state)) {
* works with 64b sizes */
unsigned char data7[] = {0xA2, 0x9B, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
-static void test_7(void **_CBOR_UNUSED(_state)) {
+static void test_7(void** _state _CBOR_UNUSED) {
item = cbor_load(data7, 16, &res);
assert_null(item);
assert_true(res.error.code == CBOR_ERR_MEMERROR);
@@ -84,7 +84,7 @@ unsigned char data8[] = {0xA3, 0x64, 0x68, 0x61, 0x6C, 0x66, 0xFF, 0x00,
0xFA, 0x7F, 0x7F, 0xFF, 0xFF, 0x6D, 0x73, 0x69,
0x6D, 0x70, 0x6C, 0x65, 0x20, 0x76, 0x61, 0x6C,
0x75, 0x65, 0x73, 0x83, 0xF5, 0xF4, 0xF6};
-static void test_8(void **_CBOR_UNUSED(_state)) {
+static void test_8(void** _state _CBOR_UNUSED) {
item = cbor_load(data8, 39, &res);
assert_null(item);
assert_true(res.error.code == CBOR_ERR_SYNTAXERROR);
@@ -92,7 +92,7 @@ static void test_8(void **_CBOR_UNUSED(_state)) {
}
unsigned char data9[] = {0xBF, 0x05, 0xFF, 0x00, 0x00, 0x00, 0x10, 0x04};
-static void test_9(void **_CBOR_UNUSED(_state)) {
+static void test_9(void** _state _CBOR_UNUSED) {
item = cbor_load(data9, 8, &res);
assert_null(item);
assert_true(res.error.code == CBOR_ERR_SYNTAXERROR);
diff --git a/test/bytestring_encoders_test.c b/test/bytestring_encoders_test.c
index 8e2fbe694055..850f84645bcf 100644
--- a/test/bytestring_encoders_test.c
+++ b/test/bytestring_encoders_test.c
@@ -11,18 +11,18 @@
unsigned char buffer[512];
-static void test_embedded_bytestring_start(void **_CBOR_UNUSED(_state)) {
+static void test_embedded_bytestring_start(void** _state _CBOR_UNUSED) {
assert_size_equal(1, cbor_encode_bytestring_start(1, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0x41}), 1);
}
-static void test_bytestring_start(void **_CBOR_UNUSED(_state)) {
+static void test_bytestring_start(void** _state _CBOR_UNUSED) {
assert_size_equal(5, cbor_encode_bytestring_start(1000000, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0x5A, 0x00, 0x0F, 0x42, 0x40}),
5);
}
-static void test_indef_bytestring_start(void **_CBOR_UNUSED(_state)) {
+static void test_indef_bytestring_start(void** _state _CBOR_UNUSED) {
assert_size_equal(0, cbor_encode_indef_bytestring_start(buffer, 0));
assert_size_equal(1, cbor_encode_indef_bytestring_start(buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0x5F}), 1);
diff --git a/test/bytestring_test.c b/test/bytestring_test.c
index 08968a13e98e..5410aabdcdbc 100644
--- a/test/bytestring_test.c
+++ b/test/bytestring_test.c
@@ -9,7 +9,7 @@
#include "cbor.h"
#include "test_allocator.h"
-cbor_item_t *bs;
+cbor_item_t* bs;
struct cbor_load_result res;
unsigned char data1[] = {0x40, 0xFF};
@@ -133,7 +133,7 @@ unsigned char data8[] = {
0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD,
0xFE, 0xFF};
-static void test_empty_bs(void **_CBOR_UNUSED(_state)) {
+static void test_empty_bs(void** _state _CBOR_UNUSED) {
bs = cbor_load(data1, 2, &res);
assert_non_null(bs);
assert_true(cbor_typeof(bs) == CBOR_TYPE_BYTESTRING);
@@ -144,7 +144,7 @@ static void test_empty_bs(void **_CBOR_UNUSED(_state)) {
assert_null(bs);
}
-static void test_embedded_bs(void **_CBOR_UNUSED(_state)) {
+static void test_embedded_bs(void** _state _CBOR_UNUSED) {
bs = cbor_load(data2, 2, &res);
assert_non_null(bs);
assert_true(cbor_typeof(bs) == CBOR_TYPE_BYTESTRING);
@@ -157,13 +157,13 @@ static void test_embedded_bs(void **_CBOR_UNUSED(_state)) {
assert_null(bs);
}
-static void test_notenough_data(void **_CBOR_UNUSED(_state)) {
+static void test_notenough_data(void** _state _CBOR_UNUSED) {
bs = cbor_load(data3, 2, &res);
assert_null(bs);
assert_true(res.error.code == CBOR_ERR_NOTENOUGHDATA);
}
-static void test_short_bs1(void **_CBOR_UNUSED(_state)) {
+static void test_short_bs1(void** _state _CBOR_UNUSED) {
bs = cbor_load(data3, 4, &res);
assert_non_null(bs);
assert_true(cbor_typeof(bs) == CBOR_TYPE_BYTESTRING);
@@ -176,7 +176,7 @@ static void test_short_bs1(void **_CBOR_UNUSED(_state)) {
assert_null(bs);
}
-static void test_short_bs2(void **_CBOR_UNUSED(_state)) {
+static void test_short_bs2(void** _state _CBOR_UNUSED) {
bs = cbor_load(data4, 259, &res);
assert_non_null(bs);
assert_true(cbor_typeof(bs) == CBOR_TYPE_BYTESTRING);
@@ -188,7 +188,7 @@ static void test_short_bs2(void **_CBOR_UNUSED(_state)) {
assert_null(bs);
}
-static void test_half_bs(void **_CBOR_UNUSED(_state)) {
+static void test_half_bs(void** _state _CBOR_UNUSED) {
bs = cbor_load(data5, 259, &res);
assert_non_null(bs);
assert_true(cbor_typeof(bs) == CBOR_TYPE_BYTESTRING);
@@ -200,7 +200,7 @@ static void test_half_bs(void **_CBOR_UNUSED(_state)) {
assert_null(bs);
}
-static void test_int_bs(void **_CBOR_UNUSED(_state)) {
+static void test_int_bs(void** _state _CBOR_UNUSED) {
bs = cbor_load(data6, 261, &res);
assert_non_null(bs);
assert_true(cbor_typeof(bs) == CBOR_TYPE_BYTESTRING);
@@ -212,7 +212,7 @@ static void test_int_bs(void **_CBOR_UNUSED(_state)) {
assert_null(bs);
}
-static void test_long_bs(void **_CBOR_UNUSED(_state)) {
+static void test_long_bs(void** _state _CBOR_UNUSED) {
bs = cbor_load(data7, 265, &res);
assert_non_null(bs);
assert_true(cbor_typeof(bs) == CBOR_TYPE_BYTESTRING);
@@ -226,7 +226,7 @@ static void test_long_bs(void **_CBOR_UNUSED(_state)) {
unsigned char data9[] = {0x5F, 0xFF};
-static void test_zero_indef(void **_CBOR_UNUSED(_state)) {
+static void test_zero_indef(void** _state _CBOR_UNUSED) {
bs = cbor_load(data9, 2, &res);
assert_non_null(bs);
assert_true(cbor_typeof(bs) == CBOR_TYPE_BYTESTRING);
@@ -242,7 +242,7 @@ unsigned char data10[] = {0x5F, 0x58, 0x01, 0xA1, 0xFF, 0xFF};
/* start | bstring | break| extra */
-static void test_short_indef(void **_CBOR_UNUSED(_state)) {
+static void test_short_indef(void** _state _CBOR_UNUSED) {
bs = cbor_load(data10, 6, &res);
assert_non_null(bs);
assert_true(cbor_typeof(bs) == CBOR_TYPE_BYTESTRING);
@@ -265,7 +265,7 @@ unsigned char data11[] = {0x5F, 0x58, 0x01, 0xA1, 0x58, 0x01, 0xA2, 0xFF, 0xFF};
/* start | bstring | bstring | break|
* extra */
-static void test_two_indef(void **_CBOR_UNUSED(_state)) {
+static void test_two_indef(void** _state _CBOR_UNUSED) {
bs = cbor_load(data11, 9, &res);
assert_non_null(bs);
assert_size_equal(1, cbor_refcount(bs));
@@ -293,23 +293,23 @@ unsigned char data12[] = {0x5F, 0x58, 0x01};
/* start | bstring - too short */
-static void test_missing_indef(void **_CBOR_UNUSED(_state)) {
+static void test_missing_indef(void** _state _CBOR_UNUSED) {
bs = cbor_load(data12, 3, &res);
assert_true(res.error.code == CBOR_ERR_NOTENOUGHDATA);
assert_null(bs);
}
-static void test_inline_creation(void **_CBOR_UNUSED(_state)) {
+static void test_inline_creation(void** _state _CBOR_UNUSED) {
bs = cbor_build_bytestring((cbor_data) "Hello!", 6);
assert_memory_equal(cbor_bytestring_handle(bs), "Hello!", 6);
cbor_decref(&bs);
}
-static void test_add_chunk_reallocation_overflow(void **_CBOR_UNUSED(_state)) {
+static void test_add_chunk_reallocation_overflow(void** _state _CBOR_UNUSED) {
bs = cbor_new_indefinite_bytestring();
- cbor_item_t *chunk = cbor_build_bytestring((cbor_data) "Hello!", 6);
- struct cbor_indefinite_string_data *metadata =
- (struct cbor_indefinite_string_data *)bs->data;
+ cbor_item_t* chunk = cbor_build_bytestring((cbor_data) "Hello!", 6);
+ struct cbor_indefinite_string_data* metadata =
+ (struct cbor_indefinite_string_data*)bs->data;
// Pretend we already have many chunks allocated
metadata->chunk_count = SIZE_MAX;
metadata->chunk_capacity = SIZE_MAX;
@@ -323,7 +323,7 @@ static void test_add_chunk_reallocation_overflow(void **_CBOR_UNUSED(_state)) {
cbor_decref(&bs);
}
-static void test_bytestring_creation(void **_CBOR_UNUSED(_state)) {
+static void test_bytestring_creation(void** _state _CBOR_UNUSED) {
WITH_FAILING_MALLOC({ assert_null(cbor_new_definite_bytestring()); });
WITH_FAILING_MALLOC({ assert_null(cbor_new_indefinite_bytestring()); });
@@ -337,18 +337,18 @@ static void test_bytestring_creation(void **_CBOR_UNUSED(_state)) {
MALLOC_FAIL);
}
-static void test_bytestring_add_chunk(void **_CBOR_UNUSED(_state)) {
+static void test_bytestring_add_chunk(void** _state _CBOR_UNUSED) {
unsigned char bytes[] = {0, 0, 0xFF, 0xAB};
WITH_MOCK_MALLOC(
{
- cbor_item_t *bytestring = cbor_new_indefinite_bytestring();
- cbor_item_t *chunk = cbor_build_bytestring(bytes, 4);
+ cbor_item_t* bytestring = cbor_new_indefinite_bytestring();
+ cbor_item_t* chunk = cbor_build_bytestring(bytes, 4);
assert_false(cbor_bytestring_add_chunk(bytestring, chunk));
assert_size_equal(cbor_bytestring_chunk_count(bytestring), 0);
assert_size_equal(
- ((struct cbor_indefinite_string_data *)bytestring->data)
+ ((struct cbor_indefinite_string_data*)bytestring->data)
->chunk_capacity,
0);
diff --git a/test/callbacks_test.c b/test/callbacks_test.c
index 65c5d37f4399..c2b5ecfe8fe0 100644
--- a/test/callbacks_test.c
+++ b/test/callbacks_test.c
@@ -20,7 +20,7 @@ unsigned char data[] = {
0x88, 0x00, 0x75, 0x9C, 0xF6, 0xF7, 0xF5};
/* Exercise the default callbacks */
-static void test_default_callbacks(void** _CBOR_UNUSED(_state)) {
+static void test_default_callbacks(void** _state _CBOR_UNUSED) {
size_t read = 0;
while (read < 79) {
struct cbor_decoder_result result =
@@ -31,7 +31,7 @@ static void test_default_callbacks(void** _CBOR_UNUSED(_state)) {
unsigned char bytestring_data[] = {0x01, 0x02, 0x03};
static void test_builder_byte_string_callback_append(
- void** _CBOR_UNUSED(_state)) {
+ void** _state _CBOR_UNUSED) {
struct _cbor_stack stack = _cbor_stack_init();
assert_non_null(
_cbor_stack_push(&stack, cbor_new_indefinite_bytestring(), 0));
@@ -71,7 +71,7 @@ static void test_builder_byte_string_callback_append(
}
static void test_builder_byte_string_callback_append_alloc_failure(
- void** _CBOR_UNUSED(_state)) {
+ void** _state _CBOR_UNUSED) {
struct _cbor_stack stack = _cbor_stack_init();
assert_non_null(
_cbor_stack_push(&stack, cbor_new_indefinite_bytestring(), 0));
@@ -103,7 +103,7 @@ static void test_builder_byte_string_callback_append_alloc_failure(
}
static void test_builder_byte_string_callback_append_item_alloc_failure(
- void** _CBOR_UNUSED(_state)) {
+ void** _state _CBOR_UNUSED) {
struct _cbor_stack stack = _cbor_stack_init();
assert_non_null(
_cbor_stack_push(&stack, cbor_new_indefinite_bytestring(), 0));
@@ -137,7 +137,7 @@ static void test_builder_byte_string_callback_append_item_alloc_failure(
}
static void test_builder_byte_string_callback_append_parent_alloc_failure(
- void** _CBOR_UNUSED(_state)) {
+ void** _state _CBOR_UNUSED) {
struct _cbor_stack stack = _cbor_stack_init();
assert_non_null(
_cbor_stack_push(&stack, cbor_new_indefinite_bytestring(), 0));
@@ -171,7 +171,7 @@ static void test_builder_byte_string_callback_append_parent_alloc_failure(
}
unsigned char string_data[] = {0x61, 0x62, 0x63};
-static void test_builder_string_callback_append(void** _CBOR_UNUSED(_state)) {
+static void test_builder_string_callback_append(void** _state _CBOR_UNUSED) {
struct _cbor_stack stack = _cbor_stack_init();
assert_non_null(_cbor_stack_push(&stack, cbor_new_indefinite_string(), 0));
struct _cbor_decoder_context context = {
@@ -208,7 +208,7 @@ static void test_builder_string_callback_append(void** _CBOR_UNUSED(_state)) {
}
static void test_builder_string_callback_append_alloc_failure(
- void** _CBOR_UNUSED(_state)) {
+ void** _state _CBOR_UNUSED) {
struct _cbor_stack stack = _cbor_stack_init();
assert_non_null(_cbor_stack_push(&stack, cbor_new_indefinite_string(), 0));
struct _cbor_decoder_context context = {
@@ -239,7 +239,7 @@ static void test_builder_string_callback_append_alloc_failure(
}
static void test_builder_string_callback_append_item_alloc_failure(
- void** _CBOR_UNUSED(_state)) {
+ void** _state _CBOR_UNUSED) {
struct _cbor_stack stack = _cbor_stack_init();
assert_non_null(_cbor_stack_push(&stack, cbor_new_indefinite_string(), 0));
struct _cbor_decoder_context context = {
@@ -271,7 +271,7 @@ static void test_builder_string_callback_append_item_alloc_failure(
}
static void test_builder_string_callback_append_parent_alloc_failure(
- void** _CBOR_UNUSED(_state)) {
+ void** _state _CBOR_UNUSED) {
struct _cbor_stack stack = _cbor_stack_init();
assert_non_null(_cbor_stack_push(&stack, cbor_new_indefinite_string(), 0));
struct _cbor_decoder_context context = {
@@ -302,7 +302,7 @@ static void test_builder_string_callback_append_parent_alloc_failure(
_cbor_stack_pop(&stack);
}
-static void test_append_array_failure(void** _CBOR_UNUSED(_state)) {
+static void test_append_array_failure(void** _state _CBOR_UNUSED) {
struct _cbor_stack stack = _cbor_stack_init();
assert_non_null(_cbor_stack_push(&stack, cbor_new_definite_array(0), 0));
stack.top->subitems = 1;
@@ -331,7 +331,7 @@ static void test_append_array_failure(void** _CBOR_UNUSED(_state)) {
_cbor_stack_pop(&stack);
}
-static void test_append_map_failure(void** _CBOR_UNUSED(_state)) {
+static void test_append_map_failure(void** _state _CBOR_UNUSED) {
struct _cbor_stack stack = _cbor_stack_init();
assert_non_null(
_cbor_stack_push(&stack, cbor_new_indefinite_map(), /*subitems=*/0));
@@ -362,7 +362,7 @@ static void test_append_map_failure(void** _CBOR_UNUSED(_state)) {
// Size 1 array start, but we get an indef break
unsigned char invalid_indef_break_data[] = {0x81, 0xFF};
-static void test_invalid_indef_break(void** _CBOR_UNUSED(_state)) {
+static void test_invalid_indef_break(void** _state _CBOR_UNUSED) {
struct cbor_load_result res;
cbor_item_t* item = cbor_load(invalid_indef_break_data, 2, &res);
@@ -371,7 +371,7 @@ static void test_invalid_indef_break(void** _CBOR_UNUSED(_state)) {
assert_true(res.error.code == CBOR_ERR_SYNTAXERROR);
}
-static void test_invalid_state_indef_break(void** _CBOR_UNUSED(_state)) {
+static void test_invalid_state_indef_break(void** _state _CBOR_UNUSED) {
struct _cbor_stack stack = _cbor_stack_init();
assert_non_null(_cbor_stack_push(&stack, cbor_new_int8(), /*subitems=*/0));
struct _cbor_decoder_context context = {
diff --git a/test/cbor_serialize_test.c b/test/cbor_serialize_test.c
index a2907b149345..5f8cf9f611da 100644
--- a/test/cbor_serialize_test.c
+++ b/test/cbor_serialize_test.c
@@ -6,7 +6,6 @@
*/
// cbor_serialize_alloc
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#include <math.h>
@@ -24,8 +23,8 @@
unsigned char buffer[512];
-static void test_serialize_uint8_embed(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_int8();
+static void test_serialize_uint8_embed(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_int8();
cbor_set_uint8(item, 0);
assert_size_equal(1, cbor_serialize(item, buffer, 512));
assert_memory_equal(buffer, (unsigned char[]){0x00}, 1);
@@ -33,8 +32,8 @@ static void test_serialize_uint8_embed(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_serialize_uint8(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_int8();
+static void test_serialize_uint8(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_int8();
cbor_set_uint8(item, 42);
assert_size_equal(2, cbor_serialize(item, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0x18, 0x2a}), 2);
@@ -42,8 +41,8 @@ static void test_serialize_uint8(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_serialize_uint16(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_int16();
+static void test_serialize_uint16(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_int16();
cbor_set_uint16(item, 1000);
assert_size_equal(3, cbor_serialize(item, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0x19, 0x03, 0xE8}), 3);
@@ -51,8 +50,8 @@ static void test_serialize_uint16(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_serialize_uint32(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_int32();
+static void test_serialize_uint32(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_int32();
cbor_set_uint32(item, 1000000);
assert_size_equal(5, cbor_serialize(item, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0x1A, 0x00, 0x0F, 0x42, 0x40}),
@@ -61,8 +60,8 @@ static void test_serialize_uint32(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_serialize_uint64(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_int64();
+static void test_serialize_uint64(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_int64();
cbor_set_uint64(item, 1000000000000);
assert_size_equal(9, cbor_serialize(item, buffer, 512));
assert_memory_equal(
@@ -73,8 +72,8 @@ static void test_serialize_uint64(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_serialize_negint8_embed(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_int8();
+static void test_serialize_negint8_embed(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_int8();
cbor_set_uint8(item, 0);
cbor_mark_negint(item);
assert_size_equal(1, cbor_serialize(item, buffer, 512));
@@ -83,8 +82,8 @@ static void test_serialize_negint8_embed(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_serialize_negint8(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_int8();
+static void test_serialize_negint8(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_int8();
cbor_set_uint8(item, 42);
cbor_mark_negint(item);
assert_size_equal(2, cbor_serialize(item, buffer, 512));
@@ -93,8 +92,8 @@ static void test_serialize_negint8(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_serialize_negint16(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_int16();
+static void test_serialize_negint16(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_int16();
cbor_set_uint16(item, 1000);
cbor_mark_negint(item);
assert_size_equal(3, cbor_serialize(item, buffer, 512));
@@ -103,8 +102,8 @@ static void test_serialize_negint16(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_serialize_negint32(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_int32();
+static void test_serialize_negint32(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_int32();
cbor_set_uint32(item, 1000000);
cbor_mark_negint(item);
assert_size_equal(5, cbor_serialize(item, buffer, 512));
@@ -114,8 +113,8 @@ static void test_serialize_negint32(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_serialize_negint64(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_int64();
+static void test_serialize_negint64(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_int64();
cbor_set_uint64(item, 1000000000000);
cbor_mark_negint(item);
assert_size_equal(9, cbor_serialize(item, buffer, 512));
@@ -127,9 +126,9 @@ static void test_serialize_negint64(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_serialize_definite_bytestring(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_definite_bytestring();
- unsigned char *data = malloc(256);
+static void test_serialize_definite_bytestring(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_definite_bytestring();
+ unsigned char* data = malloc(256);
cbor_bytestring_set_handle(item, data, 256);
memset(data, 0, 256); /* Prevent undefined behavior in comparison */
assert_size_equal(256 + 3, cbor_serialize(item, buffer, 512));
@@ -139,11 +138,11 @@ static void test_serialize_definite_bytestring(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_serialize_indefinite_bytestring(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_indefinite_bytestring();
+static void test_serialize_indefinite_bytestring(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_indefinite_bytestring();
- cbor_item_t *chunk = cbor_new_definite_bytestring();
- unsigned char *data = malloc(256);
+ cbor_item_t* chunk = cbor_new_definite_bytestring();
+ unsigned char* data = malloc(256);
memset(data, 0, 256); /* Prevent undefined behavior in comparison */
cbor_bytestring_set_handle(chunk, data, 256);
@@ -159,11 +158,11 @@ static void test_serialize_indefinite_bytestring(void **_CBOR_UNUSED(_state)) {
}
static void test_serialize_bytestring_size_overflow(
- void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_definite_bytestring();
+ void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_definite_bytestring();
// Fake having a huge chunk of data
- unsigned char *data = malloc(1);
+ unsigned char* data = malloc(1);
cbor_bytestring_set_handle(item, data, SIZE_MAX);
// Would require 1 + 8 + SIZE_MAX bytes, which overflows size_t
@@ -172,9 +171,9 @@ static void test_serialize_bytestring_size_overflow(
cbor_decref(&item);
}
-static void test_serialize_bytestring_no_space(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_definite_bytestring();
- unsigned char *data = malloc(12);
+static void test_serialize_bytestring_no_space(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_definite_bytestring();
+ unsigned char* data = malloc(12);
cbor_bytestring_set_handle(item, data, 12);
assert_size_equal(cbor_serialize(item, buffer, 1), 0);
@@ -183,10 +182,10 @@ static void test_serialize_bytestring_no_space(void **_CBOR_UNUSED(_state)) {
}
static void test_serialize_indefinite_bytestring_no_space(
- void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_indefinite_bytestring();
- cbor_item_t *chunk = cbor_new_definite_bytestring();
- unsigned char *data = malloc(256);
+ void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_indefinite_bytestring();
+ cbor_item_t* chunk = cbor_new_definite_bytestring();
+ unsigned char* data = malloc(256);
cbor_bytestring_set_handle(chunk, data, 256);
assert_true(cbor_bytestring_add_chunk(item, cbor_move(chunk)));
@@ -203,10 +202,10 @@ static void test_serialize_indefinite_bytestring_no_space(
cbor_decref(&item);
}
-static void test_serialize_definite_string(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_definite_string();
- unsigned char *data = malloc(12);
- strncpy((char *)data, "Hello world!", 12);
+static void test_serialize_definite_string(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_definite_string();
+ unsigned char* data = malloc(12);
+ strncpy((char*)data, "Hello world!", 12);
cbor_string_set_handle(item, data, 12);
assert_size_equal(1 + 12, cbor_serialize(item, buffer, 512));
assert_memory_equal(
@@ -219,11 +218,11 @@ static void test_serialize_definite_string(void **_CBOR_UNUSED(_state)) {
}
static void test_serialize_definite_string_4b_header(
- void **_CBOR_UNUSED(_state)) {
+ void** _state _CBOR_UNUSED) {
#if SIZE_MAX > UINT16_MAX
- cbor_item_t *item = cbor_new_definite_string();
+ cbor_item_t* item = cbor_new_definite_string();
const size_t size = (size_t)UINT16_MAX + 1;
- unsigned char *data = malloc(size);
+ unsigned char* data = malloc(size);
memset(data, 0, size);
cbor_string_set_handle(item, data, size);
assert_size_equal(cbor_serialized_size(item), 1 + 4 + size);
@@ -232,11 +231,11 @@ static void test_serialize_definite_string_4b_header(
}
static void test_serialize_definite_string_8b_header(
- void **_CBOR_UNUSED(_state)) {
+ void** _state _CBOR_UNUSED) {
#if SIZE_MAX > UINT32_MAX
- cbor_item_t *item = cbor_new_definite_string();
+ cbor_item_t* item = cbor_new_definite_string();
const size_t size = (size_t)UINT32_MAX + 1;
- unsigned char *data = malloc(1);
+ unsigned char* data = malloc(1);
data[0] = '\0';
cbor_string_set_handle(item, data, 1);
// Pretend that we have a big item to avoid the huge malloc
@@ -246,12 +245,12 @@ static void test_serialize_definite_string_8b_header(
#endif
}
-static void test_serialize_indefinite_string(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_indefinite_string();
- cbor_item_t *chunk = cbor_new_definite_string();
+static void test_serialize_indefinite_string(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_indefinite_string();
+ cbor_item_t* chunk = cbor_new_definite_string();
- unsigned char *data = malloc(12);
- strncpy((char *)data, "Hello world!", 12);
+ unsigned char* data = malloc(12);
+ strncpy((char*)data, "Hello world!", 12);
cbor_string_set_handle(chunk, data, 12);
assert_true(cbor_string_add_chunk(item, cbor_move(chunk)));
@@ -267,9 +266,9 @@ static void test_serialize_indefinite_string(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_serialize_string_no_space(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_definite_string();
- unsigned char *data = malloc(12);
+static void test_serialize_string_no_space(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_definite_string();
+ unsigned char* data = malloc(12);
memset(data, 0, 12);
cbor_string_set_handle(item, data, 12);
@@ -279,10 +278,10 @@ static void test_serialize_string_no_space(void **_CBOR_UNUSED(_state)) {
}
static void test_serialize_indefinite_string_no_space(
- void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_indefinite_string();
- cbor_item_t *chunk = cbor_new_definite_string();
- unsigned char *data = malloc(256);
+ void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_indefinite_string();
+ cbor_item_t* chunk = cbor_new_definite_string();
+ unsigned char* data = malloc(256);
memset(data, 0, 256);
cbor_string_set_handle(chunk, data, 256);
assert_true(cbor_string_add_chunk(item, cbor_move(chunk)));
@@ -300,10 +299,10 @@ static void test_serialize_indefinite_string_no_space(
cbor_decref(&item);
}
-static void test_serialize_definite_array(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_definite_array(2);
- cbor_item_t *one = cbor_build_uint8(1);
- cbor_item_t *two = cbor_build_uint8(2);
+static void test_serialize_definite_array(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_definite_array(2);
+ cbor_item_t* one = cbor_build_uint8(1);
+ cbor_item_t* two = cbor_build_uint8(2);
assert_true(cbor_array_push(item, one));
assert_true(cbor_array_set(item, 1, two));
@@ -317,9 +316,9 @@ static void test_serialize_definite_array(void **_CBOR_UNUSED(_state)) {
cbor_decref(&two);
}
-static void test_serialize_array_no_space(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_indefinite_array();
- cbor_item_t *one = cbor_build_uint8(1);
+static void test_serialize_array_no_space(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_indefinite_array();
+ cbor_item_t* one = cbor_build_uint8(1);
assert_true(cbor_array_push(item, one));
assert_size_equal(cbor_serialized_size(item), 3);
@@ -336,10 +335,10 @@ static void test_serialize_array_no_space(void **_CBOR_UNUSED(_state)) {
cbor_decref(&one);
}
-static void test_serialize_indefinite_array(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_indefinite_array();
- cbor_item_t *one = cbor_build_uint8(1);
- cbor_item_t *two = cbor_build_uint8(2);
+static void test_serialize_indefinite_array(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_indefinite_array();
+ cbor_item_t* one = cbor_build_uint8(1);
+ cbor_item_t* two = cbor_build_uint8(2);
assert_true(cbor_array_push(item, one));
assert_true(cbor_array_push(item, two));
@@ -352,10 +351,10 @@ static void test_serialize_indefinite_array(void **_CBOR_UNUSED(_state)) {
cbor_decref(&two);
}
-static void test_serialize_definite_map(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_definite_map(2);
- cbor_item_t *one = cbor_build_uint8(1);
- cbor_item_t *two = cbor_build_uint8(2);
+static void test_serialize_definite_map(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_definite_map(2);
+ cbor_item_t* one = cbor_build_uint8(1);
+ cbor_item_t* two = cbor_build_uint8(2);
assert_true(cbor_map_add(item, (struct cbor_pair){.key = one, .value = two}));
assert_true(cbor_map_add(item, (struct cbor_pair){.key = two, .value = one}));
@@ -369,10 +368,10 @@ static void test_serialize_definite_map(void **_CBOR_UNUSED(_state)) {
cbor_decref(&two);
}
-static void test_serialize_indefinite_map(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_indefinite_map();
- cbor_item_t *one = cbor_build_uint8(1);
- cbor_item_t *two = cbor_build_uint8(2);
+static void test_serialize_indefinite_map(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_indefinite_map();
+ cbor_item_t* one = cbor_build_uint8(1);
+ cbor_item_t* two = cbor_build_uint8(2);
assert_true(cbor_map_add(item, (struct cbor_pair){.key = one, .value = two}));
assert_true(cbor_map_add(item, (struct cbor_pair){.key = two, .value = one}));
@@ -386,10 +385,10 @@ static void test_serialize_indefinite_map(void **_CBOR_UNUSED(_state)) {
cbor_decref(&two);
}
-static void test_serialize_map_no_space(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_indefinite_map();
- cbor_item_t *one = cbor_build_uint8(1);
- cbor_item_t *two = cbor_build_uint8(2);
+static void test_serialize_map_no_space(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_indefinite_map();
+ cbor_item_t* one = cbor_build_uint8(1);
+ cbor_item_t* two = cbor_build_uint8(2);
assert_true(cbor_map_add(item, (struct cbor_pair){.key = one, .value = two}));
assert_size_equal(cbor_serialized_size(item), 4);
@@ -410,9 +409,9 @@ static void test_serialize_map_no_space(void **_CBOR_UNUSED(_state)) {
cbor_decref(&two);
}
-static void test_serialize_tags(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_tag(21);
- cbor_item_t *one = cbor_build_uint8(1);
+static void test_serialize_tags(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_tag(21);
+ cbor_item_t* one = cbor_build_uint8(1);
cbor_tag_set_item(item, one);
assert_size_equal(2, cbor_serialize(item, buffer, 512));
@@ -422,9 +421,9 @@ static void test_serialize_tags(void **_CBOR_UNUSED(_state)) {
cbor_decref(&one);
}
-static void test_serialize_tags_no_space(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_tag(21);
- cbor_item_t *one = cbor_build_uint8(1);
+static void test_serialize_tags_no_space(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_tag(21);
+ cbor_item_t* one = cbor_build_uint8(1);
cbor_tag_set_item(item, one);
assert_size_equal(cbor_serialized_size(item), 2);
@@ -438,8 +437,8 @@ static void test_serialize_tags_no_space(void **_CBOR_UNUSED(_state)) {
cbor_decref(&one);
}
-static void test_serialize_half(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_float2();
+static void test_serialize_half(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_float2();
cbor_set_float2(item, NAN);
assert_size_equal(3, cbor_serialize(item, buffer, 512));
@@ -448,8 +447,8 @@ static void test_serialize_half(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_serialize_single(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_float4();
+static void test_serialize_single(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_float4();
cbor_set_float4(item, 100000.0f);
assert_size_equal(5, cbor_serialize(item, buffer, 512));
@@ -459,8 +458,8 @@ static void test_serialize_single(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_serialize_double(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_float8();
+static void test_serialize_double(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_float8();
cbor_set_float8(item, -4.1);
assert_size_equal(9, cbor_serialize(item, buffer, 512));
@@ -472,8 +471,8 @@ static void test_serialize_double(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_serialize_ctrl(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_undef();
+static void test_serialize_ctrl(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_undef();
assert_size_equal(1, cbor_serialize(item, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0xF7}), 1);
@@ -481,8 +480,8 @@ static void test_serialize_ctrl(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_serialize_long_ctrl(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_ctrl();
+static void test_serialize_long_ctrl(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_ctrl();
cbor_set_ctrl(item, 254);
assert_size_equal(2, cbor_serialize(item, buffer, 512));
@@ -491,13 +490,13 @@ static void test_serialize_long_ctrl(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_auto_serialize(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_definite_array(4);
+static void test_auto_serialize(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_definite_array(4);
for (size_t i = 0; i < 4; i++) {
assert_true(cbor_array_push(item, cbor_move(cbor_build_uint64(0))));
}
- unsigned char *output;
+ unsigned char* output;
size_t output_size;
assert_size_equal(cbor_serialize_alloc(item, &output, &output_size), 37);
assert_size_equal(output_size, 37);
@@ -507,10 +506,10 @@ static void test_auto_serialize(void **_CBOR_UNUSED(_state)) {
_cbor_free(output);
}
-static void test_auto_serialize_no_size(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_build_uint8(1);
+static void test_auto_serialize_no_size(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_build_uint8(1);
- unsigned char *output;
+ unsigned char* output;
assert_size_equal(cbor_serialize_alloc(item, &output, NULL), 1);
assert_memory_equal(output, ((unsigned char[]){0x01}), 1);
assert_size_equal(cbor_serialized_size(item), 1);
@@ -518,16 +517,16 @@ static void test_auto_serialize_no_size(void **_CBOR_UNUSED(_state)) {
_cbor_free(output);
}
-static void test_auto_serialize_too_large(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_indefinite_string();
- cbor_item_t *chunk = cbor_new_definite_string();
+static void test_auto_serialize_too_large(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_indefinite_string();
+ cbor_item_t* chunk = cbor_new_definite_string();
assert_true(cbor_string_add_chunk(item, chunk));
// Pretend the chunk is huge
chunk->metadata.string_metadata.length = SIZE_MAX;
assert_true(SIZE_MAX + 2 == 1);
assert_size_equal(cbor_serialized_size(item), 0);
- unsigned char *output;
+ unsigned char* output;
size_t output_size;
assert_size_equal(cbor_serialize_alloc(item, &output, &output_size), 0);
assert_size_equal(output_size, 0);
@@ -538,11 +537,11 @@ static void test_auto_serialize_too_large(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_auto_serialize_alloc_fail(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_build_uint8(42);
+static void test_auto_serialize_alloc_fail(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_build_uint8(42);
WITH_FAILING_MALLOC({
- unsigned char *output;
+ unsigned char* output;
size_t output_size;
assert_size_equal(cbor_serialize_alloc(item, &output, &output_size), 0);
assert_size_equal(output_size, 0);
@@ -553,10 +552,10 @@ static void test_auto_serialize_alloc_fail(void **_CBOR_UNUSED(_state)) {
}
static void test_auto_serialize_zero_len_bytestring(
- void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_build_bytestring((cbor_data) "", 0);
+ void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_build_bytestring((cbor_data) "", 0);
- unsigned char *output;
+ unsigned char* output;
assert_size_equal(cbor_serialize_alloc(item, &output, NULL), 1);
assert_memory_equal(output, ((unsigned char[]){0x40}), 1);
assert_size_equal(cbor_serialized_size(item), 1);
@@ -564,10 +563,10 @@ static void test_auto_serialize_zero_len_bytestring(
_cbor_free(output);
}
-static void test_auto_serialize_zero_len_string(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_build_string("");
+static void test_auto_serialize_zero_len_string(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_build_string("");
- unsigned char *output;
+ unsigned char* output;
assert_size_equal(cbor_serialize_alloc(item, &output, NULL), 1);
assert_memory_equal(output, ((unsigned char[]){0x60}), 1);
assert_size_equal(cbor_serialized_size(item), 1);
@@ -576,13 +575,13 @@ static void test_auto_serialize_zero_len_string(void **_CBOR_UNUSED(_state)) {
}
static void test_auto_serialize_zero_len_bytestring_chunk(
- void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_indefinite_bytestring();
+ void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_indefinite_bytestring();
assert_true(cbor_bytestring_add_chunk(
item, cbor_move(cbor_build_bytestring((cbor_data) "", 0))));
- unsigned char *output;
+ unsigned char* output;
assert_size_equal(cbor_serialize_alloc(item, &output, NULL), 3);
assert_memory_equal(output, ((unsigned char[]){0x5f, 0x40, 0xff}), 3);
assert_size_equal(cbor_serialized_size(item), 3);
@@ -591,12 +590,12 @@ static void test_auto_serialize_zero_len_bytestring_chunk(
}
static void test_auto_serialize_zero_len_string_chunk(
- void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_indefinite_string();
+ void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_indefinite_string();
assert_true(cbor_string_add_chunk(item, cbor_move(cbor_build_string(""))));
- unsigned char *output;
+ unsigned char* output;
assert_size_equal(cbor_serialize_alloc(item, &output, NULL), 3);
assert_memory_equal(output, ((unsigned char[]){0x7f, 0x60, 0xff}), 3);
assert_size_equal(cbor_serialized_size(item), 3);
@@ -604,10 +603,10 @@ static void test_auto_serialize_zero_len_string_chunk(
_cbor_free(output);
}
-static void test_auto_serialize_zero_len_array(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_definite_array(0);
+static void test_auto_serialize_zero_len_array(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_definite_array(0);
- unsigned char *output;
+ unsigned char* output;
assert_size_equal(cbor_serialize_alloc(item, &output, NULL), 1);
assert_memory_equal(output, ((unsigned char[]){0x80}), 1);
assert_size_equal(cbor_serialized_size(item), 1);
@@ -616,10 +615,10 @@ static void test_auto_serialize_zero_len_array(void **_CBOR_UNUSED(_state)) {
}
static void test_auto_serialize_zero_len_indef_array(
- void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_indefinite_array();
+ void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_indefinite_array();
- unsigned char *output;
+ unsigned char* output;
assert_size_equal(cbor_serialize_alloc(item, &output, NULL), 2);
assert_memory_equal(output, ((unsigned char[]){0x9f, 0xff}), 2);
assert_size_equal(cbor_serialized_size(item), 2);
@@ -627,10 +626,10 @@ static void test_auto_serialize_zero_len_indef_array(
_cbor_free(output);
}
-static void test_auto_serialize_zero_len_map(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_definite_map(0);
+static void test_auto_serialize_zero_len_map(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_definite_map(0);
- unsigned char *output;
+ unsigned char* output;
assert_size_equal(cbor_serialize_alloc(item, &output, NULL), 1);
assert_memory_equal(output, ((unsigned char[]){0xa0}), 1);
assert_size_equal(cbor_serialized_size(item), 1);
@@ -638,11 +637,10 @@ static void test_auto_serialize_zero_len_map(void **_CBOR_UNUSED(_state)) {
_cbor_free(output);
}
-static void test_auto_serialize_zero_len_indef_map(
- void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_indefinite_map();
+static void test_auto_serialize_zero_len_indef_map(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_indefinite_map();
- unsigned char *output;
+ unsigned char* output;
assert_size_equal(cbor_serialize_alloc(item, &output, NULL), 2);
assert_memory_equal(output, ((unsigned char[]){0xbf, 0xff}), 2);
assert_size_equal(cbor_serialized_size(item), 2);
diff --git a/test/cbor_stream_decode_test.c b/test/cbor_stream_decode_test.c
index 5288016c2fc6..d1befd09b131 100644
--- a/test/cbor_stream_decode_test.c
+++ b/test/cbor_stream_decode_test.c
@@ -9,12 +9,12 @@
#include "cbor.h"
#include "stream_expectations.h"
-static void test_no_data(void **_CBOR_UNUSED(_state)) {
+static void test_no_data(void** _state _CBOR_UNUSED) {
assert_decoder_result_nedata(1, decode(NULL, 0));
}
unsigned char embedded_uint8_data[] = {0x00, 0x01, 0x05, 0x17};
-static void test_uint8_embedded_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_uint8_embedded_decoding(void** _state _CBOR_UNUSED) {
assert_uint8_eq(0);
assert_decoder_result(1, CBOR_DECODER_FINISHED,
decode(embedded_uint8_data, 1));
@@ -33,7 +33,7 @@ static void test_uint8_embedded_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char uint8_data[] = {0x18, 0x83, 0x18, 0xFF};
-static void test_uint8_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_uint8_decoding(void** _state _CBOR_UNUSED) {
assert_uint8_eq(0x83);
assert_decoder_result(2, CBOR_DECODER_FINISHED, decode(uint8_data, 2));
@@ -44,7 +44,7 @@ static void test_uint8_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char uint16_data[] = {0x19, 0x01, 0xf4};
-static void test_uint16_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_uint16_decoding(void** _state _CBOR_UNUSED) {
assert_uint16_eq(500);
assert_decoder_result(3, CBOR_DECODER_FINISHED, decode(uint16_data, 3));
@@ -52,7 +52,7 @@ static void test_uint16_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char uint32_data[] = {0x1a, 0xa5, 0xf7, 0x02, 0xb3};
-static void test_uint32_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_uint32_decoding(void** _state _CBOR_UNUSED) {
assert_uint32_eq((uint32_t)2784428723UL);
assert_decoder_result(5, CBOR_DECODER_FINISHED, decode(uint32_data, 5));
@@ -61,7 +61,7 @@ static void test_uint32_decoding(void **_CBOR_UNUSED(_state)) {
unsigned char uint64_data[] = {0x1b, 0xa5, 0xf7, 0x02, 0xb3,
0xa5, 0xf7, 0x02, 0xb3};
-static void test_uint64_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_uint64_decoding(void** _state _CBOR_UNUSED) {
assert_uint64_eq(11959030306112471731ULL);
assert_decoder_result(9, CBOR_DECODER_FINISHED, decode(uint64_data, 9));
@@ -69,7 +69,7 @@ static void test_uint64_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char embedded_negint8_data[] = {0x20, 0x21, 0x25, 0x37};
-static void test_negint8_embedded_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_negint8_embedded_decoding(void** _state _CBOR_UNUSED) {
assert_negint8_eq(0);
assert_decoder_result(1, CBOR_DECODER_FINISHED,
decode(embedded_negint8_data, 1));
@@ -88,7 +88,7 @@ static void test_negint8_embedded_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char negint8_data[] = {0x38, 0x83, 0x38, 0xFF};
-static void test_negint8_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_negint8_decoding(void** _state _CBOR_UNUSED) {
assert_negint8_eq(0x83);
assert_decoder_result(2, CBOR_DECODER_FINISHED, decode(negint8_data, 2));
@@ -99,7 +99,7 @@ static void test_negint8_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char negint16_data[] = {0x39, 0x01, 0xf4};
-static void test_negint16_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_negint16_decoding(void** _state _CBOR_UNUSED) {
assert_negint16_eq(500);
assert_decoder_result(3, CBOR_DECODER_FINISHED, decode(negint16_data, 3));
@@ -107,7 +107,7 @@ static void test_negint16_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char negint32_data[] = {0x3a, 0xa5, 0xf7, 0x02, 0xb3};
-static void test_negint32_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_negint32_decoding(void** _state _CBOR_UNUSED) {
assert_negint32_eq((uint32_t)2784428723UL);
assert_decoder_result(5, CBOR_DECODER_FINISHED, decode(negint32_data, 5));
@@ -116,7 +116,7 @@ static void test_negint32_decoding(void **_CBOR_UNUSED(_state)) {
unsigned char negint64_data[] = {0x3b, 0xa5, 0xf7, 0x02, 0xb3,
0xa5, 0xf7, 0x02, 0xb3};
-static void test_negint64_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_negint64_decoding(void** _state _CBOR_UNUSED) {
assert_negint64_eq(11959030306112471731ULL);
assert_decoder_result(9, CBOR_DECODER_FINISHED, decode(negint64_data, 9));
@@ -124,7 +124,7 @@ static void test_negint64_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char bstring_embedded_int8_data[] = {0x41, 0xFF};
-static void test_bstring_embedded_int8_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_bstring_embedded_int8_decoding(void** _state _CBOR_UNUSED) {
assert_bstring_mem_eq(bstring_embedded_int8_data + 1, 1);
assert_decoder_result(2, CBOR_DECODER_FINISHED,
decode(bstring_embedded_int8_data, 2));
@@ -136,7 +136,7 @@ static void test_bstring_embedded_int8_decoding(void **_CBOR_UNUSED(_state)) {
// the second byte of input); the data is never read, so we never run into
// memory issues despite not allocating and initializing all the data.
unsigned char bstring_int8_data[] = {0x58, 0x02 /*, [2 bytes] */};
-static void test_bstring_int8_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_bstring_int8_decoding(void** _state _CBOR_UNUSED) {
assert_bstring_mem_eq(bstring_int8_data + 2, 2);
assert_decoder_result(4, CBOR_DECODER_FINISHED, decode(bstring_int8_data, 4));
@@ -146,7 +146,7 @@ static void test_bstring_int8_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char bstring_int8_empty_data[] = {0x58, 0x00};
-static void test_bstring_int8_empty_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_bstring_int8_empty_decoding(void** _state _CBOR_UNUSED) {
assert_bstring_mem_eq(bstring_int8_empty_data + 2, 0);
assert_decoder_result(2, CBOR_DECODER_FINISHED,
decode(bstring_int8_empty_data, 2));
@@ -155,7 +155,7 @@ static void test_bstring_int8_empty_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char bstring_int16_data[] = {0x59, 0x01, 0x5C /*, [348 bytes] */};
-static void test_bstring_int16_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_bstring_int16_decoding(void** _state _CBOR_UNUSED) {
assert_bstring_mem_eq(bstring_int16_data + 3, 348);
assert_decoder_result(3 + 348, CBOR_DECODER_FINISHED,
decode(bstring_int16_data, 3 + 348));
@@ -167,7 +167,7 @@ static void test_bstring_int16_decoding(void **_CBOR_UNUSED(_state)) {
unsigned char bstring_int32_data[] = {0x5A, 0x00, 0x10, 0x10,
0x10 /*, [1052688 bytes] */};
-static void test_bstring_int32_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_bstring_int32_decoding(void** _state _CBOR_UNUSED) {
assert_bstring_mem_eq(bstring_int32_data + 5, 1052688);
assert_decoder_result(5 + 1052688, CBOR_DECODER_FINISHED,
decode(bstring_int32_data, 5 + 1052688));
@@ -181,7 +181,7 @@ static void test_bstring_int32_decoding(void **_CBOR_UNUSED(_state)) {
unsigned char bstring_int64_data[] = {
0x5B, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00 /*, [4294967296 bytes] */};
-static void test_bstring_int64_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_bstring_int64_decoding(void** _state _CBOR_UNUSED) {
assert_bstring_mem_eq(bstring_int64_data + 9, 4294967296);
assert_decoder_result(9 + 4294967296, CBOR_DECODER_FINISHED,
decode(bstring_int64_data, 9 + 4294967296));
@@ -194,7 +194,7 @@ static void test_bstring_int64_decoding(void **_CBOR_UNUSED(_state)) {
unsigned char bstring_indef_1_data[] = {0x5F, 0x40 /* Empty byte string */,
0xFF};
-static void test_bstring_indef_decoding_1(void **_CBOR_UNUSED(_state)) {
+static void test_bstring_indef_decoding_1(void** _state _CBOR_UNUSED) {
assert_bstring_indef_start();
assert_decoder_result(1, CBOR_DECODER_FINISHED,
decode(bstring_indef_1_data, 3));
@@ -209,7 +209,7 @@ static void test_bstring_indef_decoding_1(void **_CBOR_UNUSED(_state)) {
}
unsigned char bstring_indef_2_data[] = {0x5F, 0xFF};
-static void test_bstring_indef_decoding_2(void **_CBOR_UNUSED(_state)) {
+static void test_bstring_indef_decoding_2(void** _state _CBOR_UNUSED) {
assert_bstring_indef_start();
assert_decoder_result(1, CBOR_DECODER_FINISHED,
decode(bstring_indef_2_data, 2));
@@ -226,7 +226,7 @@ unsigned char bstring_indef_3_data[] = {0x5F,
0x58, 0x01, 0x00,
// Break
0xFF};
-static void test_bstring_indef_decoding_3(void **_CBOR_UNUSED(_state)) {
+static void test_bstring_indef_decoding_3(void** _state _CBOR_UNUSED) {
assert_bstring_indef_start();
assert_decoder_result(1, CBOR_DECODER_FINISHED,
decode(bstring_indef_3_data, 6));
@@ -245,7 +245,7 @@ static void test_bstring_indef_decoding_3(void **_CBOR_UNUSED(_state)) {
}
unsigned char string_embedded_int8_data[] = {0x61, 0xFF};
-static void test_string_embedded_int8_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_string_embedded_int8_decoding(void** _state _CBOR_UNUSED) {
assert_string_mem_eq(string_embedded_int8_data + 1, 1);
assert_decoder_result(2, CBOR_DECODER_FINISHED,
decode(string_embedded_int8_data, 2));
@@ -257,7 +257,7 @@ static void test_string_embedded_int8_decoding(void **_CBOR_UNUSED(_state)) {
// the second byte of input); the data is never read, so we never run into
// memory issues despite not allocating and initializing all the data.
unsigned char string_int8_data[] = {0x78, 0x02 /*, [2 bytes] */};
-static void test_string_int8_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_string_int8_decoding(void** _state _CBOR_UNUSED) {
assert_string_mem_eq(string_int8_data + 2, 2);
assert_decoder_result(4, CBOR_DECODER_FINISHED, decode(string_int8_data, 4));
@@ -267,7 +267,7 @@ static void test_string_int8_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char string_int8_empty_data[] = {0x78, 0x00};
-static void test_string_int8_empty_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_string_int8_empty_decoding(void** _state _CBOR_UNUSED) {
assert_string_mem_eq(string_int8_empty_data + 2, 0);
assert_decoder_result(2, CBOR_DECODER_FINISHED,
decode(string_int8_empty_data, 2));
@@ -276,7 +276,7 @@ static void test_string_int8_empty_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char string_int16_data[] = {0x79, 0x01, 0x5C /*, [348 bytes] */};
-static void test_string_int16_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_string_int16_decoding(void** _state _CBOR_UNUSED) {
assert_string_mem_eq(string_int16_data + 3, 348);
assert_decoder_result(3 + 348, CBOR_DECODER_FINISHED,
decode(string_int16_data, 3 + 348));
@@ -288,7 +288,7 @@ static void test_string_int16_decoding(void **_CBOR_UNUSED(_state)) {
unsigned char string_int32_data[] = {0x7A, 0x00, 0x10, 0x10,
0x10 /*, [1052688 bytes] */};
-static void test_string_int32_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_string_int32_decoding(void** _state _CBOR_UNUSED) {
assert_string_mem_eq(string_int32_data + 5, 1052688);
assert_decoder_result(5 + 1052688, CBOR_DECODER_FINISHED,
decode(string_int32_data, 5 + 1052688));
@@ -302,7 +302,7 @@ static void test_string_int32_decoding(void **_CBOR_UNUSED(_state)) {
unsigned char string_int64_data[] = {
0x7B, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00 /*, [4294967296 bytes] */};
-static void test_string_int64_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_string_int64_decoding(void** _state _CBOR_UNUSED) {
assert_string_mem_eq(string_int64_data + 9, 4294967296);
assert_decoder_result(9 + 4294967296, CBOR_DECODER_FINISHED,
decode(string_int64_data, 9 + 4294967296));
@@ -314,7 +314,7 @@ static void test_string_int64_decoding(void **_CBOR_UNUSED(_state)) {
#endif
unsigned char string_indef_1_data[] = {0x7F, 0x60 /* Empty string */, 0xFF};
-static void test_string_indef_decoding_1(void **_CBOR_UNUSED(_state)) {
+static void test_string_indef_decoding_1(void** _state _CBOR_UNUSED) {
assert_string_indef_start();
assert_decoder_result(1, CBOR_DECODER_FINISHED,
decode(string_indef_1_data, 3));
@@ -329,7 +329,7 @@ static void test_string_indef_decoding_1(void **_CBOR_UNUSED(_state)) {
}
unsigned char string_indef_2_data[] = {0x7F, 0xFF};
-static void test_string_indef_decoding_2(void **_CBOR_UNUSED(_state)) {
+static void test_string_indef_decoding_2(void** _state _CBOR_UNUSED) {
assert_string_indef_start();
assert_decoder_result(1, CBOR_DECODER_FINISHED,
decode(string_indef_2_data, 2));
@@ -346,7 +346,7 @@ unsigned char string_indef_3_data[] = {0x7F,
0x78, 0x01, 0x00,
// Break
0xFF};
-static void test_string_indef_decoding_3(void **_CBOR_UNUSED(_state)) {
+static void test_string_indef_decoding_3(void** _state _CBOR_UNUSED) {
assert_string_indef_start();
assert_decoder_result(1, CBOR_DECODER_FINISHED,
decode(string_indef_3_data, 6));
@@ -365,14 +365,14 @@ static void test_string_indef_decoding_3(void **_CBOR_UNUSED(_state)) {
}
unsigned char array_embedded_int8_data[] = {0x80};
-static void test_array_embedded_int8_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_array_embedded_int8_decoding(void** _state _CBOR_UNUSED) {
assert_array_start(0);
assert_decoder_result(1, CBOR_DECODER_FINISHED,
decode(array_embedded_int8_data, 1));
}
unsigned char array_int8_data[] = {0x98, 0x02, 0x00, 0x01};
-static void test_array_int8_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_array_int8_decoding(void** _state _CBOR_UNUSED) {
assert_array_start(2);
assert_decoder_result(2, CBOR_DECODER_FINISHED, decode(array_int8_data, 4));
@@ -388,7 +388,7 @@ static void test_array_int8_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char array_int16_data[] = {0x99, 0x00, 0x02, 0x00, 0x01};
-static void test_array_int16_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_array_int16_decoding(void** _state _CBOR_UNUSED) {
assert_array_start(2);
assert_decoder_result(3, CBOR_DECODER_FINISHED, decode(array_int16_data, 5));
@@ -404,7 +404,7 @@ static void test_array_int16_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char array_int32_data[] = {0x9A, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01};
-static void test_array_int32_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_array_int32_decoding(void** _state _CBOR_UNUSED) {
assert_array_start(2);
assert_decoder_result(5, CBOR_DECODER_FINISHED, decode(array_int32_data, 7));
@@ -421,7 +421,7 @@ static void test_array_int32_decoding(void **_CBOR_UNUSED(_state)) {
unsigned char array_int64_data[] = {0x9B, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x02, 0x00, 0x01};
-static void test_array_int64_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_array_int64_decoding(void** _state _CBOR_UNUSED) {
assert_array_start(2);
assert_decoder_result(9, CBOR_DECODER_FINISHED, decode(array_int64_data, 11));
@@ -437,7 +437,7 @@ static void test_array_int64_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char array_of_arrays_data[] = {0x82, 0x80, 0x80};
-static void test_array_of_arrays_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_array_of_arrays_decoding(void** _state _CBOR_UNUSED) {
assert_array_start(2);
assert_decoder_result(1, CBOR_DECODER_FINISHED,
decode(array_of_arrays_data, 3));
@@ -452,7 +452,7 @@ static void test_array_of_arrays_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char indef_array_data_1[] = {0x9F, 0x00, 0x18, 0xFF, 0x9F, 0xFF, 0xFF};
-static void test_indef_array_decoding_1(void **_CBOR_UNUSED(_state)) {
+static void test_indef_array_decoding_1(void** _state _CBOR_UNUSED) {
assert_indef_array_start();
assert_decoder_result(1, CBOR_DECODER_FINISHED,
decode(indef_array_data_1, 7));
@@ -479,7 +479,7 @@ static void test_indef_array_decoding_1(void **_CBOR_UNUSED(_state)) {
}
unsigned char map_embedded_int8_data[] = {0xa1, 0x01, 0x00};
-static void test_map_embedded_int8_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_map_embedded_int8_decoding(void** _state _CBOR_UNUSED) {
assert_map_start(1);
assert_decoder_result(1, CBOR_DECODER_FINISHED,
decode(map_embedded_int8_data, 3));
@@ -494,7 +494,7 @@ static void test_map_embedded_int8_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char map_int8_data[] = {0xB8, 0x01, 0x00, 0x01};
-static void test_map_int8_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_map_int8_decoding(void** _state _CBOR_UNUSED) {
assert_map_start(1);
assert_decoder_result(2, CBOR_DECODER_FINISHED, decode(map_int8_data, 4));
@@ -508,7 +508,7 @@ static void test_map_int8_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char map_int16_data[] = {0xB9, 0x00, 0x01, 0x00, 0x01};
-static void test_map_int16_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_map_int16_decoding(void** _state _CBOR_UNUSED) {
assert_map_start(1);
assert_decoder_result(3, CBOR_DECODER_FINISHED, decode(map_int16_data, 5));
@@ -524,7 +524,7 @@ static void test_map_int16_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char map_int32_data[] = {0xBA, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01};
-static void test_map_int32_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_map_int32_decoding(void** _state _CBOR_UNUSED) {
assert_map_start(1);
assert_decoder_result(5, CBOR_DECODER_FINISHED, decode(map_int32_data, 7));
@@ -541,7 +541,7 @@ static void test_map_int32_decoding(void **_CBOR_UNUSED(_state)) {
unsigned char map_int64_data[] = {0xBB, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x01};
-static void test_map_int64_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_map_int64_decoding(void** _state _CBOR_UNUSED) {
assert_map_start(1);
assert_decoder_result(9, CBOR_DECODER_FINISHED, decode(map_int64_data, 11));
@@ -557,7 +557,7 @@ static void test_map_int64_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char indef_map_data_1[] = {0xBF, 0x00, 0x18, 0xFF, 0xFF};
-static void test_indef_map_decoding_1(void **_CBOR_UNUSED(_state)) {
+static void test_indef_map_decoding_1(void** _state _CBOR_UNUSED) {
assert_indef_map_start();
assert_decoder_result(1, CBOR_DECODER_FINISHED, decode(indef_map_data_1, 5));
@@ -575,13 +575,13 @@ static void test_indef_map_decoding_1(void **_CBOR_UNUSED(_state)) {
}
unsigned char embedded_tag_data[] = {0xC1};
-static void test_embedded_tag_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_embedded_tag_decoding(void** _state _CBOR_UNUSED) {
assert_tag_eq(1);
assert_decoder_result(1, CBOR_DECODER_FINISHED, decode(embedded_tag_data, 1));
}
unsigned char int8_tag_data[] = {0xD8, 0xFE};
-static void test_int8_tag_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_int8_tag_decoding(void** _state _CBOR_UNUSED) {
assert_tag_eq(254);
assert_decoder_result(2, CBOR_DECODER_FINISHED, decode(int8_tag_data, 2));
@@ -589,7 +589,7 @@ static void test_int8_tag_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char int16_tag_data[] = {0xD9, 0xFE, 0xFD};
-static void test_int16_tag_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_int16_tag_decoding(void** _state _CBOR_UNUSED) {
assert_tag_eq(65277);
assert_decoder_result(3, CBOR_DECODER_FINISHED, decode(int16_tag_data, 3));
@@ -597,7 +597,7 @@ static void test_int16_tag_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char int32_tag_data[] = {0xDA, 0xFE, 0xFD, 0xFC, 0xFB};
-static void test_int32_tag_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_int32_tag_decoding(void** _state _CBOR_UNUSED) {
assert_tag_eq(4278058235ULL);
assert_decoder_result(5, CBOR_DECODER_FINISHED, decode(int32_tag_data, 5));
@@ -606,7 +606,7 @@ static void test_int32_tag_decoding(void **_CBOR_UNUSED(_state)) {
unsigned char int64_tag_data[] = {0xDB, 0xFE, 0xFD, 0xFC, 0xFB,
0xFA, 0xF9, 0xF8, 0xF7};
-static void test_int64_tag_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_int64_tag_decoding(void** _state _CBOR_UNUSED) {
assert_tag_eq(18374120213919168759ULL);
assert_decoder_result(9, CBOR_DECODER_FINISHED, decode(int64_tag_data, 9));
@@ -614,12 +614,12 @@ static void test_int64_tag_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char reserved_byte_data[] = {0xDC};
-static void test_reserved_byte_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_reserved_byte_decoding(void** _state _CBOR_UNUSED) {
assert_decoder_result(0, CBOR_DECODER_ERROR, decode(reserved_byte_data, 1));
}
unsigned char float2_data[] = {0xF9, 0x7B, 0xFF};
-static void test_float2_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_float2_decoding(void** _state _CBOR_UNUSED) {
assert_half(65504.0f);
assert_decoder_result(3, CBOR_DECODER_FINISHED, decode(float2_data, 3));
@@ -627,7 +627,7 @@ static void test_float2_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char float4_data[] = {0xFA, 0x47, 0xC3, 0x50, 0x00};
-static void test_float4_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_float4_decoding(void** _state _CBOR_UNUSED) {
assert_float(100000.0f);
assert_decoder_result(5, CBOR_DECODER_FINISHED, decode(float4_data, 5));
@@ -636,7 +636,7 @@ static void test_float4_decoding(void **_CBOR_UNUSED(_state)) {
unsigned char float8_data[] = {0xFB, 0xC0, 0x10, 0x66, 0x66,
0x66, 0x66, 0x66, 0x66};
-static void test_float8_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_float8_decoding(void** _state _CBOR_UNUSED) {
assert_double(-4.1);
assert_decoder_result(9, CBOR_DECODER_FINISHED, decode(float8_data, 9));
@@ -644,25 +644,25 @@ static void test_float8_decoding(void **_CBOR_UNUSED(_state)) {
}
unsigned char false_data[] = {0xF4};
-static void test_false_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_false_decoding(void** _state _CBOR_UNUSED) {
assert_bool(false);
assert_decoder_result(1, CBOR_DECODER_FINISHED, decode(false_data, 1));
}
unsigned char true_data[] = {0xF5};
-static void test_true_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_true_decoding(void** _state _CBOR_UNUSED) {
assert_bool(true);
assert_decoder_result(1, CBOR_DECODER_FINISHED, decode(true_data, 1));
}
unsigned char null_data[] = {0xF6};
-static void test_null_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_null_decoding(void** _state _CBOR_UNUSED) {
assert_nil();
assert_decoder_result(1, CBOR_DECODER_FINISHED, decode(null_data, 1));
}
unsigned char undef_data[] = {0xF7};
-static void test_undef_decoding(void **_CBOR_UNUSED(_state)) {
+static void test_undef_decoding(void** _state _CBOR_UNUSED) {
assert_undef();
assert_decoder_result(1, CBOR_DECODER_FINISHED, decode(undef_data, 1));
}
diff --git a/test/copy_test.c b/test/copy_test.c
index 92e210a6a600..ef58fecd5a9f 100644
--- a/test/copy_test.c
+++ b/test/copy_test.c
@@ -11,7 +11,7 @@
cbor_item_t *item, *copy, *tmp;
-static void test_uints(void **_CBOR_UNUSED(_state)) {
+static void test_uints(void** _state _CBOR_UNUSED) {
item = cbor_build_uint8(10);
assert_uint8(copy = cbor_copy(item), 10);
cbor_decref(&item);
@@ -33,7 +33,7 @@ static void test_uints(void **_CBOR_UNUSED(_state)) {
cbor_decref(&copy);
}
-static void test_negints(void **_CBOR_UNUSED(_state)) {
+static void test_negints(void** _state _CBOR_UNUSED) {
item = cbor_build_negint8(10);
assert_true(cbor_get_uint8(copy = cbor_copy(item)) == 10);
cbor_decref(&item);
@@ -55,7 +55,7 @@ static void test_negints(void **_CBOR_UNUSED(_state)) {
cbor_decref(&copy);
}
-static void test_def_bytestring(void **_CBOR_UNUSED(_state)) {
+static void test_def_bytestring(void** _state _CBOR_UNUSED) {
item = cbor_build_bytestring((cbor_data) "abc", 3);
assert_memory_equal(cbor_bytestring_handle(copy = cbor_copy(item)),
cbor_bytestring_handle(item), 3);
@@ -63,7 +63,7 @@ static void test_def_bytestring(void **_CBOR_UNUSED(_state)) {
cbor_decref(&copy);
}
-static void test_indef_bytestring(void **_CBOR_UNUSED(_state)) {
+static void test_indef_bytestring(void** _state _CBOR_UNUSED) {
item = cbor_new_indefinite_bytestring();
assert_true(cbor_bytestring_add_chunk(
item, cbor_move(cbor_build_bytestring((cbor_data) "abc", 3))));
@@ -78,7 +78,7 @@ static void test_indef_bytestring(void **_CBOR_UNUSED(_state)) {
cbor_decref(&copy);
}
-static void test_def_string(void **_CBOR_UNUSED(_state)) {
+static void test_def_string(void** _state _CBOR_UNUSED) {
item = cbor_build_string("abc");
assert_memory_equal(cbor_string_handle(copy = cbor_copy(item)),
cbor_string_handle(item), 3);
@@ -86,7 +86,7 @@ static void test_def_string(void **_CBOR_UNUSED(_state)) {
cbor_decref(&copy);
}
-static void test_indef_string(void **_CBOR_UNUSED(_state)) {
+static void test_indef_string(void** _state _CBOR_UNUSED) {
item = cbor_new_indefinite_string();
assert_true(cbor_string_add_chunk(item, cbor_move(cbor_build_string("abc"))));
copy = cbor_copy(item);
@@ -100,7 +100,7 @@ static void test_indef_string(void **_CBOR_UNUSED(_state)) {
cbor_decref(&copy);
}
-static void test_def_array(void **_CBOR_UNUSED(_state)) {
+static void test_def_array(void** _state _CBOR_UNUSED) {
item = cbor_new_definite_array(1);
assert_true(cbor_array_push(item, cbor_move(cbor_build_uint8(42))));
@@ -110,7 +110,7 @@ static void test_def_array(void **_CBOR_UNUSED(_state)) {
cbor_decref(&tmp);
}
-static void test_indef_array(void **_CBOR_UNUSED(_state)) {
+static void test_indef_array(void** _state _CBOR_UNUSED) {
item = cbor_new_indefinite_array();
assert_true(cbor_array_push(item, cbor_move(cbor_build_uint8(42))));
@@ -120,7 +120,7 @@ static void test_indef_array(void **_CBOR_UNUSED(_state)) {
cbor_decref(&tmp);
}
-static void test_def_map(void **_CBOR_UNUSED(_state)) {
+static void test_def_map(void** _state _CBOR_UNUSED) {
item = cbor_new_definite_map(1);
assert_true(cbor_map_add(item, (struct cbor_pair){
.key = cbor_move(cbor_build_uint8(42)),
@@ -133,7 +133,7 @@ static void test_def_map(void **_CBOR_UNUSED(_state)) {
cbor_decref(&copy);
}
-static void test_indef_map(void **_CBOR_UNUSED(_state)) {
+static void test_indef_map(void** _state _CBOR_UNUSED) {
item = cbor_new_indefinite_map();
assert_true(cbor_map_add(item, (struct cbor_pair){
.key = cbor_move(cbor_build_uint8(42)),
@@ -146,7 +146,7 @@ static void test_indef_map(void **_CBOR_UNUSED(_state)) {
cbor_decref(&copy);
}
-static void test_tag(void **_CBOR_UNUSED(_state)) {
+static void test_tag(void** _state _CBOR_UNUSED) {
item = cbor_build_tag(10, cbor_move(cbor_build_uint8(42)));
assert_uint8(cbor_move(cbor_tag_item(copy = cbor_copy(item))), 42);
@@ -155,14 +155,14 @@ static void test_tag(void **_CBOR_UNUSED(_state)) {
cbor_decref(&copy);
}
-static void test_ctrls(void **_CBOR_UNUSED(_state)) {
+static void test_ctrls(void** _state _CBOR_UNUSED) {
item = cbor_new_null();
assert_true(cbor_is_null(copy = cbor_copy(item)));
cbor_decref(&item);
cbor_decref(&copy);
}
-static void test_floats(void **_CBOR_UNUSED(_state)) {
+static void test_floats(void** _state _CBOR_UNUSED) {
item = cbor_build_float2(3.14f);
assert_true(cbor_float_get_float2(copy = cbor_copy(item)) ==
cbor_float_get_float2(item));
@@ -182,7 +182,7 @@ static void test_floats(void **_CBOR_UNUSED(_state)) {
cbor_decref(&copy);
}
-static void test_alloc_failure_simple(void **_CBOR_UNUSED(_state)) {
+static void test_alloc_failure_simple(void** _state _CBOR_UNUSED) {
item = cbor_build_uint8(10);
WITH_FAILING_MALLOC({ assert_null(cbor_copy(item)); });
@@ -191,7 +191,7 @@ static void test_alloc_failure_simple(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_bytestring_alloc_failure(void **_CBOR_UNUSED(_state)) {
+static void test_bytestring_alloc_failure(void** _state _CBOR_UNUSED) {
item = cbor_new_indefinite_bytestring();
assert_true(cbor_bytestring_add_chunk(
item, cbor_move(cbor_build_bytestring((cbor_data) "abc", 3))));
@@ -202,7 +202,7 @@ static void test_bytestring_alloc_failure(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_bytestring_chunk_alloc_failure(void **_CBOR_UNUSED(_state)) {
+static void test_bytestring_chunk_alloc_failure(void** _state _CBOR_UNUSED) {
item = cbor_new_indefinite_bytestring();
assert_true(cbor_bytestring_add_chunk(
item, cbor_move(cbor_build_bytestring((cbor_data) "abc", 3))));
@@ -213,7 +213,7 @@ static void test_bytestring_chunk_alloc_failure(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_bytestring_chunk_append_failure(void **_CBOR_UNUSED(_state)) {
+static void test_bytestring_chunk_append_failure(void** _state _CBOR_UNUSED) {
item = cbor_new_indefinite_bytestring();
assert_true(cbor_bytestring_add_chunk(
item, cbor_move(cbor_build_bytestring((cbor_data) "abc", 3))));
@@ -228,7 +228,7 @@ static void test_bytestring_chunk_append_failure(void **_CBOR_UNUSED(_state)) {
}
static void test_bytestring_second_chunk_alloc_failure(
- void **_CBOR_UNUSED(_state)) {
+ void** _state _CBOR_UNUSED) {
item = cbor_new_indefinite_bytestring();
assert_true(cbor_bytestring_add_chunk(
item, cbor_move(cbor_build_bytestring((cbor_data) "abc", 3))));
@@ -245,7 +245,7 @@ static void test_bytestring_second_chunk_alloc_failure(
cbor_decref(&item);
}
-static void test_string_alloc_failure(void **_CBOR_UNUSED(_state)) {
+static void test_string_alloc_failure(void** _state _CBOR_UNUSED) {
item = cbor_new_indefinite_string();
assert_true(cbor_string_add_chunk(item, cbor_move(cbor_build_string("abc"))));
@@ -255,7 +255,7 @@ static void test_string_alloc_failure(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_string_chunk_alloc_failure(void **_CBOR_UNUSED(_state)) {
+static void test_string_chunk_alloc_failure(void** _state _CBOR_UNUSED) {
item = cbor_new_indefinite_string();
assert_true(cbor_string_add_chunk(item, cbor_move(cbor_build_string("abc"))));
@@ -265,7 +265,7 @@ static void test_string_chunk_alloc_failure(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_string_chunk_append_failure(void **_CBOR_UNUSED(_state)) {
+static void test_string_chunk_append_failure(void** _state _CBOR_UNUSED) {
item = cbor_new_indefinite_string();
assert_true(cbor_string_add_chunk(item, cbor_move(cbor_build_string("abc"))));
@@ -278,8 +278,7 @@ static void test_string_chunk_append_failure(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_string_second_chunk_alloc_failure(
- void **_CBOR_UNUSED(_state)) {
+static void test_string_second_chunk_alloc_failure(void** _state _CBOR_UNUSED) {
item = cbor_new_indefinite_string();
assert_true(cbor_string_add_chunk(item, cbor_move(cbor_build_string("abc"))));
assert_true(cbor_string_add_chunk(item, cbor_move(cbor_build_string("def"))));
@@ -294,7 +293,7 @@ static void test_string_second_chunk_alloc_failure(
cbor_decref(&item);
}
-static void test_array_alloc_failure(void **_CBOR_UNUSED(_state)) {
+static void test_array_alloc_failure(void** _state _CBOR_UNUSED) {
item = cbor_new_indefinite_array();
assert_true(cbor_array_push(item, cbor_move(cbor_build_uint8(42))));
@@ -304,7 +303,7 @@ static void test_array_alloc_failure(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_array_item_alloc_failure(void **_CBOR_UNUSED(_state)) {
+static void test_array_item_alloc_failure(void** _state _CBOR_UNUSED) {
item = cbor_new_indefinite_array();
assert_true(cbor_array_push(item, cbor_move(cbor_build_uint8(42))));
@@ -317,7 +316,7 @@ static void test_array_item_alloc_failure(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_array_push_failure(void **_CBOR_UNUSED(_state)) {
+static void test_array_push_failure(void** _state _CBOR_UNUSED) {
item = cbor_new_indefinite_array();
assert_true(cbor_array_push(item, cbor_move(cbor_build_uint8(42))));
@@ -330,7 +329,7 @@ static void test_array_push_failure(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_array_second_item_alloc_failure(void **_CBOR_UNUSED(_state)) {
+static void test_array_second_item_alloc_failure(void** _state _CBOR_UNUSED) {
item = cbor_new_indefinite_array();
assert_true(cbor_array_push(item, cbor_move(cbor_build_uint8(42))));
assert_true(cbor_array_push(item, cbor_move(cbor_build_uint8(43))));
@@ -344,7 +343,7 @@ static void test_array_second_item_alloc_failure(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_map_alloc_failure(void **_CBOR_UNUSED(_state)) {
+static void test_map_alloc_failure(void** _state _CBOR_UNUSED) {
item = cbor_new_indefinite_map();
assert_true(
cbor_map_add(item, (struct cbor_pair){cbor_move(cbor_build_uint8(42)),
@@ -356,7 +355,7 @@ static void test_map_alloc_failure(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_map_key_alloc_failure(void **_CBOR_UNUSED(_state)) {
+static void test_map_key_alloc_failure(void** _state _CBOR_UNUSED) {
item = cbor_new_indefinite_map();
assert_true(
cbor_map_add(item, (struct cbor_pair){cbor_move(cbor_build_uint8(42)),
@@ -370,7 +369,7 @@ static void test_map_key_alloc_failure(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_map_value_alloc_failure(void **_CBOR_UNUSED(_state)) {
+static void test_map_value_alloc_failure(void** _state _CBOR_UNUSED) {
item = cbor_new_indefinite_map();
assert_true(
cbor_map_add(item, (struct cbor_pair){cbor_move(cbor_build_uint8(42)),
@@ -384,7 +383,7 @@ static void test_map_value_alloc_failure(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_map_add_failure(void **_CBOR_UNUSED(_state)) {
+static void test_map_add_failure(void** _state _CBOR_UNUSED) {
item = cbor_new_indefinite_map();
assert_true(
cbor_map_add(item, (struct cbor_pair){cbor_move(cbor_build_uint8(42)),
@@ -398,7 +397,7 @@ static void test_map_add_failure(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_map_second_key_failure(void **_CBOR_UNUSED(_state)) {
+static void test_map_second_key_failure(void** _state _CBOR_UNUSED) {
item = cbor_new_indefinite_map();
assert_true(
cbor_map_add(item, (struct cbor_pair){cbor_move(cbor_build_uint8(42)),
@@ -415,7 +414,7 @@ static void test_map_second_key_failure(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_tag_item_alloc_failure(void **_CBOR_UNUSED(_state)) {
+static void test_tag_item_alloc_failure(void** _state _CBOR_UNUSED) {
item = cbor_build_tag(1, cbor_move(cbor_build_uint8(42)));
WITH_FAILING_MALLOC({ assert_null(cbor_copy(item)); });
@@ -424,7 +423,7 @@ static void test_tag_item_alloc_failure(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_tag_alloc_failure(void **_CBOR_UNUSED(_state)) {
+static void test_tag_alloc_failure(void** _state _CBOR_UNUSED) {
item = cbor_build_tag(1, cbor_move(cbor_build_uint8(42)));
WITH_MOCK_MALLOC({ assert_null(cbor_copy(item)); }, 2,
diff --git a/test/float_ctrl_encoders_test.c b/test/float_ctrl_encoders_test.c
index 8940106d91d3..f7d302472666 100644
--- a/test/float_ctrl_encoders_test.c
+++ b/test/float_ctrl_encoders_test.c
@@ -11,24 +11,24 @@
unsigned char buffer[512];
-static void test_bools(void **_CBOR_UNUSED(_state)) {
+static void test_bools(void** _state _CBOR_UNUSED) {
assert_size_equal(1, cbor_encode_bool(false, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0xF4}), 1);
assert_size_equal(1, cbor_encode_bool(true, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0xF5}), 1);
}
-static void test_null(void **_CBOR_UNUSED(_state)) {
+static void test_null(void** _state _CBOR_UNUSED) {
assert_size_equal(1, cbor_encode_null(buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0xF6}), 1);
}
-static void test_undef(void **_CBOR_UNUSED(_state)) {
+static void test_undef(void** _state _CBOR_UNUSED) {
assert_size_equal(1, cbor_encode_undef(buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0xF7}), 1);
}
-static void test_break(void **_CBOR_UNUSED(_state)) {
+static void test_break(void** _state _CBOR_UNUSED) {
assert_size_equal(1, cbor_encode_break(buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0xFF}), 1);
}
@@ -39,7 +39,7 @@ static void assert_half_float_codec_identity(void) {
unsigned char secondary_buffer[3];
struct cbor_load_result res;
// Load and check data in buffer
- cbor_item_t *half_float = cbor_load(buffer, 3, &res);
+ cbor_item_t* half_float = cbor_load(buffer, 3, &res);
assert_size_equal(res.error.code, CBOR_ERR_NONE);
assert_true(cbor_isa_float_ctrl(half_float));
assert_true(cbor_is_float(half_float));
@@ -51,7 +51,7 @@ static void assert_half_float_codec_identity(void) {
cbor_decref(&half_float);
}
-static void test_half(void **_CBOR_UNUSED(_state)) {
+static void test_half(void** _state _CBOR_UNUSED) {
assert_size_equal(3, cbor_encode_half(1.5f, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0xF9, 0x3E, 0x00}), 3);
assert_half_float_codec_identity();
@@ -117,21 +117,17 @@ static void test_half(void **_CBOR_UNUSED(_state)) {
assert_half_float_codec_identity();
}
-static void test_half_special(void **_CBOR_UNUSED(_state)) {
+static void test_half_special(void** _state _CBOR_UNUSED) {
assert_size_equal(3, cbor_encode_half(NAN, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0xF9, 0x7E, 0x00}), 3);
assert_half_float_codec_identity();
- // We discard all information bits in half-float NaNs. This is
- // not required for the core CBOR protocol (it is only a suggestion in
- // Section 3.9).
- // See https://github.com/PJK/libcbor/issues/215
assert_size_equal(3, cbor_encode_half(nanf("2"), buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0xF9, 0x7E, 0x00}), 3);
assert_half_float_codec_identity();
}
-static void test_half_infinity(void **_CBOR_UNUSED(_state)) {
+static void test_half_infinity(void** _state _CBOR_UNUSED) {
assert_size_equal(3, cbor_encode_half(INFINITY, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0xF9, 0x7C, 0x00}), 3);
assert_half_float_codec_identity();
@@ -141,7 +137,7 @@ static void test_half_infinity(void **_CBOR_UNUSED(_state)) {
assert_half_float_codec_identity();
}
-static void test_float(void **_CBOR_UNUSED(_state)) {
+static void test_float(void** _state _CBOR_UNUSED) {
assert_size_equal(5, cbor_encode_single(3.4028234663852886e+38, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0xFA, 0x7F, 0x7F, 0xFF, 0xFF}),
5);
@@ -150,12 +146,9 @@ static void test_float(void **_CBOR_UNUSED(_state)) {
assert_memory_equal(buffer, ((unsigned char[]){0xFA, 0x7F, 0xC0, 0x00, 0x00}),
5);
-#ifndef _WIN32
- // TODO: https://github.com/PJK/libcbor/issues/271
assert_size_equal(5, cbor_encode_single(nanf("3"), buffer, 512));
- assert_memory_equal(buffer, ((unsigned char[]){0xFA, 0x7F, 0xC0, 0x00, 0x03}),
+ assert_memory_equal(buffer, ((unsigned char[]){0xFA, 0x7F, 0xC0, 0x00, 0x00}),
5);
-#endif
assert_size_equal(5, cbor_encode_single(strtof("Inf", NULL), buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0xFA, 0x7F, 0x80, 0x00, 0x00}),
@@ -166,7 +159,7 @@ static void test_float(void **_CBOR_UNUSED(_state)) {
5);
}
-static void test_double(void **_CBOR_UNUSED(_state)) {
+static void test_double(void** _state _CBOR_UNUSED) {
assert_size_equal(9, cbor_encode_double(1.0e+300, buffer, 512));
assert_memory_equal(
buffer,
@@ -179,14 +172,11 @@ static void test_double(void **_CBOR_UNUSED(_state)) {
((unsigned char[]){0xFB, 0x7F, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}),
9);
-#ifndef _WIN32
- // TODO: https://github.com/PJK/libcbor/issues/271
assert_size_equal(9, cbor_encode_double(nan("3"), buffer, 512));
assert_memory_equal(
buffer,
- ((unsigned char[]){0xFB, 0x7F, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03}),
+ ((unsigned char[]){0xFB, 0x7F, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}),
9);
-#endif
assert_size_equal(9, cbor_encode_double(strtod("Inf", NULL), buffer, 512));
assert_memory_equal(
diff --git a/test/float_ctrl_test.c b/test/float_ctrl_test.c
index c939486877e7..927bf567bdc3 100644
--- a/test/float_ctrl_test.c
+++ b/test/float_ctrl_test.c
@@ -17,14 +17,14 @@
#include "cbor.h"
#include "test_allocator.h"
-cbor_item_t *float_ctrl;
+cbor_item_t* float_ctrl;
struct cbor_load_result res;
static const float eps = 0.00001f;
unsigned char float2_data[] = {0xF9, 0x7B, 0xFF};
-static void test_float2(void **_CBOR_UNUSED(_state)) {
+static void test_float2(void** _state _CBOR_UNUSED) {
float_ctrl = cbor_load(float2_data, 3, &res);
assert_true(cbor_isa_float_ctrl(float_ctrl));
assert_true(cbor_is_float(float_ctrl));
@@ -37,7 +37,7 @@ static void test_float2(void **_CBOR_UNUSED(_state)) {
unsigned char float4_data[] = {0xFA, 0x47, 0xC3, 0x50, 0x00};
-static void test_float4(void **_CBOR_UNUSED(_state)) {
+static void test_float4(void** _state _CBOR_UNUSED) {
float_ctrl = cbor_load(float4_data, 5, &res);
assert_true(cbor_isa_float_ctrl(float_ctrl));
assert_true(cbor_is_float(float_ctrl));
@@ -51,7 +51,7 @@ static void test_float4(void **_CBOR_UNUSED(_state)) {
unsigned char float8_data[] = {0xFB, 0x7E, 0x37, 0xE4, 0x3C,
0x88, 0x00, 0x75, 0x9C};
-static void test_float8(void **_CBOR_UNUSED(_state)) {
+static void test_float8(void** _state _CBOR_UNUSED) {
float_ctrl = cbor_load(float8_data, 9, &res);
assert_true(cbor_isa_float_ctrl(float_ctrl));
assert_true(cbor_is_float(float_ctrl));
@@ -66,7 +66,7 @@ static void test_float8(void **_CBOR_UNUSED(_state)) {
unsigned char null_data[] = {0xF6};
-static void test_null(void **_CBOR_UNUSED(_state)) {
+static void test_null(void** _state _CBOR_UNUSED) {
float_ctrl = cbor_load(null_data, 1, &res);
assert_true(cbor_isa_float_ctrl(float_ctrl));
assert_true(cbor_is_null(float_ctrl));
@@ -76,7 +76,7 @@ static void test_null(void **_CBOR_UNUSED(_state)) {
unsigned char undef_data[] = {0xF7};
-static void test_undef(void **_CBOR_UNUSED(_state)) {
+static void test_undef(void** _state _CBOR_UNUSED) {
float_ctrl = cbor_load(undef_data, 1, &res);
assert_true(cbor_isa_float_ctrl(float_ctrl));
assert_true(cbor_is_undef(float_ctrl));
@@ -86,7 +86,7 @@ static void test_undef(void **_CBOR_UNUSED(_state)) {
unsigned char bool_data[] = {0xF4, 0xF5};
-static void test_bool(void **_CBOR_UNUSED(_state)) {
+static void test_bool(void** _state _CBOR_UNUSED) {
_CBOR_TEST_DISABLE_ASSERT({
float_ctrl = cbor_load(bool_data, 1, &res);
assert_true(cbor_isa_float_ctrl(float_ctrl));
@@ -110,7 +110,7 @@ static void test_bool(void **_CBOR_UNUSED(_state)) {
});
}
-static void test_float_ctrl_creation(void **_CBOR_UNUSED(_state)) {
+static void test_float_ctrl_creation(void** _state _CBOR_UNUSED) {
WITH_FAILING_MALLOC({ assert_null(cbor_new_ctrl()); });
WITH_FAILING_MALLOC({ assert_null(cbor_new_float2()); });
WITH_FAILING_MALLOC({ assert_null(cbor_new_float4()); });
@@ -119,8 +119,8 @@ static void test_float_ctrl_creation(void **_CBOR_UNUSED(_state)) {
WITH_FAILING_MALLOC({ assert_null(cbor_new_undef()); });
WITH_FAILING_MALLOC({ assert_null(cbor_build_bool(false)); });
- WITH_FAILING_MALLOC({ assert_null(cbor_build_float2(3.14)); });
- WITH_FAILING_MALLOC({ assert_null(cbor_build_float4(3.14)); });
+ WITH_FAILING_MALLOC({ assert_null(cbor_build_float2(3.14f)); });
+ WITH_FAILING_MALLOC({ assert_null(cbor_build_float4(3.14f)); });
WITH_FAILING_MALLOC({ assert_null(cbor_build_float8(3.14)); });
WITH_FAILING_MALLOC({ assert_null(cbor_build_ctrl(0xAF)); });
}
diff --git a/test/fuzz_test.c b/test/fuzz_test.c
index a02ed7ea9287..5effadd64774 100644
--- a/test/fuzz_test.c
+++ b/test/fuzz_test.c
@@ -18,7 +18,7 @@
#endif
#ifdef PRINT_FUZZ
-static void printmem(const unsigned char *ptr, size_t length) {
+static void printmem(const unsigned char* ptr, size_t length) {
for (size_t i = 0; i < length; i++) printf("%02X", ptr[i]);
printf("\n");
}
@@ -26,7 +26,7 @@ static void printmem(const unsigned char *ptr, size_t length) {
unsigned seed;
-void *mock_malloc(size_t size) {
+void* mock_malloc(size_t size) {
if (size > (1 << 19))
return NULL;
else
@@ -34,11 +34,11 @@ void *mock_malloc(size_t size) {
}
static void run_round(void) {
- cbor_item_t *item;
+ cbor_item_t* item;
struct cbor_load_result res;
size_t length = rand() % MAXLEN + 1;
- unsigned char *data = malloc(length);
+ unsigned char* data = malloc(length);
for (size_t i = 0; i < length; i++) {
data[i] = rand() % 0xFF;
}
@@ -55,7 +55,7 @@ static void run_round(void) {
free(data);
}
-static void fuzz(void **_CBOR_UNUSED(_state)) {
+static void fuzz(void** _state _CBOR_UNUSED) {
cbor_set_allocs(mock_malloc, realloc, free);
printf("Fuzzing %llu rounds of up to %llu bytes with seed %u\n", ROUNDS,
MAXLEN, seed);
@@ -67,7 +67,7 @@ static void fuzz(void **_CBOR_UNUSED(_state)) {
(ROUNDS * MAXLEN) / 1024);
}
-int main(int argc, char *argv[]) {
+int main(int argc, char* argv[]) {
if (argc > 1)
seed = (unsigned)strtoul(argv[1], NULL, 10);
else
diff --git a/test/map_encoders_test.c b/test/map_encoders_test.c
index bbb5fdc1ad91..40cfe33631ed 100644
--- a/test/map_encoders_test.c
+++ b/test/map_encoders_test.c
@@ -10,18 +10,18 @@
unsigned char buffer[512];
-static void test_embedded_map_start(void **_CBOR_UNUSED(_state)) {
+static void test_embedded_map_start(void** _state _CBOR_UNUSED) {
assert_size_equal(1, cbor_encode_map_start(1, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0xA1}), 1);
}
-static void test_map_start(void **_CBOR_UNUSED(_state)) {
+static void test_map_start(void** _state _CBOR_UNUSED) {
assert_size_equal(5, cbor_encode_map_start(1000000, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0xBA, 0x00, 0x0F, 0x42, 0x40}),
5);
}
-static void test_indef_map_start(void **_CBOR_UNUSED(_state)) {
+static void test_indef_map_start(void** _state _CBOR_UNUSED) {
assert_size_equal(1, cbor_encode_indef_map_start(buffer, 512));
assert_size_equal(0, cbor_encode_indef_map_start(buffer, 0));
assert_memory_equal(buffer, ((unsigned char[]){0xBF}), 1);
diff --git a/test/map_test.c b/test/map_test.c
index 11bd7a8d7242..3c41456079a0 100644
--- a/test/map_test.c
+++ b/test/map_test.c
@@ -17,12 +17,12 @@
#include "cbor.h"
#include "test_allocator.h"
-cbor_item_t *map;
+cbor_item_t* map;
struct cbor_load_result res;
unsigned char empty_map[] = {0xA0};
-static void test_empty_map(void **_CBOR_UNUSED(_state)) {
+static void test_empty_map(void** _state _CBOR_UNUSED) {
map = cbor_load(empty_map, 1, &res);
assert_non_null(map);
assert_true(cbor_typeof(map) == CBOR_TYPE_MAP);
@@ -37,7 +37,7 @@ static void test_empty_map(void **_CBOR_UNUSED(_state)) {
unsigned char simple_map[] = {0xA2, 0x01, 0x02, 0x03, 0x04};
/* {1: 2, 3: 4} */
-static void test_simple_map(void **_CBOR_UNUSED(_state)) {
+static void test_simple_map(void** _state _CBOR_UNUSED) {
map = cbor_load(simple_map, 5, &res);
assert_non_null(map);
assert_true(cbor_typeof(map) == CBOR_TYPE_MAP);
@@ -45,7 +45,7 @@ static void test_simple_map(void **_CBOR_UNUSED(_state)) {
assert_true(cbor_map_is_definite(map));
assert_true(cbor_map_size(map) == 2);
assert_true(res.read == 5);
- struct cbor_pair *handle = cbor_map_handle(map);
+ struct cbor_pair* handle = cbor_map_handle(map);
assert_uint8(handle[0].key, 1);
assert_uint8(handle[0].value, 2);
assert_uint8(handle[1].key, 3);
@@ -57,7 +57,7 @@ static void test_simple_map(void **_CBOR_UNUSED(_state)) {
unsigned char simple_indef_map[] = {0xBF, 0x01, 0x02, 0x03, 0x04, 0xFF};
/* {_ 1: 2, 3: 4} */
-static void test_indef_simple_map(void **_CBOR_UNUSED(_state)) {
+static void test_indef_simple_map(void** _state _CBOR_UNUSED) {
map = cbor_load(simple_indef_map, 6, &res);
assert_non_null(map);
assert_true(cbor_typeof(map) == CBOR_TYPE_MAP);
@@ -65,7 +65,7 @@ static void test_indef_simple_map(void **_CBOR_UNUSED(_state)) {
assert_true(cbor_map_is_indefinite(map));
assert_true(cbor_map_size(map) == 2);
assert_true(res.read == 6);
- struct cbor_pair *handle = cbor_map_handle(map);
+ struct cbor_pair* handle = cbor_map_handle(map);
assert_uint8(handle[0].key, 1);
assert_uint8(handle[0].value, 2);
assert_uint8(handle[1].key, 3);
@@ -84,7 +84,7 @@ unsigned char def_nested_map[] = {
0x74, 0x69, 0x74, 0x6C, 0x65, 0x70, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C,
0x65, 0x20, 0x67, 0x6C, 0x6F, 0x73, 0x73, 0x61, 0x72, 0x79};
-static void test_def_nested_map(void **_CBOR_UNUSED(_state)) {
+static void test_def_nested_map(void** _state _CBOR_UNUSED) {
map = cbor_load(def_nested_map, 34, &res);
assert_non_null(map);
assert_true(cbor_typeof(map) == CBOR_TYPE_MAP);
@@ -92,10 +92,10 @@ static void test_def_nested_map(void **_CBOR_UNUSED(_state)) {
assert_true(cbor_map_is_definite(map));
assert_true(cbor_map_size(map) == 1);
assert_true(res.read == 34);
- struct cbor_pair *handle = cbor_map_handle(map);
+ struct cbor_pair* handle = cbor_map_handle(map);
assert_true(cbor_typeof(handle[0].key) == CBOR_TYPE_STRING);
assert_true(cbor_typeof(handle[0].value) == CBOR_TYPE_MAP);
- struct cbor_pair *inner_handle = cbor_map_handle(handle[0].value);
+ struct cbor_pair* inner_handle = cbor_map_handle(handle[0].value);
assert_true(cbor_typeof(inner_handle[0].key) == CBOR_TYPE_STRING);
assert_true(cbor_typeof(inner_handle[0].value) == CBOR_TYPE_STRING);
assert_memory_equal(cbor_string_handle(inner_handle[0].value),
@@ -108,7 +108,7 @@ unsigned char streamed_key_map[] = {0xA1, 0x7F, 0x61, 0x61,
0x61, 0x62, 0xFF, 0xA0};
/* '{ (_"a" "b"): {}}' */
-static void test_streamed_key_map(void **_CBOR_UNUSED(_state)) {
+static void test_streamed_key_map(void** _state _CBOR_UNUSED) {
map = cbor_load(streamed_key_map, 8, &res);
assert_non_null(map);
assert_true(cbor_typeof(map) == CBOR_TYPE_MAP);
@@ -116,7 +116,7 @@ static void test_streamed_key_map(void **_CBOR_UNUSED(_state)) {
assert_true(cbor_map_is_definite(map));
assert_true(cbor_map_size(map) == 1);
assert_true(res.read == 8);
- struct cbor_pair *handle = cbor_map_handle(map);
+ struct cbor_pair* handle = cbor_map_handle(map);
assert_true(cbor_typeof(handle[0].key) == CBOR_TYPE_STRING);
assert_true(cbor_string_is_indefinite(handle[0].key));
assert_size_equal(cbor_string_chunk_count(handle[0].key), 2);
@@ -130,7 +130,7 @@ unsigned char streamed_kv_map[] = {0xA1, 0x7F, 0x61, 0x61, 0x61, 0x62, 0xFF,
0x7F, 0x61, 0x63, 0x61, 0x64, 0xFF};
/* '{ (_"a" "b"): (_"c", "d")}' */
-static void test_streamed_kv_map(void **_CBOR_UNUSED(_state)) {
+static void test_streamed_kv_map(void** _state _CBOR_UNUSED) {
map = cbor_load(streamed_kv_map, 13, &res);
assert_non_null(map);
assert_true(cbor_typeof(map) == CBOR_TYPE_MAP);
@@ -138,7 +138,7 @@ static void test_streamed_kv_map(void **_CBOR_UNUSED(_state)) {
assert_true(cbor_map_is_definite(map));
assert_size_equal(cbor_map_size(map), 1);
assert_size_equal(res.read, 13);
- struct cbor_pair *handle = cbor_map_handle(map);
+ struct cbor_pair* handle = cbor_map_handle(map);
assert_true(cbor_typeof(handle[0].key) == CBOR_TYPE_STRING);
assert_true(cbor_string_is_indefinite(handle[0].key));
assert_size_equal(cbor_string_chunk_count(handle[0].key), 2);
@@ -157,7 +157,7 @@ unsigned char streamed_streamed_kv_map[] = {0xBF, 0x7F, 0x61, 0x61, 0x61,
0x61, 0x64, 0xFF, 0xFF};
/* '{_ (_"a" "b"): (_"c", "d")}' */
-static void test_streamed_streamed_kv_map(void **_CBOR_UNUSED(_state)) {
+static void test_streamed_streamed_kv_map(void** _state _CBOR_UNUSED) {
map = cbor_load(streamed_streamed_kv_map, 14, &res);
assert_non_null(map);
assert_true(cbor_typeof(map) == CBOR_TYPE_MAP);
@@ -165,7 +165,7 @@ static void test_streamed_streamed_kv_map(void **_CBOR_UNUSED(_state)) {
assert_true(cbor_map_is_indefinite(map));
assert_size_equal(cbor_map_size(map), 1);
assert_size_equal(res.read, 14);
- struct cbor_pair *handle = cbor_map_handle(map);
+ struct cbor_pair* handle = cbor_map_handle(map);
assert_true(cbor_typeof(handle[0].key) == CBOR_TYPE_STRING);
assert_true(cbor_string_is_indefinite(handle[0].key));
assert_size_equal(cbor_string_chunk_count(handle[0].key), 2);
@@ -179,10 +179,10 @@ static void test_streamed_streamed_kv_map(void **_CBOR_UNUSED(_state)) {
assert_null(map);
}
-static void test_map_add_full(void **_CBOR_UNUSED(_state)) {
+static void test_map_add_full(void** _state _CBOR_UNUSED) {
map = cbor_new_definite_map(0);
- cbor_item_t *one = cbor_build_uint8(1);
- cbor_item_t *two = cbor_build_uint8(2);
+ cbor_item_t* one = cbor_build_uint8(1);
+ cbor_item_t* two = cbor_build_uint8(2);
assert_false(cbor_map_add(map, (struct cbor_pair){.key = one, .value = two}));
@@ -191,15 +191,15 @@ static void test_map_add_full(void **_CBOR_UNUSED(_state)) {
cbor_decref(&two);
}
-static void test_map_add_too_big_to_realloc(void **_CBOR_UNUSED(_state)) {
+static void test_map_add_too_big_to_realloc(void** _state _CBOR_UNUSED) {
map = cbor_new_indefinite_map();
- struct _cbor_map_metadata *metadata =
- (struct _cbor_map_metadata *)&map->metadata;
+ struct _cbor_map_metadata* metadata =
+ (struct _cbor_map_metadata*)&map->metadata;
// Pretend we already have a huge memory block
metadata->allocated = SIZE_MAX;
metadata->end_ptr = SIZE_MAX;
- cbor_item_t *one = cbor_build_uint8(1);
- cbor_item_t *two = cbor_build_uint8(2);
+ cbor_item_t* one = cbor_build_uint8(1);
+ cbor_item_t* two = cbor_build_uint8(2);
assert_false(cbor_map_add(map, (struct cbor_pair){.key = one, .value = two}));
@@ -210,7 +210,7 @@ static void test_map_add_too_big_to_realloc(void **_CBOR_UNUSED(_state)) {
cbor_decref(&two);
}
-static void test_map_creation(void **_CBOR_UNUSED(_state)) {
+static void test_map_creation(void** _state _CBOR_UNUSED) {
WITH_FAILING_MALLOC({ assert_null(cbor_new_definite_map(42)); });
WITH_MOCK_MALLOC({ assert_null(cbor_new_definite_map(42)); }, 2, MALLOC,
MALLOC_FAIL);
@@ -218,12 +218,12 @@ static void test_map_creation(void **_CBOR_UNUSED(_state)) {
WITH_FAILING_MALLOC({ assert_null(cbor_new_indefinite_map()); });
}
-static void test_map_add(void **_CBOR_UNUSED(_state)) {
+static void test_map_add(void** _state _CBOR_UNUSED) {
WITH_MOCK_MALLOC(
{
- cbor_item_t *map = cbor_new_indefinite_map();
- cbor_item_t *key = cbor_build_uint8(0);
- cbor_item_t *value = cbor_build_bool(true);
+ cbor_item_t* map = cbor_new_indefinite_map();
+ cbor_item_t* key = cbor_build_uint8(0);
+ cbor_item_t* value = cbor_build_bool(true);
assert_false(
cbor_map_add(map, (struct cbor_pair){.key = key, .value = value}));
@@ -238,10 +238,10 @@ static void test_map_add(void **_CBOR_UNUSED(_state)) {
}
static unsigned char test_indef_map[] = {0xBF, 0x01, 0x02, 0x03, 0x04, 0xFF};
-static void test_indef_map_decode(void **_CBOR_UNUSED(_state)) {
+static void test_indef_map_decode(void** _state _CBOR_UNUSED) {
WITH_MOCK_MALLOC(
{
- cbor_item_t *map;
+ cbor_item_t* map;
struct cbor_load_result res;
map = cbor_load(test_indef_map, 6, &res);
diff --git a/test/memory_utils_test.c b/test/memory_utils_test.c
index 6cf07c7da934..e10551c7b502 100644
--- a/test/memory_utils_test.c
+++ b/test/memory_utils_test.c
@@ -9,7 +9,7 @@
#include <string.h>
#include "assertions.h"
-static void test_safe_multiply(void **_CBOR_UNUSED(_state)) {
+static void test_safe_multiply(void** _state _CBOR_UNUSED) {
assert_true(_cbor_safe_to_multiply(1, 1));
assert_true(_cbor_safe_to_multiply(SIZE_MAX, 0));
assert_true(_cbor_safe_to_multiply(SIZE_MAX, 1));
@@ -17,7 +17,7 @@ static void test_safe_multiply(void **_CBOR_UNUSED(_state)) {
assert_false(_cbor_safe_to_multiply(SIZE_MAX, SIZE_MAX));
}
-static void test_safe_add(void **_CBOR_UNUSED(_state)) {
+static void test_safe_add(void** _state _CBOR_UNUSED) {
assert_true(_cbor_safe_to_add(1, 1));
assert_true(_cbor_safe_to_add(SIZE_MAX - 1, 1));
assert_true(_cbor_safe_to_add(SIZE_MAX, 0));
@@ -28,7 +28,7 @@ static void test_safe_add(void **_CBOR_UNUSED(_state)) {
assert_false(_cbor_safe_to_add(SIZE_MAX - 1, SIZE_MAX - 1));
}
-static void test_safe_signalling_add(void **_CBOR_UNUSED(_state)) {
+static void test_safe_signalling_add(void** _state _CBOR_UNUSED) {
assert_size_equal(_cbor_safe_signaling_add(1, 2), 3);
assert_size_equal(_cbor_safe_signaling_add(0, 1), 0);
assert_size_equal(_cbor_safe_signaling_add(0, SIZE_MAX), 0);
@@ -36,8 +36,8 @@ static void test_safe_signalling_add(void **_CBOR_UNUSED(_state)) {
assert_size_equal(_cbor_safe_signaling_add(1, SIZE_MAX - 1), SIZE_MAX);
}
-static void test_realloc_multiple(void **_CBOR_UNUSED(_state)) {
- unsigned char *data = malloc(1);
+static void test_realloc_multiple(void** _state _CBOR_UNUSED) {
+ unsigned char* data = malloc(1);
data[0] = 0x2a;
data = _cbor_realloc_multiple(data, /*item_size=*/1, /*item_count=*/10);
diff --git a/test/negint_encoders_test.c b/test/negint_encoders_test.c
index e9230fbe42ae..f4e52c8c37d0 100644
--- a/test/negint_encoders_test.c
+++ b/test/negint_encoders_test.c
@@ -10,31 +10,31 @@
unsigned char buffer[512];
-static void test_embedded_negint8(void **_CBOR_UNUSED(_state)) {
+static void test_embedded_negint8(void** _state _CBOR_UNUSED) {
assert_size_equal(1, cbor_encode_negint8(14, buffer, 512));
assert_memory_equal(buffer, (unsigned char[]){0x2E}, 1);
}
-static void test_negint8(void **_CBOR_UNUSED(_state)) {
+static void test_negint8(void** _state _CBOR_UNUSED) {
assert_size_equal(0, cbor_encode_negint8(180, buffer, 1));
assert_size_equal(2, cbor_encode_negint8(255, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0x38, 0xFF}), 2);
}
-static void test_negint16(void **_CBOR_UNUSED(_state)) {
+static void test_negint16(void** _state _CBOR_UNUSED) {
assert_size_equal(0, cbor_encode_negint16(1000, buffer, 2));
assert_size_equal(3, cbor_encode_negint16(1000, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0x39, 0x03, 0xE8}), 3);
}
-static void test_negint32(void **_CBOR_UNUSED(_state)) {
+static void test_negint32(void** _state _CBOR_UNUSED) {
assert_size_equal(0, cbor_encode_negint32(1000000, buffer, 4));
assert_size_equal(5, cbor_encode_negint32(1000000, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0x3A, 0x00, 0x0F, 0x42, 0x40}),
5);
}
-static void test_negint64(void **_CBOR_UNUSED(_state)) {
+static void test_negint64(void** _state _CBOR_UNUSED) {
assert_size_equal(0,
cbor_encode_negint64(18446744073709551615ULL, buffer, 8));
assert_size_equal(9,
@@ -45,7 +45,7 @@ static void test_negint64(void **_CBOR_UNUSED(_state)) {
9);
}
-static void test_unspecified(void **_CBOR_UNUSED(_state)) {
+static void test_unspecified(void** _state _CBOR_UNUSED) {
assert_size_equal(9,
cbor_encode_negint(18446744073709551615ULL, buffer, 512));
assert_memory_equal(
diff --git a/test/negint_test.c b/test/negint_test.c
index 66e7445b7f23..1df7d53fd526 100644
--- a/test/negint_test.c
+++ b/test/negint_test.c
@@ -9,7 +9,7 @@
#include "cbor.h"
#include "test_allocator.h"
-cbor_item_t *number;
+cbor_item_t* number;
struct cbor_load_result res;
unsigned char data1[] = {0x22, 0xFF};
@@ -19,7 +19,7 @@ unsigned char data4[] = {0x3a, 0xa5, 0xf7, 0x02, 0xb3, 0xFF};
unsigned char data5[] = {0x3b, 0xa5, 0xf7, 0x02, 0xb3,
0xa5, 0xf7, 0x02, 0xb3, 0xFF};
-static void test_very_short_int(void **_CBOR_UNUSED(_state)) {
+static void test_very_short_int(void** _state _CBOR_UNUSED) {
number = cbor_load(data1, 2, &res);
assert_true(cbor_typeof(number) == CBOR_TYPE_NEGINT);
assert_true(cbor_int_get_width(number) == CBOR_INT_8);
@@ -33,7 +33,7 @@ static void test_very_short_int(void **_CBOR_UNUSED(_state)) {
assert_null(number);
}
-static void test_short_int(void **_CBOR_UNUSED(_state)) {
+static void test_short_int(void** _state _CBOR_UNUSED) {
number = cbor_load(data2, 3, &res);
assert_true(cbor_typeof(number) == CBOR_TYPE_NEGINT);
assert_true(cbor_int_get_width(number) == CBOR_INT_8);
@@ -47,7 +47,7 @@ static void test_short_int(void **_CBOR_UNUSED(_state)) {
assert_null(number);
}
-static void test_half_int(void **_CBOR_UNUSED(_state)) {
+static void test_half_int(void** _state _CBOR_UNUSED) {
number = cbor_load(data3, 5, &res);
assert_true(cbor_typeof(number) == CBOR_TYPE_NEGINT);
assert_true(cbor_int_get_width(number) == CBOR_INT_16);
@@ -61,7 +61,7 @@ static void test_half_int(void **_CBOR_UNUSED(_state)) {
assert_null(number);
}
-static void test_int(void **_CBOR_UNUSED(_state)) {
+static void test_int(void** _state _CBOR_UNUSED) {
number = cbor_load(data4, 6, &res);
assert_true(cbor_typeof(number) == CBOR_TYPE_NEGINT);
assert_true(cbor_int_get_width(number) == CBOR_INT_32);
@@ -75,7 +75,7 @@ static void test_int(void **_CBOR_UNUSED(_state)) {
assert_null(number);
}
-static void test_long_int(void **_CBOR_UNUSED(_state)) {
+static void test_long_int(void** _state _CBOR_UNUSED) {
number = cbor_load(data5, 10, &res);
assert_true(cbor_typeof(number) == CBOR_TYPE_NEGINT);
assert_true(cbor_int_get_width(number) == CBOR_INT_64);
@@ -89,7 +89,7 @@ static void test_long_int(void **_CBOR_UNUSED(_state)) {
assert_null(number);
}
-static void test_int_creation(void **_CBOR_UNUSED(_state)) {
+static void test_int_creation(void** _state _CBOR_UNUSED) {
WITH_FAILING_MALLOC({ assert_null(cbor_new_int8()); });
WITH_FAILING_MALLOC({ assert_null(cbor_new_int16()); });
WITH_FAILING_MALLOC({ assert_null(cbor_new_int32()); });
diff --git a/test/pretty_printer_test.c b/test/pretty_printer_test.c
index 6ea40c0e7ce2..3652ef304787 100644
--- a/test/pretty_printer_test.c
+++ b/test/pretty_printer_test.c
@@ -11,17 +11,17 @@
#include "assertions.h"
#include "cbor.h"
-void assert_describe_result(cbor_item_t *item, char *expected_result) {
+void assert_describe_result(cbor_item_t* item, char* expected_result) {
#if CBOR_PRETTY_PRINTER
// We know the expected size based on `expected_result`, but read everything
// in order to get the full actual output in a useful error message.
const size_t buffer_size = 512;
- FILE *outfile = tmpfile();
+ FILE* outfile = tmpfile();
cbor_describe(item, outfile);
rewind(outfile);
// Treat string as null-terminated since cmocka doesn't have asserts
// for explicit length strings.
- char *output = malloc(buffer_size);
+ char* output = malloc(buffer_size);
assert_non_null(output);
size_t output_size = fread(output, sizeof(char), buffer_size, outfile);
output[output_size] = '\0';
@@ -32,31 +32,31 @@ void assert_describe_result(cbor_item_t *item, char *expected_result) {
#endif
}
-static void test_uint(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_build_uint8(42);
+static void test_uint(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_build_uint8(42);
assert_describe_result(item, "[CBOR_TYPE_UINT] Width: 1B, Value: 42\n");
cbor_decref(&item);
}
-static void test_negint(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_build_negint16(40);
+static void test_negint(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_build_negint16(40);
assert_describe_result(item,
"[CBOR_TYPE_NEGINT] Width: 2B, Value: -40 - 1\n");
cbor_decref(&item);
}
-static void test_definite_bytestring(void **_CBOR_UNUSED(_state)) {
+static void test_definite_bytestring(void** _state _CBOR_UNUSED) {
unsigned char data[] = {0x01, 0x02, 0x03};
- cbor_item_t *item = cbor_build_bytestring(data, 3);
+ cbor_item_t* item = cbor_build_bytestring(data, 3);
assert_describe_result(item,
"[CBOR_TYPE_BYTESTRING] Definite, Length: 3B, Data:\n"
" 010203\n");
cbor_decref(&item);
}
-static void test_indefinite_bytestring(void **_CBOR_UNUSED(_state)) {
+static void test_indefinite_bytestring(void** _state _CBOR_UNUSED) {
unsigned char data[] = {0x01, 0x02, 0x03};
- cbor_item_t *item = cbor_new_indefinite_bytestring();
+ cbor_item_t* item = cbor_new_indefinite_bytestring();
assert_true(cbor_bytestring_add_chunk(
item, cbor_move(cbor_build_bytestring(data, 3))));
assert_true(cbor_bytestring_add_chunk(
@@ -71,9 +71,9 @@ static void test_indefinite_bytestring(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_definite_string(void **_CBOR_UNUSED(_state)) {
- char *string = "Hello!";
- cbor_item_t *item = cbor_build_string(string);
+static void test_definite_string(void** _state _CBOR_UNUSED) {
+ char* string = "Hello!";
+ cbor_item_t* item = cbor_build_string(string);
assert_describe_result(
item,
"[CBOR_TYPE_STRING] Definite, Length: 6B, Codepoints: 6, Data:\n"
@@ -81,9 +81,9 @@ static void test_definite_string(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_indefinite_string(void **_CBOR_UNUSED(_state)) {
- char *string = "Hello!";
- cbor_item_t *item = cbor_new_indefinite_string();
+static void test_indefinite_string(void** _state _CBOR_UNUSED) {
+ char* string = "Hello!";
+ cbor_item_t* item = cbor_new_indefinite_string();
assert_true(
cbor_string_add_chunk(item, cbor_move(cbor_build_string(string))));
assert_true(
@@ -98,10 +98,10 @@ static void test_indefinite_string(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_multibyte_string(void **_CBOR_UNUSED(_state)) {
+static void test_multibyte_string(void** _state _CBOR_UNUSED) {
// "Štěstíčko" in UTF-8
- char *string = "\xc5\xa0t\xc4\x9bst\xc3\xad\xc4\x8dko";
- cbor_item_t *item = cbor_build_string(string);
+ char* string = "\xc5\xa0t\xc4\x9bst\xc3\xad\xc4\x8dko";
+ cbor_item_t* item = cbor_build_string(string);
assert_describe_result(
item,
"[CBOR_TYPE_STRING] Definite, Length: 13B, Codepoints: 9, Data:\n"
@@ -109,8 +109,8 @@ static void test_multibyte_string(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_definite_array(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_definite_array(2);
+static void test_definite_array(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_definite_array(2);
assert_true(cbor_array_push(item, cbor_move(cbor_build_uint8(1))));
assert_true(cbor_array_push(item, cbor_move(cbor_build_uint8(2))));
assert_describe_result(item,
@@ -120,8 +120,8 @@ static void test_definite_array(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_indefinite_array(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_indefinite_array();
+static void test_indefinite_array(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_indefinite_array();
assert_true(cbor_array_push(item, cbor_move(cbor_build_uint8(1))));
assert_true(cbor_array_push(item, cbor_move(cbor_build_uint8(2))));
assert_describe_result(item,
@@ -131,8 +131,8 @@ static void test_indefinite_array(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_definite_map(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_definite_map(1);
+static void test_definite_map(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_definite_map(1);
assert_true(cbor_map_add(
item, (struct cbor_pair){.key = cbor_move(cbor_build_uint8(1)),
.value = cbor_move(cbor_build_uint8(2))}));
@@ -144,8 +144,8 @@ static void test_definite_map(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_indefinite_map(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_indefinite_map();
+static void test_indefinite_map(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_indefinite_map();
assert_true(cbor_map_add(
item, (struct cbor_pair){.key = cbor_move(cbor_build_uint8(1)),
.value = cbor_move(cbor_build_uint8(2))}));
@@ -157,16 +157,16 @@ static void test_indefinite_map(void **_CBOR_UNUSED(_state)) {
cbor_decref(&item);
}
-static void test_tag(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_build_tag(42, cbor_move(cbor_build_uint8(1)));
+static void test_tag(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_build_tag(42, cbor_move(cbor_build_uint8(1)));
assert_describe_result(item,
"[CBOR_TYPE_TAG] Value: 42\n"
" [CBOR_TYPE_UINT] Width: 1B, Value: 1\n");
cbor_decref(&item);
}
-static void test_floats(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *item = cbor_new_indefinite_array();
+static void test_floats(void** _state _CBOR_UNUSED) {
+ cbor_item_t* item = cbor_new_indefinite_array();
assert_true(cbor_array_push(item, cbor_move(cbor_build_bool(true))));
assert_true(
cbor_array_push(item, cbor_move(cbor_build_ctrl(CBOR_CTRL_UNDEF))));
diff --git a/test/stack_over_limit_test.c b/test/stack_over_limit_test.c
index 73b6bdc2567b..fef2c6dd018e 100644
--- a/test/stack_over_limit_test.c
+++ b/test/stack_over_limit_test.c
@@ -1,9 +1,9 @@
#include "assertions.h"
#include "cbor.h"
-static size_t generate_overflow_data(unsigned char **overflow_data) {
+static size_t generate_overflow_data(unsigned char** overflow_data) {
int i;
- *overflow_data = (unsigned char *)malloc(CBOR_MAX_STACK_SIZE + 3);
+ *overflow_data = (unsigned char*)malloc(CBOR_MAX_STACK_SIZE + 3);
for (i = 0; i < CBOR_MAX_STACK_SIZE + 1; i++) {
(*overflow_data)[i] = 0xC2; // tag of positive bignum
}
@@ -12,8 +12,8 @@ static size_t generate_overflow_data(unsigned char **overflow_data) {
return CBOR_MAX_STACK_SIZE + 3;
}
-static void test_stack_over_limit(void **_CBOR_UNUSED(_state)) {
- unsigned char *overflow_data;
+static void test_stack_over_limit(void** _state _CBOR_UNUSED) {
+ unsigned char* overflow_data;
size_t overflow_data_len;
struct cbor_load_result res;
overflow_data_len = generate_overflow_data(&overflow_data);
diff --git a/test/stream_expectations.c b/test/stream_expectations.c
index 3592c9625da5..2a1b512f36c6 100644
--- a/test/stream_expectations.c
+++ b/test/stream_expectations.c
@@ -4,7 +4,7 @@ struct test_assertion assertions_queue[MAX_QUEUE_ITEMS];
int queue_size = 0;
int current_expectation = 0;
-int clean_up_stream_assertions(void **state) {
+int clean_up_stream_assertions(void** state) {
if (queue_size != current_expectation) {
return 1; // We have not matched all expectations correctly
}
@@ -25,7 +25,7 @@ void assert_uint8_eq(uint8_t actual) {
UINT8_EQ, (union test_expectation_data){.int8 = actual}};
}
-void uint8_callback(void *_CBOR_UNUSED(_context), uint8_t actual) {
+void uint8_callback(void* _context _CBOR_UNUSED, uint8_t actual) {
assert_true(current().expectation == UINT8_EQ);
assert_true(current().data.int8 == actual);
current_expectation++;
@@ -36,7 +36,7 @@ void assert_uint16_eq(uint16_t actual) {
UINT16_EQ, (union test_expectation_data){.int16 = actual}};
}
-void uint16_callback(void *_CBOR_UNUSED(_context), uint16_t actual) {
+void uint16_callback(void* _context _CBOR_UNUSED, uint16_t actual) {
assert_true(current().expectation == UINT16_EQ);
assert_true(current().data.int16 == actual);
current_expectation++;
@@ -47,7 +47,7 @@ void assert_uint32_eq(uint32_t actual) {
UINT32_EQ, (union test_expectation_data){.int32 = actual}};
}
-void uint32_callback(void *_CBOR_UNUSED(_context), uint32_t actual) {
+void uint32_callback(void* _context _CBOR_UNUSED, uint32_t actual) {
assert_true(current().expectation == UINT32_EQ);
assert_true(current().data.int32 == actual);
current_expectation++;
@@ -58,7 +58,7 @@ void assert_uint64_eq(uint64_t actual) {
UINT64_EQ, (union test_expectation_data){.int64 = actual}};
}
-void uint64_callback(void *_CBOR_UNUSED(_context), uint64_t actual) {
+void uint64_callback(void* _context _CBOR_UNUSED, uint64_t actual) {
assert_true(current().expectation == UINT64_EQ);
assert_true(current().data.int64 == actual);
current_expectation++;
@@ -69,7 +69,7 @@ void assert_negint8_eq(uint8_t actual) {
NEGINT8_EQ, (union test_expectation_data){.int8 = actual}};
}
-void negint8_callback(void *_CBOR_UNUSED(_context), uint8_t actual) {
+void negint8_callback(void* _context _CBOR_UNUSED, uint8_t actual) {
assert_true(current().expectation == NEGINT8_EQ);
assert_true(current().data.int8 == actual);
current_expectation++;
@@ -80,7 +80,7 @@ void assert_negint16_eq(uint16_t actual) {
NEGINT16_EQ, (union test_expectation_data){.int16 = actual}};
}
-void negint16_callback(void *_CBOR_UNUSED(_context), uint16_t actual) {
+void negint16_callback(void* _context _CBOR_UNUSED, uint16_t actual) {
assert_true(current().expectation == NEGINT16_EQ);
assert_true(current().data.int16 == actual);
current_expectation++;
@@ -91,7 +91,7 @@ void assert_negint32_eq(uint32_t actual) {
NEGINT32_EQ, (union test_expectation_data){.int32 = actual}};
}
-void negint32_callback(void *_CBOR_UNUSED(_context), uint32_t actual) {
+void negint32_callback(void* _context _CBOR_UNUSED, uint32_t actual) {
assert_true(current().expectation == NEGINT32_EQ);
assert_true(current().data.int32 == actual);
current_expectation++;
@@ -102,7 +102,7 @@ void assert_negint64_eq(uint64_t actual) {
NEGINT64_EQ, (union test_expectation_data){.int64 = actual}};
}
-void negint64_callback(void *_CBOR_UNUSED(_context), uint64_t actual) {
+void negint64_callback(void* _context _CBOR_UNUSED, uint64_t actual) {
assert_true(current().expectation == NEGINT64_EQ);
assert_true(current().data.int64 == actual);
current_expectation++;
@@ -114,7 +114,7 @@ void assert_bstring_mem_eq(cbor_data address, size_t length) {
(union test_expectation_data){.string = {address, length}}};
}
-void byte_string_callback(void *_CBOR_UNUSED(_context), cbor_data address,
+void byte_string_callback(void* _context _CBOR_UNUSED, cbor_data address,
uint64_t length) {
assert_true(current().expectation == BSTRING_MEM_EQ);
assert_true(current().data.string.address == address);
@@ -127,7 +127,7 @@ void assert_bstring_indef_start(void) {
(struct test_assertion){.expectation = BSTRING_INDEF_START};
}
-void byte_string_start_callback(void *_CBOR_UNUSED(_context)) {
+void byte_string_start_callback(void* _context _CBOR_UNUSED) {
assert_true(current().expectation == BSTRING_INDEF_START);
current_expectation++;
}
@@ -138,7 +138,7 @@ void assert_string_mem_eq(cbor_data address, size_t length) {
(union test_expectation_data){.string = {address, length}}};
}
-void string_callback(void *_CBOR_UNUSED(_context), cbor_data address,
+void string_callback(void* _context _CBOR_UNUSED, cbor_data address,
uint64_t length) {
assert_true(current().expectation == STRING_MEM_EQ);
assert_true(current().data.string.address == address);
@@ -151,7 +151,7 @@ void assert_string_indef_start(void) {
(struct test_assertion){.expectation = STRING_INDEF_START};
}
-void string_start_callback(void *_CBOR_UNUSED(_context)) {
+void string_start_callback(void* _context _CBOR_UNUSED) {
assert_true(current().expectation == STRING_INDEF_START);
current_expectation++;
}
@@ -161,7 +161,7 @@ void assert_indef_break(void) {
(struct test_assertion){.expectation = INDEF_BREAK};
}
-void indef_break_callback(void *_CBOR_UNUSED(_context)) {
+void indef_break_callback(void* _context _CBOR_UNUSED) {
assert_true(current().expectation == INDEF_BREAK);
current_expectation++;
}
@@ -171,7 +171,7 @@ void assert_array_start(size_t length) {
(struct test_assertion){ARRAY_START, {.length = length}};
}
-void array_start_callback(void *_CBOR_UNUSED(_context), uint64_t length) {
+void array_start_callback(void* _context _CBOR_UNUSED, uint64_t length) {
assert_true(current().expectation == ARRAY_START);
assert_true(current().data.length == length);
current_expectation++;
@@ -182,7 +182,7 @@ void assert_indef_array_start(void) {
(struct test_assertion){.expectation = ARRAY_INDEF_START};
}
-void indef_array_start_callback(void *_CBOR_UNUSED(_context)) {
+void indef_array_start_callback(void* _context _CBOR_UNUSED) {
assert_true(current().expectation == ARRAY_INDEF_START);
current_expectation++;
}
@@ -192,7 +192,7 @@ void assert_map_start(size_t length) {
(struct test_assertion){MAP_START, {.length = length}};
}
-void map_start_callback(void *_CBOR_UNUSED(_context), uint64_t length) {
+void map_start_callback(void* _context _CBOR_UNUSED, uint64_t length) {
assert_true(current().expectation == MAP_START);
assert_true(current().data.length == length);
current_expectation++;
@@ -203,7 +203,7 @@ void assert_indef_map_start(void) {
(struct test_assertion){.expectation = MAP_INDEF_START};
}
-void indef_map_start_callback(void *_CBOR_UNUSED(_context)) {
+void indef_map_start_callback(void* _context _CBOR_UNUSED) {
assert_true(current().expectation == MAP_INDEF_START);
current_expectation++;
}
@@ -213,7 +213,7 @@ void assert_tag_eq(uint64_t value) {
(struct test_assertion){TAG_EQ, {.int64 = value}};
}
-void tag_callback(void *_CBOR_UNUSED(_context), uint64_t value) {
+void tag_callback(void* _context _CBOR_UNUSED, uint64_t value) {
assert_true(current().expectation == TAG_EQ);
assert_true(current().data.int64 == value);
current_expectation++;
@@ -224,7 +224,7 @@ void assert_half(float value) {
(struct test_assertion){HALF_EQ, {.float2 = value}};
}
-void half_callback(void *_CBOR_UNUSED(_context), float actual) {
+void half_callback(void* _context _CBOR_UNUSED, float actual) {
assert_true(current().expectation == HALF_EQ);
assert_true(current().data.float2 == actual);
current_expectation++;
@@ -235,7 +235,7 @@ void assert_float(float value) {
(struct test_assertion){FLOAT_EQ, {.float4 = value}};
}
-void float_callback(void *_CBOR_UNUSED(_context), float actual) {
+void float_callback(void* _context _CBOR_UNUSED, float actual) {
assert_true(current().expectation == FLOAT_EQ);
assert_true(current().data.float4 == actual);
current_expectation++;
@@ -246,7 +246,7 @@ void assert_double(double value) {
(struct test_assertion){DOUBLE_EQ, {.float8 = value}};
}
-void double_callback(void *_CBOR_UNUSED(_context), double actual) {
+void double_callback(void* _context _CBOR_UNUSED, double actual) {
assert_true(current().expectation == DOUBLE_EQ);
assert_true(current().data.float8 == actual);
current_expectation++;
@@ -266,18 +266,18 @@ void assert_undef(void) {
(struct test_assertion){.expectation = UNDEF};
}
-void bool_callback(void *_CBOR_UNUSED(_context), bool actual) {
+void bool_callback(void* _context _CBOR_UNUSED, bool actual) {
assert_true(current().expectation == BOOL_EQ);
assert_true(current().data.boolean == actual);
current_expectation++;
}
-void null_callback(void *_CBOR_UNUSED(_context)) {
+void null_callback(void* _context _CBOR_UNUSED) {
assert_true(current().expectation == NIL);
current_expectation++;
}
-void undef_callback(void *_CBOR_UNUSED(_context)) {
+void undef_callback(void* _context _CBOR_UNUSED) {
assert_true(current().expectation == UNDEF);
current_expectation++;
}
diff --git a/test/stream_expectations.h b/test/stream_expectations.h
index bfc58e97cd9f..f67d025f9eaa 100644
--- a/test/stream_expectations.h
+++ b/test/stream_expectations.h
@@ -78,7 +78,7 @@ struct test_assertion {
struct cbor_decoder_result decode(cbor_data, size_t);
/* Verify all assertions were applied and clean up */
-int clean_up_stream_assertions(void **);
+int clean_up_stream_assertions(void**);
/* Assertions builders */
void assert_uint8_eq(uint8_t);
@@ -116,37 +116,37 @@ void assert_undef(void);
void assert_indef_break(void);
/* Assertions verifying callbacks */
-void uint8_callback(void *, uint8_t);
-void uint16_callback(void *, uint16_t);
-void uint32_callback(void *, uint32_t);
-void uint64_callback(void *, uint64_t);
+void uint8_callback(void*, uint8_t);
+void uint16_callback(void*, uint16_t);
+void uint32_callback(void*, uint32_t);
+void uint64_callback(void*, uint64_t);
-void negint8_callback(void *, uint8_t);
-void negint16_callback(void *, uint16_t);
-void negint32_callback(void *, uint32_t);
-void negint64_callback(void *, uint64_t);
+void negint8_callback(void*, uint8_t);
+void negint16_callback(void*, uint16_t);
+void negint32_callback(void*, uint32_t);
+void negint64_callback(void*, uint64_t);
-void byte_string_callback(void *, cbor_data, uint64_t);
-void byte_string_start_callback(void *);
+void byte_string_callback(void*, cbor_data, uint64_t);
+void byte_string_start_callback(void*);
-void string_callback(void *, cbor_data, uint64_t);
-void string_start_callback(void *);
+void string_callback(void*, cbor_data, uint64_t);
+void string_start_callback(void*);
-void array_start_callback(void *, uint64_t);
-void indef_array_start_callback(void *);
+void array_start_callback(void*, uint64_t);
+void indef_array_start_callback(void*);
-void map_start_callback(void *, uint64_t);
-void indef_map_start_callback(void *);
+void map_start_callback(void*, uint64_t);
+void indef_map_start_callback(void*);
-void tag_callback(void *, uint64_t);
+void tag_callback(void*, uint64_t);
-void half_callback(void *, float);
-void float_callback(void *, float);
-void double_callback(void *, double);
-void indef_break_callback(void *);
+void half_callback(void*, float);
+void float_callback(void*, float);
+void double_callback(void*, double);
+void indef_break_callback(void*);
-void bool_callback(void *, bool);
-void null_callback(void *);
-void undef_callback(void *);
+void bool_callback(void*, bool);
+void null_callback(void*);
+void undef_callback(void*);
#endif
diff --git a/test/string_encoders_test.c b/test/string_encoders_test.c
index 6de1cfb27eb3..2c00ff991090 100644
--- a/test/string_encoders_test.c
+++ b/test/string_encoders_test.c
@@ -10,18 +10,18 @@
unsigned char buffer[512];
-static void test_embedded_string_start(void **_CBOR_UNUSED(_state)) {
+static void test_embedded_string_start(void** _state _CBOR_UNUSED) {
assert_size_equal(1, cbor_encode_string_start(1, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0x61}), 1);
}
-static void test_string_start(void **_CBOR_UNUSED(_state)) {
+static void test_string_start(void** _state _CBOR_UNUSED) {
assert_size_equal(5, cbor_encode_string_start(1000000, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0x7A, 0x00, 0x0F, 0x42, 0x40}),
5);
}
-static void test_indef_string_start(void **_CBOR_UNUSED(_state)) {
+static void test_indef_string_start(void** _state _CBOR_UNUSED) {
assert_size_equal(1, cbor_encode_indef_string_start(buffer, 512));
assert_size_equal(0, cbor_encode_indef_string_start(buffer, 0));
assert_memory_equal(buffer, ((unsigned char[]){0x7F}), 1);
diff --git a/test/string_test.c b/test/string_test.c
index c3079b449838..9ce3bdfb7d17 100644
--- a/test/string_test.c
+++ b/test/string_test.c
@@ -10,12 +10,12 @@
#include "cbor.h"
#include "test_allocator.h"
-cbor_item_t *string;
+cbor_item_t* string;
struct cbor_load_result res;
unsigned char empty_string_data[] = {0x60};
-static void test_empty_string(void **_CBOR_UNUSED(_state)) {
+static void test_empty_string(void** _state _CBOR_UNUSED) {
string = cbor_load(empty_string_data, 1, &res);
assert_non_null(string);
assert_true(cbor_typeof(string) == CBOR_TYPE_STRING);
@@ -31,7 +31,7 @@ unsigned char short_string_data[] = {0x6C, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20,
0x77, 0x6F, 0x72, 0x6C, 0x64, 0x21};
/* 0x60 + 12 | Hello world! */
-static void test_short_string(void **_CBOR_UNUSED(_state)) {
+static void test_short_string(void** _state _CBOR_UNUSED) {
string = cbor_load(short_string_data, 13, &res);
assert_non_null(string);
assert_true(cbor_typeof(string) == CBOR_TYPE_STRING);
@@ -49,7 +49,7 @@ unsigned char short_multibyte_string_data[] = {
0xC3, 0x9F, 0x76, 0xC4, 0x9B, 0x74, 0x65, 0x21};
/* 0x60 + 15 | Čaues ßvěte! */
-static void test_short_multibyte_string(void **_CBOR_UNUSED(_state)) {
+static void test_short_multibyte_string(void** _state _CBOR_UNUSED) {
string = cbor_load(short_multibyte_string_data, 16, &res);
assert_non_null(string);
assert_true(cbor_typeof(string) == CBOR_TYPE_STRING);
@@ -78,7 +78,7 @@ unsigned char int8_string_data[] = {
0x70, 0x6F, 0x73, 0x75, 0x65, 0x72, 0x65, 0x2E};
/* 150 | Lorem ....*/
-static void test_int8_string(void **_CBOR_UNUSED(_state)) {
+static void test_int8_string(void** _state _CBOR_UNUSED) {
string = cbor_load(int8_string_data, 152, &res);
assert_non_null(string);
assert_true(cbor_typeof(string) == CBOR_TYPE_STRING);
@@ -112,7 +112,7 @@ unsigned char int16_string_data[] = {
/* 150 | Lorem ....*/
/* This valid but not realistic - length 150 could be encoded in a single
* uint8_t (but we need to keep the test files reasonably compact) */
-static void test_int16_string(void **_CBOR_UNUSED(_state)) {
+static void test_int16_string(void** _state _CBOR_UNUSED) {
string = cbor_load(int16_string_data, 153, &res);
assert_non_null(string);
assert_true(cbor_typeof(string) == CBOR_TYPE_STRING);
@@ -145,7 +145,7 @@ unsigned char int32_string_data[] = {
0x74, 0x6F, 0x20, 0x70, 0x6F, 0x73, 0x75, 0x65, 0x72, 0x65, 0x2E};
/* 150 | Lorem ....*/
-static void test_int32_string(void **_CBOR_UNUSED(_state)) {
+static void test_int32_string(void** _state _CBOR_UNUSED) {
string = cbor_load(int32_string_data, 155, &res);
assert_non_null(string);
assert_true(cbor_typeof(string) == CBOR_TYPE_STRING);
@@ -179,7 +179,7 @@ unsigned char int64_string_data[] = {
0x72, 0x65, 0x2E};
/* 150 | Lorem ....*/
-static void test_int64_string(void **_CBOR_UNUSED(_state)) {
+static void test_int64_string(void** _state _CBOR_UNUSED) {
string = cbor_load(int64_string_data, 159, &res);
assert_non_null(string);
assert_true(cbor_typeof(string) == CBOR_TYPE_STRING);
@@ -201,7 +201,7 @@ unsigned char short_indef_string_data[] = {0x7F, 0x78, 0x01, 0x65, 0xFF, 0xFF};
/* start | string | break| extra
*/
-static void test_short_indef_string(void **_CBOR_UNUSED(_state)) {
+static void test_short_indef_string(void** _state _CBOR_UNUSED) {
string = cbor_load(short_indef_string_data, 6, &res);
assert_non_null(string);
assert_true(cbor_typeof(string) == CBOR_TYPE_STRING);
@@ -217,7 +217,7 @@ static void test_short_indef_string(void **_CBOR_UNUSED(_state)) {
assert_null(string);
}
-static void test_invalid_utf(void **_CBOR_UNUSED(_state)) {
+static void test_invalid_utf(void** _state _CBOR_UNUSED) {
/* 0x60 + 1 | 0xC5 (invalid unfinished 2B codepoint) */
unsigned char string_data[] = {0x61, 0xC5};
string = cbor_load(string_data, 2, &res);
@@ -233,13 +233,13 @@ static void test_invalid_utf(void **_CBOR_UNUSED(_state)) {
cbor_decref(&string);
}
-static void test_inline_creation(void **_CBOR_UNUSED(_state)) {
+static void test_inline_creation(void** _state _CBOR_UNUSED) {
string = cbor_build_string("Hello!");
assert_memory_equal(cbor_string_handle(string), "Hello!", strlen("Hello!"));
cbor_decref(&string);
}
-static void test_string_creation(void **_CBOR_UNUSED(_state)) {
+static void test_string_creation(void** _state _CBOR_UNUSED) {
WITH_FAILING_MALLOC({ assert_null(cbor_new_definite_string()); });
WITH_FAILING_MALLOC({ assert_null(cbor_new_indefinite_string()); });
@@ -255,17 +255,17 @@ static void test_string_creation(void **_CBOR_UNUSED(_state)) {
MALLOC_FAIL);
}
-static void test_string_add_chunk(void **_CBOR_UNUSED(_state)) {
+static void test_string_add_chunk(void** _state _CBOR_UNUSED) {
WITH_MOCK_MALLOC(
{
- cbor_item_t *string = cbor_new_indefinite_string();
- cbor_item_t *chunk = cbor_build_string("Hello!");
+ cbor_item_t* string = cbor_new_indefinite_string();
+ cbor_item_t* chunk = cbor_build_string("Hello!");
assert_false(cbor_string_add_chunk(string, chunk));
assert_size_equal(cbor_string_chunk_count(string), 0);
- assert_size_equal(((struct cbor_indefinite_string_data *)string->data)
- ->chunk_capacity,
- 0);
+ assert_size_equal(
+ ((struct cbor_indefinite_string_data*)string->data)->chunk_capacity,
+ 0);
cbor_decref(&chunk);
cbor_decref(&string);
@@ -273,11 +273,11 @@ static void test_string_add_chunk(void **_CBOR_UNUSED(_state)) {
5, MALLOC, MALLOC, MALLOC, MALLOC, REALLOC_FAIL);
}
-static void test_add_chunk_reallocation_overflow(void **_CBOR_UNUSED(_state)) {
+static void test_add_chunk_reallocation_overflow(void** _state _CBOR_UNUSED) {
string = cbor_new_indefinite_string();
- cbor_item_t *chunk = cbor_build_string("Hello!");
- struct cbor_indefinite_string_data *metadata =
- (struct cbor_indefinite_string_data *)string->data;
+ cbor_item_t* chunk = cbor_build_string("Hello!");
+ struct cbor_indefinite_string_data* metadata =
+ (struct cbor_indefinite_string_data*)string->data;
// Pretend we already have many chunks allocated
metadata->chunk_count = SIZE_MAX;
metadata->chunk_capacity = SIZE_MAX;
@@ -291,10 +291,10 @@ static void test_add_chunk_reallocation_overflow(void **_CBOR_UNUSED(_state)) {
cbor_decref(&string);
}
-static void test_set_handle(void **_CBOR_UNUSED(_state)) {
+static void test_set_handle(void** _state _CBOR_UNUSED) {
string = cbor_new_definite_string();
- char *test_string = "Hello";
- unsigned char *string_data = malloc(strlen(test_string));
+ char* test_string = "Hello";
+ unsigned char* string_data = malloc(strlen(test_string));
memcpy(string_data, test_string, strlen(test_string));
assert_ptr_not_equal(string_data, NULL);
cbor_string_set_handle(string, string_data, strlen(test_string));
@@ -306,11 +306,11 @@ static void test_set_handle(void **_CBOR_UNUSED(_state)) {
cbor_decref(&string);
}
-static void test_set_handle_multibyte_codepoint(void **_CBOR_UNUSED(_state)) {
+static void test_set_handle_multibyte_codepoint(void** _state _CBOR_UNUSED) {
string = cbor_new_definite_string();
// "Štěstíčko" in UTF-8
- char *test_string = "\xc5\xa0t\xc4\x9bst\xc3\xad\xc4\x8dko";
- unsigned char *string_data = malloc(strlen(test_string));
+ char* test_string = "\xc5\xa0t\xc4\x9bst\xc3\xad\xc4\x8dko";
+ unsigned char* string_data = malloc(strlen(test_string));
memcpy(string_data, test_string, strlen(test_string));
assert_ptr_not_equal(string_data, NULL);
cbor_string_set_handle(string, string_data, strlen(test_string));
@@ -322,11 +322,11 @@ static void test_set_handle_multibyte_codepoint(void **_CBOR_UNUSED(_state)) {
cbor_decref(&string);
}
-static void test_set_handle_invalid_utf(void **_CBOR_UNUSED(_state)) {
+static void test_set_handle_invalid_utf(void** _state _CBOR_UNUSED) {
string = cbor_new_definite_string();
// Invalid multi-byte character (missing the second byte).
- char *test_string = "Test: \xc5";
- unsigned char *string_data = malloc(strlen(test_string));
+ char* test_string = "Test: \xc5";
+ unsigned char* string_data = malloc(strlen(test_string));
memcpy(string_data, test_string, strlen(test_string));
assert_ptr_not_equal(string_data, NULL);
cbor_string_set_handle(string, string_data, strlen(test_string));
diff --git a/test/tag_encoders_test.c b/test/tag_encoders_test.c
index 5962dd9d8938..06f87475392d 100644
--- a/test/tag_encoders_test.c
+++ b/test/tag_encoders_test.c
@@ -10,12 +10,12 @@
unsigned char buffer[512];
-static void test_embedded_tag(void **_CBOR_UNUSED(_state)) {
+static void test_embedded_tag(void** _state _CBOR_UNUSED) {
assert_size_equal(1, cbor_encode_tag(1, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0xC1}), 1);
}
-static void test_tag(void **_CBOR_UNUSED(_state)) {
+static void test_tag(void** _state _CBOR_UNUSED) {
assert_size_equal(5, cbor_encode_tag(1000000, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0xDA, 0x00, 0x0F, 0x42, 0x40}),
5);
diff --git a/test/tag_test.c b/test/tag_test.c
index 4bce10589803..293953cb4d9b 100644
--- a/test/tag_test.c
+++ b/test/tag_test.c
@@ -9,15 +9,15 @@
#include "cbor.h"
#include "test_allocator.h"
-cbor_item_t *tag;
+cbor_item_t* tag;
struct cbor_load_result res;
unsigned char embedded_tag_data[] = {0xC0, 0x00};
-static void test_refcounting(void **_CBOR_UNUSED(_state)) {
+static void test_refcounting(void** _state _CBOR_UNUSED) {
tag = cbor_load(embedded_tag_data, 2, &res);
assert_true(cbor_refcount(tag) == 1);
- cbor_item_t *item = cbor_tag_item(tag);
+ cbor_item_t* item = cbor_tag_item(tag);
assert_true(cbor_refcount(item) == 2);
cbor_decref(&tag);
assert_null(tag);
@@ -27,7 +27,7 @@ static void test_refcounting(void **_CBOR_UNUSED(_state)) {
}
/* Tag 0 + uint 0 */
-static void test_embedded_tag(void **_CBOR_UNUSED(_state)) {
+static void test_embedded_tag(void** _state _CBOR_UNUSED) {
tag = cbor_load(embedded_tag_data, 2, &res);
assert_true(cbor_typeof(tag) == CBOR_TYPE_TAG);
assert_true(cbor_tag_value(tag) == 0);
@@ -39,7 +39,7 @@ static void test_embedded_tag(void **_CBOR_UNUSED(_state)) {
unsigned char int8_tag_data[] = {0xD8, 0xFF, 0x01};
/* Tag 255 + uint 1 */
-static void test_int8_tag(void **_CBOR_UNUSED(_state)) {
+static void test_int8_tag(void** _state _CBOR_UNUSED) {
tag = cbor_load(int8_tag_data, 3, &res);
assert_true(cbor_typeof(tag) == CBOR_TYPE_TAG);
assert_true(cbor_tag_value(tag) == 255);
@@ -51,7 +51,7 @@ static void test_int8_tag(void **_CBOR_UNUSED(_state)) {
unsigned char int16_tag_data[] = {0xD9, 0xFF, 0x00, 0x02};
/* Tag 255 << 8 + uint 2 */
-static void test_int16_tag(void **_CBOR_UNUSED(_state)) {
+static void test_int16_tag(void** _state _CBOR_UNUSED) {
tag = cbor_load(int16_tag_data, 4, &res);
assert_true(cbor_typeof(tag) == CBOR_TYPE_TAG);
assert_true(cbor_tag_value(tag) == 255 << 8);
@@ -63,7 +63,7 @@ static void test_int16_tag(void **_CBOR_UNUSED(_state)) {
unsigned char int32_tag_data[] = {0xDA, 0xFF, 0x00, 0x00, 0x00, 0x03};
/* uint 3 */
-static void test_int32_tag(void **_CBOR_UNUSED(_state)) {
+static void test_int32_tag(void** _state _CBOR_UNUSED) {
tag = cbor_load(int32_tag_data, 6, &res);
assert_true(cbor_typeof(tag) == CBOR_TYPE_TAG);
assert_true(cbor_tag_value(tag) == 4278190080ULL);
@@ -76,7 +76,7 @@ unsigned char int64_tag_data[] = {0xDB, 0xFF, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x04};
/* uint 4 */
-static void test_int64_tag(void **_CBOR_UNUSED(_state)) {
+static void test_int64_tag(void** _state _CBOR_UNUSED) {
tag = cbor_load(int64_tag_data, 10, &res);
assert_true(cbor_typeof(tag) == CBOR_TYPE_TAG);
assert_true(cbor_tag_value(tag) == 18374686479671623680ULL);
@@ -88,11 +88,11 @@ static void test_int64_tag(void **_CBOR_UNUSED(_state)) {
unsigned char nested_tag_data[] = {0xC0, 0xC1, 0x18, 0x2A};
/* Tag 0, tag 1 + uint 0 */
-static void test_nested_tag(void **_CBOR_UNUSED(_state)) {
+static void test_nested_tag(void** _state _CBOR_UNUSED) {
tag = cbor_load(nested_tag_data, 4, &res);
assert_true(cbor_typeof(tag) == CBOR_TYPE_TAG);
assert_true(cbor_tag_value(tag) == 0);
- cbor_item_t *nested_tag = cbor_tag_item(tag);
+ cbor_item_t* nested_tag = cbor_tag_item(tag);
assert_true(cbor_typeof(nested_tag) == CBOR_TYPE_TAG);
assert_true(cbor_tag_value(nested_tag) == 1);
assert_uint8(cbor_move(cbor_tag_item(nested_tag)), 42);
@@ -102,13 +102,13 @@ static void test_nested_tag(void **_CBOR_UNUSED(_state)) {
assert_null(nested_tag);
}
-static void test_all_tag_values_supported(void **_CBOR_UNUSED(_state)) {
+static void test_all_tag_values_supported(void** _state _CBOR_UNUSED) {
/* Test all items in the protected range of
* https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml */
- for (int64_t tag_value = 0; tag_value <= 32767; tag_value++) {
- cbor_item_t *tag_item =
+ for (uint64_t tag_value = 0; tag_value <= 32767; tag_value++) {
+ cbor_item_t* tag_item =
cbor_build_tag(tag_value, cbor_move(cbor_build_uint8(42)));
- unsigned char *serialized_tag;
+ unsigned char* serialized_tag;
size_t serialized_tag_size =
cbor_serialize_alloc(tag_item, &serialized_tag, NULL);
assert_true(serialized_tag_size > 0);
@@ -124,7 +124,7 @@ static void test_all_tag_values_supported(void **_CBOR_UNUSED(_state)) {
}
}
-static void test_build_tag(void **_CBOR_UNUSED(_state)) {
+static void test_build_tag(void** _state _CBOR_UNUSED) {
tag = cbor_build_tag(1, cbor_move(cbor_build_uint8(42)));
assert_true(cbor_typeof(tag) == CBOR_TYPE_TAG);
@@ -134,8 +134,8 @@ static void test_build_tag(void **_CBOR_UNUSED(_state)) {
cbor_decref(&tag);
}
-static void test_build_tag_failure(void **_CBOR_UNUSED(_state)) {
- cbor_item_t *tagged_item = cbor_build_uint8(42);
+static void test_build_tag_failure(void** _state _CBOR_UNUSED) {
+ cbor_item_t* tagged_item = cbor_build_uint8(42);
WITH_FAILING_MALLOC({ assert_null(cbor_build_tag(1, tagged_item)); });
assert_size_equal(cbor_refcount(tagged_item), 1);
@@ -143,7 +143,7 @@ static void test_build_tag_failure(void **_CBOR_UNUSED(_state)) {
cbor_decref(&tagged_item);
}
-static void test_tag_creation(void **_CBOR_UNUSED(_state)) {
+static void test_tag_creation(void** _state _CBOR_UNUSED) {
WITH_FAILING_MALLOC({ assert_null(cbor_new_tag(42)); });
}
diff --git a/test/test_allocator.c b/test/test_allocator.c
index a2f98efa22f7..b941c79a4181 100644
--- a/test/test_allocator.c
+++ b/test/test_allocator.c
@@ -8,8 +8,8 @@
int alloc_calls_expected;
// How many alloc calls we got
int alloc_calls;
-// Array of booleans indicating whether to return a block or fail with NULL
-call_expectation *expectations;
+// Array of expected call and their behavior (success or failure)
+call_expectation* expectations;
void set_mock_malloc(int calls, ...) {
va_list args;
@@ -31,9 +31,9 @@ void finalize_mock_malloc(void) {
void print_backtrace(void) {
#if HAS_EXECINFO
- void *buffer[128];
+ void* buffer[128];
int frames = backtrace(buffer, 128);
- char **symbols = backtrace_symbols(buffer, frames);
+ char** symbols = backtrace_symbols(buffer, frames);
// Skip this function and the caller
for (int i = 2; i < frames; ++i) {
printf("%s\n", symbols[i]);
@@ -42,7 +42,7 @@ void print_backtrace(void) {
#endif
}
-void *instrumented_malloc(size_t size) {
+void* instrumented_malloc(size_t size) {
if (alloc_calls >= alloc_calls_expected) {
goto error;
}
@@ -59,13 +59,13 @@ error:
print_error(
"Unexpected call to malloc(%zu) at position %d of %d; expected %d\n",
size, alloc_calls, alloc_calls_expected,
- alloc_calls < alloc_calls_expected ? expectations[alloc_calls] : -1);
+ alloc_calls < alloc_calls_expected ? (int)expectations[alloc_calls] : -1);
print_backtrace();
fail();
return NULL;
}
-void *instrumented_realloc(void *ptr, size_t size) {
+void* instrumented_realloc(void* ptr, size_t size) {
if (alloc_calls >= alloc_calls_expected) {
goto error;
}
@@ -82,7 +82,7 @@ error:
print_error(
"Unexpected call to realloc(%zu) at position %d of %d; expected %d\n",
size, alloc_calls, alloc_calls_expected,
- alloc_calls < alloc_calls_expected ? expectations[alloc_calls] : -1);
+ alloc_calls < alloc_calls_expected ? (int)expectations[alloc_calls] : -1);
print_backtrace();
fail();
return NULL;
diff --git a/test/test_allocator.h b/test/test_allocator.h
index 0e58454edbd6..09e5791b81d9 100644
--- a/test/test_allocator.h
+++ b/test/test_allocator.h
@@ -7,9 +7,13 @@
// Harness for mocking `malloc` and `realloc`
typedef enum call_expectation {
+ // Call malloc and return a pointer
MALLOC,
+ // Pretend call malloc, but return NULL (fail)
MALLOC_FAIL,
+ // Call realloc and return a pointer
REALLOC,
+ // Pretend call realloc, but return NULL (fail)
REALLOC_FAIL
} call_expectation;
@@ -17,9 +21,9 @@ void set_mock_malloc(int calls, ...);
void finalize_mock_malloc(void);
-void *instrumented_malloc(size_t size);
+void* instrumented_malloc(size_t size);
-void *instrumented_realloc(void *ptr, size_t size);
+void* instrumented_realloc(void* ptr, size_t size);
#define WITH_MOCK_MALLOC(block, malloc_calls, ...) \
do { \
diff --git a/test/uint_encoders_test.c b/test/uint_encoders_test.c
index 59b95a33026e..886086469819 100644
--- a/test/uint_encoders_test.c
+++ b/test/uint_encoders_test.c
@@ -10,31 +10,31 @@
unsigned char buffer[512];
-static void test_embedded_uint8(void **_CBOR_UNUSED(_state)) {
+static void test_embedded_uint8(void** _state _CBOR_UNUSED) {
assert_size_equal(1, cbor_encode_uint8(14, buffer, 512));
assert_memory_equal(buffer, (unsigned char[]){0x0E}, 1);
}
-static void test_uint8(void **_CBOR_UNUSED(_state)) {
+static void test_uint8(void** _state _CBOR_UNUSED) {
assert_size_equal(0, cbor_encode_uint8(180, buffer, 1));
assert_size_equal(2, cbor_encode_uint8(255, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0x18, 0xFF}), 2);
}
-static void test_uint16(void **_CBOR_UNUSED(_state)) {
+static void test_uint16(void** _state _CBOR_UNUSED) {
assert_size_equal(0, cbor_encode_uint16(1000, buffer, 2));
assert_size_equal(3, cbor_encode_uint16(1000, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0x19, 0x03, 0xE8}), 3);
}
-static void test_uint32(void **_CBOR_UNUSED(_state)) {
+static void test_uint32(void** _state _CBOR_UNUSED) {
assert_size_equal(0, cbor_encode_uint32(1000000, buffer, 4));
assert_size_equal(5, cbor_encode_uint32(1000000, buffer, 512));
assert_memory_equal(buffer, ((unsigned char[]){0x1A, 0x00, 0x0F, 0x42, 0x40}),
5);
}
-static void test_uint64(void **_CBOR_UNUSED(_state)) {
+static void test_uint64(void** _state _CBOR_UNUSED) {
assert_size_equal(0, cbor_encode_uint64(18446744073709551615ULL, buffer, 8));
assert_size_equal(9,
cbor_encode_uint64(18446744073709551615ULL, buffer, 512));
@@ -44,7 +44,7 @@ static void test_uint64(void **_CBOR_UNUSED(_state)) {
9);
}
-static void test_unspecified(void **_CBOR_UNUSED(_state)) {
+static void test_unspecified(void** _state _CBOR_UNUSED) {
assert_size_equal(9, cbor_encode_uint(18446744073709551615ULL, buffer, 512));
assert_memory_equal(
buffer,
diff --git a/test/uint_test.c b/test/uint_test.c
index 89eb2b91833e..3c269daef238 100644
--- a/test/uint_test.c
+++ b/test/uint_test.c
@@ -10,7 +10,7 @@
#include "cbor.h"
-cbor_item_t *number;
+cbor_item_t* number;
struct cbor_load_result res;
unsigned char data1[] = {0x02, 0xFF};
@@ -20,7 +20,7 @@ unsigned char data4[] = {0x1a, 0xa5, 0xf7, 0x02, 0xb3, 0xFF};
unsigned char data5[] = {0x1b, 0xa5, 0xf7, 0x02, 0xb3,
0xa5, 0xf7, 0x02, 0xb3, 0xFF};
-static void test_very_short_int(void **_CBOR_UNUSED(_state)) {
+static void test_very_short_int(void** _state _CBOR_UNUSED) {
number = cbor_load(data1, 2, &res);
assert_true(cbor_typeof(number) == CBOR_TYPE_UINT);
assert_true(cbor_int_get_width(number) == CBOR_INT_8);
@@ -34,13 +34,13 @@ static void test_very_short_int(void **_CBOR_UNUSED(_state)) {
assert_null(number);
}
-static void test_incomplete_data(void **_CBOR_UNUSED(_state)) {
+static void test_incomplete_data(void** _state _CBOR_UNUSED) {
number = cbor_load(data2, 1, &res);
assert_null(number);
assert_true(res.error.code == CBOR_ERR_NOTENOUGHDATA);
}
-static void test_short_int(void **_CBOR_UNUSED(_state)) {
+static void test_short_int(void** _state _CBOR_UNUSED) {
number = cbor_load(data2, 3, &res);
assert_true(cbor_typeof(number) == CBOR_TYPE_UINT);
assert_true(cbor_int_get_width(number) == CBOR_INT_8);
@@ -54,7 +54,7 @@ static void test_short_int(void **_CBOR_UNUSED(_state)) {
assert_null(number);
}
-static void test_half_int(void **_CBOR_UNUSED(_state)) {
+static void test_half_int(void** _state _CBOR_UNUSED) {
number = cbor_load(data3, 5, &res);
assert_true(cbor_typeof(number) == CBOR_TYPE_UINT);
assert_true(cbor_int_get_width(number) == CBOR_INT_16);
@@ -68,7 +68,7 @@ static void test_half_int(void **_CBOR_UNUSED(_state)) {
assert_null(number);
}
-static void test_int(void **_CBOR_UNUSED(_state)) {
+static void test_int(void** _state _CBOR_UNUSED) {
number = cbor_load(data4, 6, &res);
assert_true(cbor_typeof(number) == CBOR_TYPE_UINT);
assert_true(cbor_int_get_width(number) == CBOR_INT_32);
@@ -82,7 +82,7 @@ static void test_int(void **_CBOR_UNUSED(_state)) {
assert_null(number);
}
-static void test_long_int(void **_CBOR_UNUSED(_state)) {
+static void test_long_int(void** _state _CBOR_UNUSED) {
number = cbor_load(data5, 10, &res);
assert_true(cbor_typeof(number) == CBOR_TYPE_UINT);
assert_true(cbor_int_get_width(number) == CBOR_INT_64);
@@ -96,7 +96,7 @@ static void test_long_int(void **_CBOR_UNUSED(_state)) {
assert_null(number);
}
-static void test_refcounting(void **_CBOR_UNUSED(_state)) {
+static void test_refcounting(void** _state _CBOR_UNUSED) {
number = cbor_load(data5, 10, &res);
cbor_incref(number);
assert_true(number->refcount == 2);
@@ -106,13 +106,13 @@ static void test_refcounting(void **_CBOR_UNUSED(_state)) {
assert_null(number);
}
-static void test_empty_input(void **_CBOR_UNUSED(_state)) {
+static void test_empty_input(void** _state _CBOR_UNUSED) {
number = cbor_load(data5, 0, &res);
assert_null(number);
assert_true(res.error.code == CBOR_ERR_NODATA);
}
-static void test_inline_creation(void **_CBOR_UNUSED(_state)) {
+static void test_inline_creation(void** _state _CBOR_UNUSED) {
number = cbor_build_uint8(10);
assert_true(cbor_get_int(number) == 10);
cbor_decref(&number);
@@ -130,7 +130,7 @@ static void test_inline_creation(void **_CBOR_UNUSED(_state)) {
cbor_decref(&number);
}
-static void test_int_creation(void **_CBOR_UNUSED(_state)) {
+static void test_int_creation(void** _state _CBOR_UNUSED) {
WITH_FAILING_MALLOC({ assert_null(cbor_new_int8()); });
WITH_FAILING_MALLOC({ assert_null(cbor_new_int16()); });
WITH_FAILING_MALLOC({ assert_null(cbor_new_int32()); });
diff --git a/test/unicode_test.c b/test/unicode_test.c
index 4b3613e77f78..62245bc1fe4a 100644
--- a/test/unicode_test.c
+++ b/test/unicode_test.c
@@ -13,7 +13,7 @@ struct _cbor_unicode_status status;
unsigned char missing_bytes_data[] = {0xC4, 0x8C};
/* Capital accented C */
-static void test_missing_bytes(void **_CBOR_UNUSED(_state)) {
+static void test_missing_bytes(void** _state _CBOR_UNUSED) {
assert_true(_cbor_unicode_codepoint_count(missing_bytes_data, 1, &status) ==
0);
assert_true(status.status == _CBOR_UNICODE_BADCP);
@@ -28,7 +28,7 @@ static void test_missing_bytes(void **_CBOR_UNUSED(_state)) {
unsigned char invalid_sequence_data[] = {0x65, 0xC4, 0x00};
/* e, invalid seq */
-static void test_invalid_sequence(void **_CBOR_UNUSED(_state)) {
+static void test_invalid_sequence(void** _state _CBOR_UNUSED) {
assert_true(
_cbor_unicode_codepoint_count(invalid_sequence_data, 3, &status) == 0);
assert_true(status.status == _CBOR_UNICODE_BADCP);