Skip to content

Commit bad81be

Browse files
Merge branch 'main' into dev
2 parents 62c73f6 + 0d55382 commit bad81be

20 files changed

+151
-66
lines changed

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ install:
88
- cmd: >-
99
if /i "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" (call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x86) & (set QTDIR=C:\Qt\5.13\msvc2017)
1010
11-
if /i "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2019" (call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64) & (set QTDIR=C:\Qt\6.1\msvc2019_64)
11+
if /i "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2019" (call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64) & (set QTDIR=C:\Qt\6.5\msvc2019_64)
1212
1313
set path=%PATH%;%QTDIR%\bin
1414
build_script:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ cflags += -std=gnu99 $(CFLAGS)
240240

241241
ifneq ($(DISABLE_WERROR),1)
242242
cflags += \
243-
-Werror=discarded-qualifiers \
243+
$(shell $(CC) -S -Werror -Wdiscarded-qualifiers -o - -xc /dev/null >/dev/null 2>&1 && echo -Werror=discarded-qualifiers) \
244244
-Werror=incompatible-pointer-types \
245245
-Werror=implicit-function-declaration \
246246
-Werror=int-conversion

src/cbor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
#include <string.h>
3535
#include <stdio.h>
3636

37+
#ifdef CBOR_EXTERNAL_CFG
38+
#include "cbor_cfg.h"
39+
#endif
40+
3741
#include "tinycbor-version.h"
3842

3943
#define TINYCBOR_VERSION ((TINYCBOR_VERSION_MAJOR << 16) | (TINYCBOR_VERSION_MINOR << 8) | TINYCBOR_VERSION_PATCH)

src/cborencoder.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#ifndef __STDC_LIMIT_MACROS
3232
# define __STDC_LIMIT_MACROS 1
3333
#endif
34+
#define __STDC_WANT_IEC_60559_TYPES_EXT__
3435

