Commit Graph
338 Commits
Author SHA1 Message Date
Thiago Macieira 5d871b201a Validator & Pretty: Remove the last uses of _cbor_value_extract_number
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2021-09-03 13:08:25 -07:00
Thiago Macieira eddbf5b176 Parser: rework the two extract_{number,length} internal functions
The extract_length() was the only case that called
extract_number_and_advance() without verifying we had a proper number. This
commit reworks the implementation so extract_number_and_advance() reuses
the number previously read by preparse_value(), and extract_length() gets
inlined to the only place that uses it.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2021-09-03 13:08:25 -07:00
Thiago Macieira a8515c4e11 Parser: use read_bytes() in the extract_number function
The extract_length() function is only used in string context, so rename
accordingly.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2021-09-03 13:08:25 -07:00
Thiago Macieira 0b4f7f66f9 Parser: inline the cbor_value_get_half_float() function
It was originally non-inline because I had thought of doing conversions
from half-float to float and onwards to double, but I never actually
made that in the API. Instead, even the get_float() and get_double(), we
only memcpy anyway and leave it up to the upper layer to convert, as
needed.

This change triggered an use-when-uninitialised false positive warning
that I needed to work around in the validator.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2021-09-03 13:08:25 -07:00
Thiago Macieira 14299a2be1 Parser: Save the fact that we found a 64-bit number
We don't need to skimp on bits in the CborValue::flags, so save the fact
that the preparser found a 64-bit number in there. This saves us from
having to re-read the descriptor byte again in
_cbor_value_decode_int64_internal().

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2021-09-03 13:08:25 -07:00
Thiago Macieira b8ea2eb29a Parser: create a function that centralizes reading from the buffer
This commit does not change all the readers yet, this is just the first
step.

As an interesting side-effect, we ended up reading the half-float into
it->extra and need not re-read it. The cbor_value_get_half_float()
function can be inlined in a later commit.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2021-09-03 13:08:25 -07:00
Thiago Macieira 5521ccf2f7 Parser: centralize checking of the available buffer size
As noted in the comment, we need to be sure we don't allow a length too
big from the stream to overflow and become smaller than the number of
bytes we're looking for.

This is also the first step in creating an API that reads from something
other than a linear buffer.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2021-09-03 13:08:25 -07:00
Thiago Macieira 2d8e73ba6c Tests: Catch an earlier QCOMPARE failure in compare()
QCOMPARE macro has a return in case of failure. If a test fails inside
the encodeOne function, we log that error, but were proceeding to
perform more tests (which could fail again and produce more errors).

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2021-09-03 13:08:25 -07:00
Thiago Macieira 6f001e6f35 Add a way to disable the declaration of some API
Because of all the inline functions, #include'ing <cbor.h> without
linking in all .c files may result in undefined symbol linker errors.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2021-09-03 13:08:25 -07:00
Thiago Macieira f798bc073d Validator: simplify (and correct) the map sorting verification
We don't need to compare the map lengths directly. The memcmp is
sufficient, since the source data is big endian.

Of course, verifying for sorting requires the map has known length.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2021-09-03 13:08:25 -07:00
Thiago Macieira bf919a2ebd AppVeyor: update to use more recent Qt and MSVC
The last version of Qt to support MSVC 2015 is no longer maintained, so
I'm skipping that. I'm therefore rededicating MSVC 2017 for 32-bit.

There's also no more no-tests build.
2021-09-03 13:08:25 -07:00
Thiago Macieira e2a4ed135c Build system: Add a few -Werror for sane C development 2021-09-03 12:54:10 -07:00
Thiago Macieira 5910b7def3 Merge remote-tracking branch 'origin/main' into HEAD 2021-09-03 12:34:33 -07:00
Thiago Macieira 9ed9d03a69 Update the qmake buildsystem source files
The listing was outdated.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2021-09-03 12:00:22 -07:00
phirsov 814ec02bb5 enhancement #149 implemented: access half-precision floating point data as single float
Motivation: half-precision floating point format is used to minimize storage
and traffic mostly.  Application level manipulates with single and double
precision usually. So, two routines added to public API to encode/decode given
single precision value in the half precision format

