Commit Graph
309 Commits
Author SHA1 Message Date
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 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 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 0362274505 Parser: apply the same memory-check update
See previous commit for more details. This just applies the same
technique using malloc/mmap to the the rest of the parser tests.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2019-03-06 09:50:04 -08:00
Thiago Macieira 57b66a8353 Validation: fix out-of-bounds access when content ends in a string
We can only validate_number() if we know that we have a number to
validate in the first place. If we've reached the end of our string, the
content that follows is not necessarily a number (it could be a Break
byte). More importantly, we could reach the end of the buffer.

This issue was masked by the way we provided data to the parser. It
always came from read-only memory becausee of QByteArray::fromRawData(),
so valgrind never caught any issues. Using QByteArray directly wouldn't
have helped because it always inserts a terminating null byte, which
always validates as a correct number (unsigned 0) and fails to trigger
valgrind.

So we need to use malloc() directly to make Valgrind complain. And there
was already a test that did:

==26543== Invalid read of size 1
==26543==    at 0x483EA10: memmove (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==26543==    by 0x43CEEA: read_bytes_unchecked (cborinternal_p.h:239)
==26543==    by 0x43CFEC: extract_number_checked (cborinternal_p.h:286)
==26543==    by 0x43D3E9: validate_number (cborvalidation.c:304)
==26543==    by 0x43DC7B: validate_value (cborvalidation.c:551)
==26543==    by 0x43DE8C: cbor_value_validate (cborvalidation.c:645)
==26543==    by 0x4328D2: tst_Parser::strictValidation() (tst_parser.cpp:1637)
==26543==    by 0x434632: tst_Parser::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) (tst_parser.moc:291)
==26543==    by 0x4C0B36D: QMetaMethod::invoke(QObject*, Qt::ConnectionType, QGenericReturnArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument) const (qmetaobject.cpp:2310)
==26543==    by 0x48673E9: QMetaMethod::invoke(QObject*, Qt::ConnectionType, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument) const (qmetaobject.h:122)
==26543==    by 0x4860256: QTest::TestMethods::invokeTestOnData(int) const (qtestcase.cpp:922)
==26543==    by 0x4860D4B: QTest::TestMethods::invokeTest(int, char const*, QTest::WatchDog*) const (qtestcase.cpp:1121)
==26543==  Address 0x61c4db1 is 0 bytes after a block of size 1 alloc'd
==26543==    at 0x483777F: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==26543==    by 0x403891: ParserWrapper::allocateMemory(unsigned long) (tst_parser.cpp:181)
==26543==    by 0x436898: ParserWrapper::init(QByteArray const&) (tst_parser.cpp:126)
==26543==    by 0x432712: tst_Parser::strictValidation() (tst_parser.cpp:1634)
==26543==    by 0x434632: tst_Parser::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) (tst_parser.moc:291)
==26543==    by 0x4C0B36D: QMetaMethod::invoke(QObject*, Qt::ConnectionType, QGenericReturnArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument) const (qmetaobject.cpp:2310)
==26543==    by 0x48673E9: QMetaMethod::invoke(QObject*, Qt::ConnectionType, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument) const (qmetaobject.h:122)
==26543==    by 0x4860256: QTest::TestMethods::invokeTestOnData(int) const (qtestcase.cpp:922)
==26543==    by 0x4860D4B: QTest::TestMethods::invokeTest(int, char const*, QTest::WatchDog*) const (qtestcase.cpp:1121)
==26543==    by 0x4862083: QTest::TestMethods::invokeTests(QObject*) const (qtestcase.cpp:1465)
==26543==    by 0x4862C14: QTest::qRun() (qtestcase.cpp:1903)
==26543==    by 0x48626C3: QTest::qExec(QObject*, int, char**) (qtestcase.cpp:1792)
==26543==
PASS   : tst_Parser::strictValidation(bytearray-0)

This commit goes further and makes it so an out-of-bounds access will
cause a pagefault.

Fixes #156.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2019-03-05 20:01:37 -08:00
Thiago Macieira 49ef3f89ac Pretty: fix use of uninitialised variable
The string chunk getter doesn't set ptr if there was an error
decoding. Instead, we need to deal with the error first.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2019-03-05 19:59:25 -08:00
Thiago Macieira 587ff539ba Update Travis CI to Ubuntu Xenial
This updates to Qt 5.12, since Stephan has a build for that in his
PPA. But we need to turn off RDRNAD support for the Valgrind build, as
it doesn't understand that instruction.

This also downgrades GCC to 5.4, which is what comes by default with
Travis CI.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2019-03-05 15:13:00 -08:00
Pedro Oliveira d75f2ebf65 Fixed minor error in the example code.
Signed-off-by: pelco <pelco89@gmail.com>
2019-01-11 12:11:33 -08:00
phirsov 7b08a99b9e Make AppVeyor test suit run silent as in Travis
Signed-off-by: phirsov <41143811+phirsov@users.noreply.github.com>
2018-12-06 14:44:17 -08:00
phirsov 3c910cf144 Run check silently in Travis
Run unittest in Travis in the silent mode to avoid Travis log cluttering