3536
#include "cbor.h"
3637
#include "cborinternal_p.h"
@@ -101,7 +102,7 @@
101102
* complete the encoding. At the end, you can obtain that count by calling
102103
* cbor_encoder_get_extra_bytes_needed().
103104
*
104-
* \section1 Finalizing the encoding
105+
* \section Finalizing the encoding
105106
*
106107
* Once all items have been appended and the containers have all been properly
107108
* closed, the user-supplied buffer will contain the CBOR stream and may be
@@ -558,7 +559,7 @@ CborError cbor_encoder_create_array(CborEncoder *parentEncoder, CborEncoder *arr
558559
* when creating the map, the constant \ref CborIndefiniteLength may be passed as
559560
* length instead, and an indefinite length map is created.
560561
*
561-
* \b{Implementation limitation:} TinyCBOR cannot encode more than SIZE_MAX/2
562+
* <b>Implementation limitation:</b> TinyCBOR cannot encode more than SIZE_MAX/2
562563
* key-value pairs in the stream. If the length \a length is larger than this
563564
* value (and is not \ref CborIndefiniteLength), this function returns error
564565
* CborErrorDataTooLarge.

src/cborencoder_close_container_checked.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#ifndef __STDC_LIMIT_MACROS
2828
# define __STDC_LIMIT_MACROS 1
2929
#endif
30+
#define __STDC_WANT_IEC_60559_TYPES_EXT__
3031

3132
#include "cbor.h"
3233

src/cborencoder_float.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#ifndef __STDC_LIMIT_MACROS
2828
# define __STDC_LIMIT_MACROS 1
2929
#endif
30+
#define __STDC_WANT_IEC_60559_TYPES_EXT__
3031

3132
#include "cbor.h"
3233

src/cborinternal_p.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,46 @@
2525
#ifndef CBORINTERNAL_P_H
2626
#define CBORINTERNAL_P_H
2727

28+
/* Dependent source files (*.c) must define __STDC_WANT_IEC_60559_TYPES_EXT__
29+
* before <float.h> is (transitively) first included.
30+
*/
31+
#if !defined(__STDC_WANT_IEC_60559_TYPES_EXT__)
32+
# error __STDC_WANT_IEC_60559_TYPES_EXT__ not defined
33+
#endif
34+
2835
#include "compilersupport_p.h"
2936

3037
#ifndef CBOR_NO_FLOATING_POINT
3138
# include <float.h>
3239
# include <math.h>
40+
# include <string.h>
3341
#else
3442
# ifndef CBOR_NO_HALF_FLOAT_TYPE
3543
# define CBOR_NO_HALF_FLOAT_TYPE 1
3644
# endif
3745
#endif
3846

3947
#ifndef CBOR_NO_HALF_FLOAT_TYPE
40-
# if defined(__F16C__) || defined(__AVX2__)
48+
/* Check for FLT16_MANT_DIG using integer comparison. Clang headers incorrectly
49+
* define this macro unconditionally when __STDC_WANT_IEC_60559_TYPES_EXT__
50+
* is defined (regardless of actual support for _Float16).
51+
*/
52+
# if FLT16_MANT_DIG > 0 || __FLT16_MANT_DIG__ > 0
53+
static inline unsigned short encode_half(float x)
54+
{
55+
unsigned short h;
56+
_Float16 f = (_Float16)x;
57+
memcpy(&h, &f, 2);
58+
return h;
59+
}
60+
61+
static inline float decode_half(unsigned short x)
62+
{
63+
_Float16 f;
64+
memcpy(&f, &x, 2);
65+
return (float)f;
66+
}
67+
# elif defined(__F16C__) || defined(__AVX2__)
4168
# include <immintrin.h>
4269
static inline unsigned short encode_half(float val)
4370
{

src/cborparser.c

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#ifndef __STDC_LIMIT_MACROS
3232
# define __STDC_LIMIT_MACROS 1
3333
#endif
34+
#define __STDC_WANT_IEC_60559_TYPES_EXT__
3435

3536
#include "cbor.h"
3637
#include "cborinternal_p.h"
@@ -93,7 +94,7 @@
9394
*
9495
* The code above does not execute a range-check either: it is possible that
9596
* the value decoded from the CBOR stream encodes a number larger than what can
96-
* be represented in a variable of type \c{int}. If detecting that case is
97+
* be represented in a variable of type \c int. If detecting that case is
9798
* important, the code should call cbor_value_get_int_checked() instead.
9899
*
99100
* <h3 class="groupheader">Memory and parsing constraints</h3>
@@ -133,12 +134,10 @@
133134
*
134135
* \if privatedocs
135136
* Implementation details: the CborValue contains these fields:
136-
* \list
137-
* \li ptr: pointer to the actual data
138-
* \li flags: flags from the decoder
139-
* \li extra: partially decoded integer value (0, 1 or 2 bytes)
140-
* \li remaining: remaining items in this collection after this item or UINT32_MAX if length is unknown
141-
* \endlist
137+
* - ptr: pointer to the actual data
138+
* - flags: flags from the decoder
139+
* - extra: partially decoded integer value (0, 1 or 2 bytes)
140+
* - remaining: remaining items in this collection after this item or UINT32_MAX if length is unknown
142141
* \endif
143142
*/
144143

@@ -428,12 +427,10 @@ CborError cbor_value_reparse(CborValue *it)
428427
* will appear during parsing.
429428
*
430429
* A basic validation checks for:
431-
* \list
432-
* \li absence of undefined additional information bytes;
433-
* \li well-formedness of all numbers, lengths, and simple values;
434-
* \li string contents match reported sizes;
435-
* \li arrays and maps contain the number of elements they are reported to have;
436-
* \endlist
430+
* - absence of undefined additional information bytes;
431+
* - well-formedness of all numbers, lengths, and simple values;
432+
* - string contents match reported sizes;
433+
* - arrays and maps contain the number of elements they are reported to have;
437434
*
438435
* For further checks, see cbor_value_validate().
439436
*
@@ -744,7 +741,7 @@ CborError cbor_value_leave_container(CborValue *it, const CborValue *recursed)
744741
* \ref cbor_value_is_integer is recommended.
745742
*
746743
* Note that this function does not do range-checking: integral values that do
747-
* not fit in a variable of type \c{int} are silently truncated to fit. Use
744+
* not fit in a variable of type \c int are silently truncated to fit. Use
748745
* cbor_value_get_int_checked() if that is not acceptable.
749746
*
750747
* \sa cbor_value_get_type(), cbor_value_is_valid(), cbor_value_is_integer()
@@ -759,7 +756,7 @@ CborError cbor_value_leave_container(CborValue *it, const CborValue *recursed)
759756
* \ref cbor_value_is_integer is recommended.
760757
*
761758
* Note that this function does not do range-checking: integral values that do
762-
* not fit in a variable of type \c{int64_t} are silently truncated to fit. Use
759+
* not fit in a variable of type \c int64_t are silently truncated to fit. Use
763760
* cbor_value_get_int64_checked() that is not acceptable.
764761
*
765762
* \sa cbor_value_get_type(), cbor_value_is_valid(), cbor_value_is_integer()
@@ -790,7 +787,7 @@ CborError cbor_value_leave_container(CborValue *it, const CborValue *recursed)
790787
* If the integer is unsigned (that is, if cbor_value_is_unsigned_integer()
791788
* returns true), then \a result will contain the actual value. If the integer
792789
* is negative, then \a result will contain the absolute value of that integer,
793-
* minus one. That is, \c {actual = -result - 1}. On architectures using two's
790+
* minus one. That is, <tt>actual = -result - 1</tt>. On architectures using two's
794791
* complement for representation of negative integers, it is equivalent to say
795792
* that \a result will contain the bitwise negation of the actual value.
796793
*
@@ -1243,10 +1240,10 @@ static CborError iterate_string_chunks(const CborValue *value, char *buffer, siz
12431240
* of the string in order to preallocate a buffer, use
12441241
* cbor_value_calculate_string_length().
12451242
*
1246-
* On success, this function sets the number of bytes copied to \c{*buflen}. If
1243+
* On success, this function sets the number of bytes copied to \c *buflen. If
12471244
* the buffer is large enough, this function will insert a null byte after the
12481245
* last copied byte, to facilitate manipulation of text strings. That byte is
1249-
* not included in the returned value of \c{*buflen}. If there was no space for
1246+
* not included in the returned value of \c *buflen. If there was no space for
12501247
* the terminating null, no error is returned, so callers must check the value
12511248
* of *buflen after the call, before relying on the '\0'; if it has not been
12521249
* changed by the call, there is no '\0'-termination on the buffer's contents.
@@ -1280,10 +1277,10 @@ static CborError iterate_string_chunks(const CborValue *value, char *buffer, siz
12801277
* of the string in order to preallocate a buffer, use
12811278
* cbor_value_calculate_string_length().
12821279
*
1283-
* On success, this function sets the number of bytes copied to \c{*buflen}. If
1280+
* On success, this function sets the number of bytes copied to \c *buflen. If
12841281
* the buffer is large enough, this function will insert a null byte after the
12851282
* last copied byte, to facilitate manipulation of null-terminated strings.
1286-
* That byte is not included in the returned value of \c{*buflen}.
1283+
* That byte is not included in the returned value of \c *buflen.
12871284
*
12881285
* The \a next pointer, if not null, will be updated to point to the next item
12891286
* after this string. If \a value points to the last item, then \a next will be
@@ -1520,7 +1517,7 @@ CborError cbor_value_map_find_value(const CborValue *map, const char *string, Cb
15201517
* cbor_value_is_half_float is recommended.
15211518
*
15221519
* Note: since the C language does not have a standard type for half-precision
1523-
* floating point, this function takes a \c{void *} as a parameter for the
1520+
* floating point, this function takes a <tt>void *</tt> as a parameter for the
15241521
* storage area, which must be at least 16 bits wide.
15251522
*
15261523
* \sa cbor_value_get_type(), cbor_value_is_valid(), cbor_value_is_half_float(), cbor_value_get_half_float_as_float(), cbor_value_get_float()

src/cborparser_dup_string.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,18 @@
3131
#ifndef __STDC_LIMIT_MACROS
3232
# define __STDC_LIMIT_MACROS 1
3333
#endif
34+
#define __STDC_WANT_IEC_60559_TYPES_EXT__
3435

3536
#include "cbor.h"
3637
#include "compilersupport_p.h"
37-
#include <stdlib.h>
38+
39+
#if defined(CBOR_CUSTOM_ALLOC_INCLUDE)
40+
# include CBOR_CUSTOM_ALLOC_INCLUDE
41+
#else
42+
# include <stdlib.h>
43+
# define cbor_malloc malloc
44+
# define cbor_free free
45+
#endif
3846

3947
/**
4048
* \fn CborError cbor_value_dup_text_string(const CborValue *value, char **buffer, size_t *buflen, CborValue *next)
@@ -50,8 +58,8 @@
5058
* If \c malloc returns a NULL pointer, this function will return error
5159
* condition \ref CborErrorOutOfMemory.
5260
*
53-
* On success, \c{*buffer} will contain a valid pointer that must be freed by
54-
* calling \c{free()}. This is the case even for zero-length strings.
61+
* On success, \c *buffer will contain a valid pointer that must be freed by
62+
* calling \c free(). This is the case even for zero-length strings.
5563
*
5664
* The \a next pointer, if not null, will be updated to point to the next item
5765
* after this string. If \a value points to the last item, then \a next will be
@@ -81,8 +89,8 @@
8189
* If \c malloc returns a NULL pointer, this function will return error
8290
* condition \ref CborErrorOutOfMemory.
8391
*
84-
* On success, \c{*buffer} will contain a valid pointer that must be freed by
85-
* calling \c{free()}. This is the case even for zero-length strings.
92+
* On success, \c *buffer will contain a valid pointer that must be freed by
93+
* calling \c free(). This is the case even for zero-length strings.
8694
*
8795
* The \a next pointer, if not null, will be updated to point to the next item
8896
* after this string. If \a value points to the last item, then \a next will be
@@ -105,14 +113,14 @@ CborError _cbor_value_dup_string(const CborValue *value, void **buffer, size_t *
105113
return err;
106114

107115
++*buflen;
108-
*buffer = malloc(*buflen);
116+
*buffer = cbor_malloc(*buflen);
109117
if (!*buffer) {
110118
/* out of memory */
111119
return CborErrorOutOfMemory;
112120
}
113121
err = _cbor_value_copy_string(value, *buffer, buflen, next);
114122
if (err) {
115-
free(*buffer);
123+
cbor_free(*buffer);
116124
return err;
117125
}
118126
return CborNoError;

src/cborparser_float.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#ifndef __STDC_LIMIT_MACROS
2828
# define __STDC_LIMIT_MACROS 1
2929
#endif
30+
#define __STDC_WANT_IEC_60559_TYPES_EXT__
3031

3132
#include "cbor.h"
3233

0 commit comments

Comments
 (0)