Signed-off-by: S.Phirsov
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2021-09-03 12:00:07 -07:00
Thiago Macieira cb372527df Update version number for TinyCBOR 0.6
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2021-09-03 11:56:36 -07:00
Thiago Macieira dbf8f13114 Update references of 'master' to 'main' 2021-09-03 11:48:37 -07:00
Thiago Macieira 11590e470d Docs: update to match the last commit for create_array() too
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
v0.5.4
2021-09-03 11:33:29 -07:00
Michael Richardson 4c7b15c58b clarify that CborIndefiniteLength creates an indefinite map, which is not always supported 2021-09-03 11:32:33 -07:00
Thiago Macieira 3d8da2ca83 Merge commit 'refs/pull/197/head' of github.com:intel/tinycbor 2021-09-03 11:30:45 -07:00
Thiago Macieira 5115a87bc7 Merge commit 'refs/pull/177/head' of github.com:intel/tinycbor 2021-09-03 11:29:44 -07:00
Michael Richardson d1062769ab change the argument name from "encoder" to "parentEncoder", as the names were unclear. containerEncoder could be the containing Encoder 2021-09-03 11:27:54 -07:00
Mahavir Jain 7c349dbb6b Add checks for memory allocation failures
Signed-off-by: Mahavir Jain <mahavir@espressif.com>
2021-02-24 21:30:37 -03:00
Michael Richardson e35f736b00 only build docs on master branch 2021-01-25 13:18:01 -05:00
Thiago Macieira 7dce551629 Merge branch 'master' into dev 2021-01-13 09:05:42 -08:00
Thiago Macieira 4a13b3ed3e parser: add a test that the string copy functions properly terminate
Or don't terminate, as the case may be.

Relates to #194.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2021-01-13 00:25:18 -03:00
Thiago Macieira 5d62d789c3 cborinternal_p.h: Fix AVX2 build with MSVC
MSVC (and I think ICC too) are lacking the simpler, scalar instructions
to convert from single-precision to half-precision and back. Instead, we
need to use the packed data intrinsics.

Fixes #192.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2020-12-25 20:06:24 -03:00
Thiago Macieira 369959ac3d AppVeyor: replace MSVC 2013 with 2019 2020-12-22 11:42:37 -03:00
Dan Church fc42a04985 Fix links to shared library upon "make install" 2020-10-24 01:13:13 -03:00
Shubham Patil 9924cfed3b Encoder: Update documentation
Exchanged function documentation of cbor_encode_text_string
and cbor_encode_byte_string

Signed-off-by: Shubham Patil <shubham.patil@espressif.com>
2020-08-13 12:31:10 -03:00
Stewart Gebbie c49bb8f5f1 Refine handling of container state synchronisation
When a container is closed, the outer container's buffer state is
synchronised with the inner container's state.

This was previously done via:

```
CborError cbor_encoder_close_container(CborEncoder *encoder, const CborEncoder *containerEncoder)
{
    if (encoder->end)
        encoder->data.ptr = containerEncoder->data.ptr;
    else
        encoder->data.bytes_needed = containerEncoder->data.bytes_needed;
    encoder->end = containerEncoder->end;

    ...

    return CborNoError;
}
```

However, strictly speaking the inner container could have updated `end` to be `NULL` if
the buffer was too small. In that case, the outer container should carry over `bytes_needed`
and not `ptr`. However, the logic was using the outer container's "stale" view of `end`.

However, generally `sizeof(ptr)` and `sizeof(bytes_needed)` are the same, and these values
exist in a union. Therefore, the correct values where still being copied.

This change moves the synchronisation of `end` to ahead of the synchronisation of `data`.

It additionally, actually avoids this potential error by simply synchronising the full `data`
structure, thereby avoiding the conditional logic. Simplifying the code to simply:

```
encoder->end = containerEncoder->end;
encoder->data = containerEncoder->data;
```
2020-07-28 18:17:41 -03:00
Alexander Richardson 71ce60962f Fix -Werror,-Wself-assign on big-endian systems
I was getting the following error when compiling cborencoder.c as part of
QtBase for FreeBSD MIPS64:
error: explicitly assigning value of variable of type 'uint64_t' (aka 'unsigned long') to itself [-Werror,-Wself-assign]
    v = cbor_htonll(v);

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
2020-07-28 13:41:04 -03:00
Ricardo Crudo 085ca40781 Enable build for different c libraries
The open_memstream.c was using GLIBC macro definition to test if the
library is building on a Linux box. This makes impossible to build
tinycbor against other C libraries, as musl for example.