Signed-off-by: phirsov <41143811+phirsov@users.noreply.github.com>
2018-12-06 12:24:22 -08:00
phirsov e9c6ebe9d6 eliminating misleading messages in case .config file not yet created
Signed-off-by: phirsov <41143811+phirsov@users.noreply.github.com>
2018-12-04 15:15:32 -08:00
Svyatoslav Phirsov 1db99f95f2 typo in dumprecursive return type
should be CborErrorr rather than bool
2018-10-23 10:47:40 -07:00
Svyatoslav Phirsov 2b267847ef Typo fixed in stdlib fread(...) usage
fread(...) function returns the number of items read so far, not number of bytes, ergo, reading one st.st_size sized item produces 1 on success and 0 on failure.
Possibly fixing issue #77

Signed-off-by: phirsov <41143811+phirsov@users.noreply.github.com>
2018-10-13 16:26:48 -07:00
phirsov 37d4ba453a Protect macro argument expansion using parentheses
Fixes #141

Signed-off-by: phirsov <41143811+phirsov@users.noreply.github.com>
2018-10-13 09:51:43 -07:00
phirsov 3f0a830fad Fix off-by-one causing buffer overflow in open_memstream
Fixes #140

Signed-off-by: phirsov <41143811+phirsov@users.noreply.github.com>
2018-10-13 09:51:43 -07:00
Fabrice Fontaine d072f461e9 fix undefined encode_half in json2cbor
encode_half has been moved from compilersupport_p.h to cborinternal_p.h
in commit bfc40dcf90 so include this file
in json2cbor to avoid the following build failure:

/home/buildroot/autobuild/run/instance-0/output/host/bin/microblazeel-linux-gcc -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I./src -std=gnu99 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -Os    -c -o tools/json2cbor/json2cbor.o tools/json2cbor/json2cbor.c
tools/json2cbor/json2cbor.c: In function 'decode_json_with_metadata':
tools/json2cbor/json2cbor.c:295:50: warning: implicit declaration of function 'encode_half' [-Wimplicit-function-declaration]
                                          (half = encode_half(v), cbor_encode_half_float(encoder, &half));
                                                  ^~~~~~~~~~~
/home/buildroot/autobuild/run/instance-0/output/host/bin/microblazeel-linux-gcc -o bin/json2cbor  tools/json2cbor/json2cbor.o lib/libtinycbor.so -lcjson -lm
tools/json2cbor/json2cbor.o: In function `decode_json_with_metadata':
(.text+0xe54): undefined reference to `encode_half'
collect2: error: ld returned 1 exit status
Makefile:151: recipe for target 'bin/json2cbor' failed

Fixes:
 - http://autobuild.buildroot.net/results/afd8d24f2a4e501264abff618cf421d4bd088ebf

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2018-09-21 09:43:08 -07:00
Thiago Macieira 2421690d44 Fix #137: off-by-one error in UTF-8 decoding
I ported this from code I had written for Qt, where the subtraction was
correct. Qt's code is roughly:

    uchar b = *src++;
    ...
    int bytesAvailable = Traits::availableBytes(src, end);
    if (Q_UNLIKELY(bytesAvailable < charsNeeded - 1)) {

Which means src was advanced by the time we call Traits::availableBytes,
meaning that call returns the number of continuation bytes only. Our
code was:

    ptrdiff_t n = end - *buffer;
    ...
    uc = *(*buffer)++;
    ...
    if (n < charsNeeded - 1)

Which means our n is the total number of bytes, including the first
byte.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2018-09-21 09:41:57 -07:00
Thiago Macieira 27d913e0d5 Update version number for a possible but unlikely 0.5.3 release
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2018-09-09 09:24:40 -07:00
Thiago Macieira d94ca09aa9 Install the tinycbor-version.h header.
Fixes #136.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
v0.5.2
2018-09-08 22:33:57 -07:00
Thiago Macieira bfc40dcf90 Move the floating point code to cborinternal_p.h
... and put it behind #ifndef CBOR_NO_FLOATING_POINT.

The functions were not really compiler support, but are internal
functionality of TinyCBOR. This commit also puts both the <math.H> and
<float.h> headers behind an #if, so constrained systems without floating
point support won't enable it.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2018-08-13 21:03:31 -07:00
Thiago Macieira 88943666c4 Properly link the shared libtinycbor.so to -lm
The hosted version makes use of math functions (usually, we don't test
that CBOR_NO_FLOATING_POINT is defined).

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2018-08-13 21:03:31 -07:00