Commit Graph
126 Commits
Author SHA1 Message Date
Thiago Macieira fb10a783cd Update .gitignore
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-08-04 14:25:32 -07:00
Thiago Macieira ede7f1431a Revert "Revert "Give a name to unnamed union in CborEncoder""
This reverts commit 4628a110b7 and thus
brings 0e1440ab92 back.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-07-30 23:09:56 -07:00
Thomas Petazzoni 31c7f81d45 Makefile: use installation logic compatible with old make version
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>
v0.3.2
2016-07-30 23:07:32 -07:00
Thiago Macieira 1735f9cb7c Fix "make distcheck" when TMPDIR isn't set
Otherwise, we get this:
 GIT_DIR=./.git git archive --prefix=tinycbor-distcheck/ --format=tar HEAD | tar -xf - -C $TMPDIR
 tar: option requires an argument -- 'C'

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-07-30 23:07:32 -07:00
Thiago Macieira 4628a110b7 Revert "Give a name to unnamed union in CborEncoder"
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>
2016-07-30 23:04:46 -07:00
Fabrice Fontaine 0e1440ab92 Give a name to unnamed union in CborEncoder
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>
2016-07-30 12:26:04 -07:00
Thiago Macieira 481ec6e8a9 Use printf instead of echo -e in Makefile.configure
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>
v0.3.1
2016-07-22 08:51:40 -07:00
Fabrice Fontaine c88913e53c Fix compilation error due to file descriptor
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>
2016-07-21 08:35:18 -07:00
Thiago Macieira f775cf5b9d Merge branch 'master' into dev v0.3 2016-07-11 08:46:05 -07:00
Otavio Pontes e73e4d87be Add missing dependencies to cbordump build
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>
2016-07-11 08:45:15 -07:00
Thiago Macieira f2acf3cf40 Update .travis.yml to match new PPA repositories
After the Qt 5.6.1 release, Stephan renamed the repository.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-07-08 11:01:23 -07:00
Thiago Macieira b590a2be69 Merge branch 'master' into HEAD
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-07-08 10:05:48 -07:00
Otavio Pontes e2d5dd563e Fix _BSD_SOURCE is deprecated warning
In systems with glibc >= 2.2 _BSD_SOURCE is deprecated. In order to use
it and to keep compatibility with older systems _DEFAULT_SOURCE should
  also be defined when _BSD_SOURCE is defined, according to