Signed-off-by: Ricardo Crudo <ricardo.crudo@gmail.com>
2020-06-01 13:18:30 -03:00
Maciej Jurczak e608465164 Fixed a typo in cbor_value_is_byte_string documentation 2020-02-18 10:58:33 -08:00
Hamilton Chapman e373de2067 Fix tag registry documentation by formatting the table rows correctly 2020-02-10 09:31:00 -08:00
Svyatoslav Phirsov 1a43b45ed9 string pretty-print improved
string got plain old C output format to avoid confusion e.g. "true" string with CBOR true value

Signed-off-by: phirsov <41143811+phirsov@users.noreply.github.com>
2020-02-09 17:52:42 +03:00
Svyatoslav Phirsov 8acb09f5b0 bytestring output pretty-print improved
bytestring got escaped hex string literal output format to not to confuse e.g. "\x11" bytestring with 11 integer

Signed-off-by: phirsov <41143811+phirsov@users.noreply.github.com>
2020-02-09 17:51:07 +03:00
Svyatoslav Phirsov 722f6496c3 indentation typo fixed
printf s.b. used for indentation because no newline at end is needed

Signed-off-by: phirsov <41143811+phirsov@users.noreply.github.com>
2020-02-09 17:49:31 +03:00
Svyatoslav Phirsov 467b0ebc55 check app arguments in more strict manner
Signed-off-by: phirsov <41143811+phirsov@users.noreply.github.com>
2020-02-09 17:30:20 +03:00
Mathieu ef289000e1 Fix warning: __cplusplus / __cpp_static_assert is not defined
compilersupport_p.h : __cplusplus / __cpp_static_assert is not defined

Signed-off-by: Mathieu Stephan <contributors@themooltipass.com>
2020-01-30 07:49:31 -08:00
Mathieu 1300d8b71f Fix warning: initialization discards 'const' qualifier from pointer target type
cbortojson.c: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]

Signed-off-by: Mathieu Stephan <contributors@themooltipass.com>
2020-01-30 07:49:31 -08:00
Thiago Macieira 2b1105eb8b Fix version numbers for a possible 0.5.4 release 2019-11-13 12:23:16 -08:00
Thiago Macieira 755f9ef932 Parser: validate that maps have both key and value items
If a map end (Break byte) occurs before we've read the concrete item for
the value, then the map is invalid.

Fixes #167

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
v0.5.3
2019-10-22 08:11:21 -07:00
elie-elkhoury 1cc264a3fc Update cborencoder.c documentation
Fixed the error checking example proposed in the comments/documentation at the beginning of the file.
Changed occurrences of `if(!err)` to `if(err)`, and `cbor_assert(err)` to `cbor_assert(!err)`.

Signed-off-by: Elie El Khoury <eliekhoury@hotmail.de>
2019-10-10 09:34:43 -07:00
Sergio Martins d2dd95cb88 Fix compilation error in the documentation 2019-06-06 13:34:49 -07:00
Thiago Macieira 9a13e9252d Merge remote-tracking branch 'origin/master' into dev 2019-04-04 12:40:39 -07:00
Thiago Macieira e52b1d5bec Tests: Catch an earlier QCOMPARE failure in compare()
QCOMPARE macro has a return in case of failure. If a test fails inside
the encodeOne function, we log that error, but were proceeding to
perform more tests (which could fail again and produce more errors).

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2019-04-04 12:39:00 -07:00
Thiago Macieira 878eb01b96 Tests: remove useless comment
It's implemented.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2019-04-04 10:18:16 -07:00
Thiago Macieira 6643c174e4 Merge branch 'master' into dev 2019-03-15 10:12:23 -07:00
phirsov f1db0abccd enhancement #149 implemented: access half-precision floating point data as single float
Motivation: half-precision floating point format is used to minimize storage
and traffic mostly.  Application level manipulates with single and double
precision usually. So, two routines added to public API to encode/decode given
single precision value in the half precision format

Signed-off-by: S.Phirsov
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2019-03-15 10:11:00 -07:00