Commit Graph
227 Commits
Author SHA1 Message Date
Thiago Macieira 3cdb9c890b Add a script to make docs in Travis
This also stores the current library sizes (in -Os / -Oz build modes)
for each branch,

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
v0.5.0
2018-01-30 14:21:35 -08:00
Thiago Macieira 301e263afb Update the ELF soname not to say "libtinycbor.so.0"
Since we're not (yet) guaranteeing binary compatibility, let's use 0.5
as the "soversion".

This changes the version number stored in the VERSION file so that the
actual library file is "libtinycbor.so.0.5.0". As an indirect
consequence, the release will be tagged "v0.5.0", which sorts after
"v0.5-beta1".

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2018-01-30 14:01:23 -08:00
Thiago Macieira f2b75b8721 Make it easier to build only the freestanding code
Freestanding C, as opposed to hosted C (see the macro), is restricted to
a few C headers and usually lacks a libc. In our case, that means we
cannot assume <stdio.h> and FILE* is present, but we do require
<string.h> (memcpy, memcmp).

This commit simply makes it easier for me to test that TinyCBOR still
compiles in freestanding mode. Eventually I need to test with an actual
Zephyr build (issue #40).

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2018-01-30 13:43:49 -08:00
Thiago Macieira 5515a99434 Parser: remove the cbor_value_get_xxxx_string_chunk() API
It's really good, but I need to redesign it in order to support the
chained buffers found in Zephyr[1][2] and Mynewt. I'll bring it back in
0.6 when I introduce support for parsing directly from chained buffers
too.

[1] http://docs.zephyrproject.org/api/networking.html#network-buffers
[2] https://github.com/zephyrproject-rtos/zephyr/blob/master/include/net/buf.h

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2018-01-30 12:04:05 -08:00
Thiago Macieira 2a38a95ca5 Parser: merge the break-handling code in enter_container()
There was a section of code that was mostly the same, dealing with the
possibility of reading a Break (0xFF) as the next element in a map or
array. The only difference was that preparse_next_value() also
decremented the item count for the current list.

We could have used that, but that would have meant a +1 on the list,
which in turn lowers the number of possible elements from UINT32_MAX-1
to UINT32_MAX-2. Not a big deal, but we can avoid it by just splitting
to a new function and retaining tail-call optimisations.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2018-01-30 10:38:04 -08:00
Thiago Macieira 497066ee87 Encoder: Fix off-by-one error encoding negative numbers
The documentation said we encoded the negative value equivalent to the
passed absolute value. That means encode_number() requires the
subtraction.

This commit takes the opportunity to unit-test the rest of the integer
API in the parser.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
v0.5-beta1
2018-01-23 10:36:41 -08:00
Thiago Macieira 1b9a6401ea JSON: Change the first number of the JSON conversion errors
This gives us a little more room to add validation errors when we have
to keep binary compatibility.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2018-01-23 10:36:25 -08:00
Thiago Macieira e5843df411 Tests: change a few more QCOMPARE to print the error message.
Commit 36bdbfb854 did not catch all cases.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2018-01-13 08:41:07 -08:00
Thiago Macieira f8514e3d0e Test Clang and release GCC builds in Travis
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2018-01-13 08:41:07 -08:00
Thiago Macieira cc2bfbb209 Encoder: Change the way we reckon the number of items added
Instead of counting forward the number of items added, which meant we
couldn't know in cbot_encoder_close_container() whether we had added
enough, let's count backwards. The number is offset by 1 so we should be
at 1 if we added exactly as many items as we had expected to. Zero means
we added too many. Any other number means we added too few.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2018-01-13 14:37:40 -02:00
Thiago Macieira d3c47d2296 Valiation: suppress warning about uninitialized variables
GCC7 complains, though it's wrong:

 src/cborvalidation.c:472:57: error: ‘previous’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
 src/cborvalidation.c:485:61: error: ‘previous_end’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2018-01-13 14:36:35 -02:00
Thiago Macieira f39dcb8b56 Pretty: move the two functions taking FILE* to a separate file
This now allows the cborpretty.c source to be compiled even in C
freestanding environments.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2018-01-02 17:05:44 -06:00
Thiago Macieira ee63f791be Pretty: add the ability to stream out to a generic thing
Instead of always requiring FILE *. This does mean a slight code size
increase, since we now have to pass an extra parameter down the function
stack, plus we're making indirect calls, but it's worth it.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2018-01-02 17:05:44 -06:00
Thiago Macieira 36bdbfb854 Tests: print the error message insead of just a number (or nothing)
Some QCOMPARE did convert to int() so we would see an error number, but
not all comparisons did. For those those that didn't, QCOMPARE would
just print that the values differed, but not show what.

So try to harmonize on printing the error message.

I may not have caught all uses...

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-12-26 19:05:32 -06:00
Thiago Macieira 345ffce82a Add support for more half-float values
Since Qt 5.9 has qfloat16, it became easier to write values. There was
no point with just the stand-in type, since the encoder would write
exactly the bytes we gave it.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-12-26 19:01:58 -06:00
Thiago Macieira b087939748 Parser: set *len = 0 in the last string chunk
Probably a good idea anyway, plus solves a false positive warning:

 src/compilersupport_p.h:192:34: error: ‘chunkLen’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     return __builtin_add_overflow(v1, v2, r);
            ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
 src/cborparser.c:1163:16: note: ‘chunkLen’ was declared here
         size_t chunkLen = chunkLen;
                ^~~~~~~~

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-12-26 19:01:29 -06:00
Thiago Macieira c3c7bf63ed Only #include <assert.h> if assert isn't yet defined
The C standard requires every the macro to be redefined every time that
<assert.h> is included. It does so you can change NDEBUG from one

But that also means a wrapper couldn't #define assert to their own
macro. So stop overriding.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-12-26 14:28:39 -06:00
Thiago Macieira e5662358cb Brown paper bag: forgot to change the PATH to Qt
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-12-26 18:24:11 -02:00
Thiago Macieira 09e4f8e436 Update Qt to 5.9 on Travis/Linux testing
The Windows builds on Appveyor use 5.9; the macOS builds on Travis use
the latest from Homebrew, which is currently 5.10.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-12-26 18:10:29 -02:00
Thiago Macieira afa273cffe Add #include guards to the utf8_p.h internal header
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-12-22 09:55:14 -08:00
Thiago Macieira c4fa09e196 Validation: make sure that it compiles in C++ mode too
Like the rest of our parser and encoder, it's useful to be #include'd in
C++ souces.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-12-21 14:01:32 -08:00
Thiago Macieira d1f9416db4 Pretty: limit the number of recursions, like the Parser
The pretty-dumper code did not have a limit, assuming that the input had
been validated beforehand, so if the nesting was too deep, one would
have got an error before getting to the dumper.

However, it's not inconceivable that someone adds a logger code to a
packet a bit too early. So let's be defensive and apply the limiter here
too.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-12-21 13:04:48 -08:00
Thiago Macieira 5433fc38ef Encoder: Fix the returning of OOM errors in closing containers
Conditional added by 3369dd1f01 was
inverted.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-12-19 11:09:37 -08:00
Thiago Macieira 4df836436c Invert the way we account for the recursion level
This allows advance_recursive to be called with different levels when
called directly.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-12-18 10:40:18 -08:00
Thiago Macieira ed68cdae5f Merge remote-tracking branch 'origin/dev' into HEAD 2017-12-17 23:48:22 -08:00
Thiago Macieira 78905c85da Add the -f flag to ln, to force symlink creation
Otherwise, remaking ends with:

 ln: failed to create symbolic link 'libtinycbor.so': File exists
 ln: failed to create symbolic link 'libtinycbor.so.0': File exists

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-12-17 23:46:54 -08:00
Thiago Macieira 8dcde96b65 Fix warning about implicitly casting a double to float
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-12-17 23:45:27 -08:00
Vipul Rahane 650c31f3be Fix compiler warnings for tst_cpp
- The defines(_BSD_SOURCE, _DEFAULT_SOURCE) were getting defined in multiple source files generating
  warnings
- Solution is to conditionally define the above
2017-12-16 20:39:48 -08:00
Fabrice Fontaine 19b26bd416 Add BUILD_STATIC option
- Enable BUILD_STATIC by default
 - If BUILD_STATIC and BUILD_SHARED are both different from 1, return an
error
 - If BUILD_STATIC is disabled, use shared library for binaries
 - If both are enabled, use the static library

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2017-12-07 13:20:48 -08:00
Erich Keane a2dab2c9b2 Update documentation link in README 2017-12-06 18:25:51 -08:00
Thiago Macieira df440a0891 Make sure that -fPIC objects are removed in make clean
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-11-13 22:28:07 -08:00
Thiago Macieira aa692b7863 Fix build on non-ELF systems (macOS): don't build the shared library
Detect if this is an ELF system by checking if /bin/sh is ELF. This can
be configured manually with:
   make BUILD_SHARED=0
or
   make BUILD_SHARED=1

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-11-13 20:54:30 -08:00
Thiago Macieira 110d6bc02c Fix Travis builds on macOS
Travis and Homebrew have been at odds: the Ruby in PATH is not what
Homebrew wants, so it prints:

 /usr/local/Homebrew/Library/Homebrew/brew.rb:12:in `<main>': Homebrew must be run under Ruby 2.3! You're running 2.0.0. (RuntimeError)

Info in the Travis's own GitHub bug report indicates "brew update" fixes
this issue, even though it increases the build time.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-11-13 20:30:43 -08:00
Thiago Macieira 5a9dae7420 Merge tag 'v0.4.2' into dev
TinyCBOR release 0.4.2

This is a bugfix release. Important bugs fixed in this release:
 - Fixed builds against a static cJSON
 - Fixed MSVC builds
 - Fixed builds on freestanding C implementation (no FILE* API)
 - Fixed the return value of cbor_encoder_close_container when a previous OOM
   condition had been detected
 - Fixed the build in strict C89 mode (no C99 extensions)

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-11-13 19:25:56 -08:00
Philippe Coval f9457017aa json2cbor: Initialize index before "for scope"
Observed issue on earlier version:

  json2cbor.c:157:5: error: for loop initial declarations are only allowed in C99 mode

Note, it's not mandatory for current master branch
since build script already sets the c99 flag,
but it won't cause any harm.

Signed-off-by: Philippe Coval <philippe.coval@osg.samsung.com>
v0.4.2
2017-11-13 19:13:06 -08:00
Thiago Macieira 4bd38cfa83 Silence the annoying warning in MSVC about undeclared bswap
..\..\src\cborparser.c(149): warning C4013: '_byteswap_ushort' undefined; assuming extern returning int
 ..\..\src\cborparser.c(156): warning C4013: '_byteswap_ulong' undefined; assuming extern returning int
 ..\..\src\cborparser.c(163): warning C4013: '_byteswap_uint64' undefined; assuming extern returning int

This apparently also fixes the unit test failures.

 FAIL!  : tst_Parser::fixed(UINT32_MAX+1) Compared values are not the same
   Actual   (decoded) : "0_3"
   Expected (expected): "4294967296"
 .\tst_parser.cpp(233) : failure location

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-11-13 13:58:31 -08:00
Thiago Macieira 49c15d986c Fix MSVC build: cborvalidation.obj wasn't added to the library
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-11-13 13:18:23 -08:00
Thiago Macieira ad288d51e4 Add the .appveyor.yml file for testing MSVC on AppVeyor CI
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-11-13 12:56:05 -08:00
Thiago Macieira 3369dd1f01 Make sure we return the OOM error condition when closing containers
Usually, if you ignore the OOM error, the encoder API may start
returning success, even though no buffer overrun happens. The way to
check if an OOM happened is with cbor_encoder_get_extra_bytes_needed,
which will return non-zero if a larger buffer is returned.

That said, the API was mostly already returning the OOM error
consistently, due to almost everything ending up calling
append_to_buffer(). This case was an exception.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-11-13 11:14:27 -08:00
Thiago Macieira eb4bedbf36 Add a function to obtain the CborEncoder's current pointer
This is better than mucking with the struct's internals. I plan to
change it soon by adding more unions, to support fragmented buffers on
constrained OSes like Zephyr.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-11-13 11:11:03 -08:00
Thiago Macieira dde26c81ac Change the CborErrorInternalError value to be non-negative
We want CborErrorOutOfMemory to be the only negative value (or at least
with sign bit set), so the internal error constant can't be that.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-11-13 11:10:17 -08:00
Thiago Macieira 65f71172d6 Fix spelling of "Double" in the tag parsing script
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-11-13 11:09:04 -08:00
Thiago Macieira 2fe481c0ce Add the CBOR Object Signing and Encryption tags (RFC 8152)
This also adds #defines for the CborXxxTag identifiers so user code can

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-10-07 16:18:01 -04:00
Thiago Macieira 15dfacff6c Fix the build outside of Linux: disable shared libraries
Technically, they should be allowed on the BSDs, but it's far easier to
whitelist than blacklist.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-10-07 16:17:01 -04:00
Bertrand Roussel 47914e0fa1 Provide shared library
Some people may want to use tinycbor as a shared library instead of
as a static library, so providing a set of .so accordingly.

Even with the static library, I'm having trouble incorporating it
into another shared library, so providing -fPIC option as well.

Signed-off-by: Bertrand Roussel <broussel@sierrawireless.com>
2017-10-07 13:16:46 -07:00
Thiago Macieira effaf7d5c3 Merge branch 'master' into dev
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-10-07 15:38:31 -04:00
Thiago Macieira 85c9f81c2d Update Qt installation to 5.6.3 for Travis
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-10-07 15:28:08 -04:00
Thiago Macieira 45ab2d085a Remove the #pragma for -ffunctions-sections
Recent GCC have begun complaining about it. The buildsystem should do
this, not a header.

 compilersupport_p.h:175:11: warning: bad option '-ffunction-sections' to pragma 'optimize' [-Wpragmas]

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-09-29 11:12:10 -07:00
Bertrand Roussel 70f58e8b8a Fix LICENSE
Updating LICENSE file so project can be recognized as MIT in
GitHub.

Signed-off-by: Bertrand Roussel <broussel@sierrawireless.com>
2017-07-26 10:29:17 -07:00
Thiago Macieira 25ea8aff91 Hide the API using FILE* from freestanding C implementations
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-06-09 12:49:45 -07:00