feature_test_macros man page
(http://man7.org/linux/man-pages/man7/feature_test_macros.7.html)

Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-07-08 09:55:15 -07:00
Otavio Pontes 225304ddf8 Add tinycbor.pc to .gitignore
Signed-off-by: Otavio Pontes <otavio.pontes@intel.com>
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-07-08 09:55:15 -07:00
Otavio Pontes 4ce56694ed Remove from cborparser.c file the dependency on stdlib header
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>
2016-07-08 09:55:15 -07:00
Thiago Macieira 0f02e793b8 Parsing: implement the missing cbor_value_get_int{,64}_checked functions
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>
2016-07-07 20:40:13 -07:00
Thiago Macieira eabee060e3 CborValue: fix mis-named cbor_value_is_{null,undefined}
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>
2016-07-07 20:40:13 -07:00
Thiago Macieira cac5db5a60 CborValue: add missing convenience FP cbor_value_is_xxxx functions
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-07-07 20:40:13 -07:00
Thiago Macieira 740e29d225 Parsing: Add cbor_value_get_next_byte()
Replaces direct access to the "ptr" member.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-07-07 20:40:13 -07:00
Thiago Macieira 7ae36a7fad Add cbor_encoder_get_buffer_size and get_extra_bytes_needed
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>
2016-07-07 20:40:13 -07:00
Thiago Macieira 46a818e31f Finish TinyCBOR documentation
This commit adds the Doxyfile and the necessary Makefile commands

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-07-07 20:40:13 -07:00
Thiago Macieira 8384a4618c Update qmake build files
TinyCBOR doesn't use Qt. When compiling in release mode, disable
assert() from assert.h.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-07-07 20:40:13 -07:00
Thiago Macieira 0b7a4e7754 tst_Encoder: Remove the variance of NaN and inf due to compiler
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>
2016-07-07 20:40:13 -07:00
Thiago Macieira 9b33d71fb7 tst_Parser: Add a couple more tests related to array/map/string length
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-07-07 20:39:13 -07:00
Thiago Macieira dbc0129400 Convert C++/C99 style comments to C89
I'm only doing this once and I'll probably regress later.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-07-07 09:35:57 -07:00
Otavio Pontes 358a7e42ab Fix compilation for systems without math.h header
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>
v0.2.1
2016-07-07 09:35:41 -07:00
Thiago Macieira 8f73a36aaf Fix compilation of unit tests nesting QVariantList inside another
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>
2016-06-07 23:09:37 -07:00
Thiago Macieira 53091f803f Fix tests dealing with NaNs with MSVC
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>
2016-06-07 17:43:03 -07:00
Thiago Macieira 00ef1bb833 Fix compilation and warnings in the tests with MSVC
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-06-07 17:43:03 -07:00
Thiago Macieira 2085ad872e Add initial support for building with Visual Studio
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>
2016-06-07 17:43:02 -07:00
Thiago Macieira 5a52c14da0 Fix compilation in C89 mode: variables can't be declared in for stmt
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-06-07 17:39:09 -07:00
Thiago Macieira f750a10458 Fix compilation when using a C compiler that doesn't understand "inline"
It wasn't a keyword in C89. The relevant compiler is MSVC 2012.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-06-07 17:39:09 -07:00
Thiago Macieira e12dfd00c4 Fix a few more MSVC level 3 warnings
cbor.h(278): warning C4800: 'const uint16_t': forcing value to bool 'true' or 'false' (performance warning)
 cborencoder.c(295): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift
 cborparser.c(677): warning C4800: 'uintptr_t': forcing value to bool 'true' or 'false' (performance warning)

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-06-07 17:39:09 -07:00
Thiago Macieira 1d00c48afe Fix warnings printed by the Microsoft compiler at -W3
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>
2016-06-06 17:04:58 -07:00
Thiago Macieira ddd99e434c Fix the simplereader example after the API change a while ago
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>
2016-04-12 10:55:57 -07:00
Thiago Macieira ad42bb7ef2 Update travis to support Qt 5.6
The qt55 repository disappeared.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-04-12 10:55:57 -07:00
David Antler 5170a8f5b3 Add reference to header file for Windows.
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>
2016-03-17 17:12:52 -07:00
Mike Colagrosso 629d5b7182 parser: Set the length to 0 on error in extract_length()
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>
2016-02-25 09:04:26 -08:00
Thiago Macieira b80318ab06 Add a LICENSE file
Fixes #19

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-01-04 10:02:27 -02:00
Thiago Macieira 63abed98de Fix a parsing issue caused by pointer wraparounds
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>
2015-10-29 13:03:37 -07:00
Thiago Macieira 43e3ac9490 Add .travis.yml file 2015-10-17 21:36:43 -07:00
Thiago Macieira cd567bc8f9 Finish open_memstream for older glibc without it
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2015-10-17 21:36:43 -07:00
Thiago Macieira 5c1116ca4b Fix compilation on OS X: missing #include <locale.h>
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2015-10-17 21:36:43 -07:00
Thiago Macieira 4f9a6fd172 Fix and test the functions getting the sizes of containers
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>
2015-10-17 11:00:58 -07:00
Thiago Macieira f0791a2a12 Add missing #include
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2015-09-30 12:56:02 -07:00
Thiago Macieira 190a01f0ea Fix #16: sizeof(struct {}) is not allowed in C++
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2015-09-30 12:55:59 -07:00
Thiago Macieira db9904fcf9 Update the "make release" target to work
I used it for the v0.2 release.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2015-09-30 11:48:19 -07:00
Thiago Macieira 6cdac8ee07 Update version number
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
v0.2
2015-09-30 11:24:01 -07:00
Thiago Macieira 618d2f1d51 Micro-optimisation: Merge append_byte_to_buffer with append_to_buffer
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>
2015-09-29 18:50:27 -07:00
Thiago Macieira c9a9cffc38 Optimise the Base64 dumper
Just because I can.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2015-09-29 18:50:27 -07:00