The installation logic used by the Makefile causes a problem with old
make versions, such as make 3.81. Indeed, the rule "$(DESTDIR)%/" gets
matched even for targets like "$(DESTDIR)$(libdir)/libtinycbor.a". Due
to this, with those old make versions, tinycbor.a is installed as a
directory, and the library is never copied:
make[1]: Entering directory `/home/test/outputs/b1305500555cbb5b959e5be11dee5cf75907f0ce/output/build/tinycbor-v0.3.1'
install -d /home/test/outputs/b1305500555cbb5b959e5be11dee5cf75907f0ce/output/target/usr/bin/cbordump
install -d /home/test/outputs/b1305500555cbb5b959e5be11dee5cf75907f0ce/output/target/usr/lib/libtinycbor.a
install -d /home/test/outputs/b1305500555cbb5b959e5be11dee5cf75907f0ce/output/target/usr/lib/pkgconfig/tinycbor.pc
install -d /home/test/outputs/b1305500555cbb5b959e5be11dee5cf75907f0ce/output/target/usr/include/tinycbor/cbor.h
install -d /home/test/outputs/b1305500555cbb5b959e5be11dee5cf75907f0ce/output/target/usr/include/tinycbor/cborjson.h
make[1]: Leaving directory `/home/test/outputs/b1305500555cbb5b959e5be11dee5cf75907f0ce/output/build/tinycbor-v0.3.1'
To address this, we create the destination directory directly within
the per-file make targets.
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
This breaks the build in two circumstances:
a) tools/json2cbor wasn't included in the change
b) some old code accessed the ptr member before
cbor_encoder_get_buffer_size and cbor_encoder_get_extra_bytes_needed
This reverts commit 0e1440ab92. I will
re-apply it in the master branch and fix the missing code.
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
cbor.h contains an unnamed union in CborEncoder structure, this functionality is
not always supported by all compilers, especially it seems that the Blackfin
build on buildroot fails (with gcc 4.3). This patch names this union "data".
Signed-off-by: Fabrice Fontaine <fabrice.fontaine@orange.com>
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
echo -e is not POSIX-compliant, but printf is supposed to interpret
escaped sequences like \n.
Fixes: #34
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
In Makefile, the file descriptor 10 is used to redirect input to .config:
$(MAKE) -f $(SRCDIR)Makefile.configure OUT='>&10' configure 10> $@
This patch replaces this file descriptor from to 10 to 9 as
"Redirections using file descriptors greater than 9 should be used with
care, as they may conflict with file descriptors the shell uses
internally."
(cf. https://www.gnu.org/software/bash/manual/html_node/Redirections.html)
Signed-off-by: Fabrice Fontaine <fabrice.fontaine@orange.com>
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
Compilation was failing when trying to compile cbordump running make in
tools directory. Add missing dependencies, cbortojson and
cborparser_dup_string to cbordump Makefile.
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
Function _cbor_value_dup_string from cborparser.c is using malloc/free
functions, from sdtlib header, so it is not possible to compile the
cborparser in systems without stdlib support. Move this function to a
different c file in order to remove the dependency on stdlib header from
cborparser.
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
The int64_t version is easier because the C99 & C11 standards require
that int64_t use two's complement representation. We're unlikely to find
an architecture that supports two's complement 64-bit but doesn't
support it for int, but the code is written to be strictly conforming.
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
The cbor_type_is_ prefix is an old iteration of the API. Apparently I
never tested the "is" functions.
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
This removes the need for people to go messing with the internals of
CborEncoder. It also provides an alternative way to determine if a
buffer OOM error occurred without checking the return value of each
function. That, of course, requires the user to be sure no other error
can happen.
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
Some compiler represent NaNs and some infinite numbers with different
bit pattern than others. Since TinyCBOR encodes without changing the
pattern, let's make sure we use only one pattern (I chose the one that
RFC 7049 shows).
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
cbortojson and cborpretty depends on decode_half function from
compilersupport_p.h that uses math.h functions. As cbortojson and
cborpretty are usually important only in development phase, move math
dependency to another header so it is now possible to compile tinycbor
in systems that doesn't provide math.h header
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
MSVC 2015 and GCC disagree on which constructor to call. When you write:
QVariantList{another_list}
GCC calls the std::initializer_list constructor (by converting the first
parameter to QVariant), whereas MSVC calls the copy constructor. That
meant that the tests that expected to see nested arrays didn't.
Clang and the Intel compiler agree with MSVC. However, the behaviour in
GCC is the expected correct behaviour after CWG2137 is resolved
(http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0384r0.html#2137).
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
The MS compiler represents NaNs differently from GCC. The most important
difference is that GCC leaves the sign bit set and MSVC doesn't, which
changes the representation. In the case of our data containing the sign
bit set, sprintf() shows the sign explicitly.
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
cbortojson.c uses open_memstream for part of its functionality, which
isn't available with the Microsoft CRT, so it's excluded.
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
src\cbor.h(268): warning C4244: '=': conversion from 'const uint16_t' to 'uint8_t', possible loss of data
src\cbor.h(422): warning C4244: 'initializing': conversion from 'uint64_t' to 'uint32_t', possible loss of data
src\cborencoder.c(134): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
src\cbortojson.c(410): warning C4244: '=': conversion from 'uint64_t' to 'double', possible loss of data
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
We changed a lot of "char*" that was binary to "uint8_t*". The example
was never fixed.
This fixes#23.
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
stdlib.h includes the definition for _byteswap_ushort, without which the
compiler will assume an int return value.
Signed-off-by: David Antler <david.a.antler@intel.com>
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
This silences a false-positive compilation warning
[-Werror=maybe-uninitialized] in iterate_string_chunks() that some
variables were used without initialisation.
Fixes#21
Signed-off-by: Mike Colagrosso <colagrosso@users.noreply.github.com>
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
If the size of the string was a suitable value, the "ptr + total" check
could overflow and we wouldn't know because the sum would most likely be
smaller than value->parser->end. We would then proceed to allocate a
silly amount of memory.
I never caught this in my own testing because, on Linux, the heap
usually starts in the low 4 GB of the address space, so adding
0xffffffff000000000 would not cause an overflow. However, on OS X, the
heap starts above 4 GB, so the pointer does wrap around.
So test specifically for the pointer wraparound cases, plus the case of
sizes larger than the address space in 32-bit systems.
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
This fixes#17. The internal parser->remaining counter is multiplied by
two for maps to make the decoder easier, but that does not apply to the
cbor_value_get_map_length() function. So remove the division by two.
Add a lot of tests to make sure we don't regress anymore.
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
This makes the cborencoder.o only 986 bytes with -Os on x86-64. The
function is still inlined with -O2.
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>