Standard library implementations may specify calling convention for memcpy
explicitly. However, the cbor* APIs don't do that. If you compile the lib
with default calling convention that doesn't match the calling convention o
memcpy(), the iterate_string_chunks() will not setup the stack for memcpy()
call correctly resulting in a stack corruption. The compiler doesn't catch
this issue because of the cast that is being applied when passing memcpy()
to the iterate_string_chunks().
The fix is to wrap memcpy() in a function that conforms to the declaration o
the IterateFunction which does two things, removes the need for a cast and
uncouples memcpy() calling convention from the rest of the cbor* APIs.
Signed-off-by: Alex Radutskiy (alex.radutskiy@microsoft.com)
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
This removes an ugly cast from the source and an unnecessary 1-byte
variable from the .rodata section.
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
Fix various errors when -Werror=pedantic flag is enabled:
Cast enum values to int to prevent errors like:
deps/tinycbor/src/cborconstants_p.h:47:31:\
error: ISO C restricts enumerator values to range of ‘int’\
[-Werror=pedantic]
MajorTypeMask = ~0U << MajorTypeShift,
"error: ISO C99 does not support" ‘Static_assert’
This effort is needed for RIOT port of iotivity-contrained
Bug-RIOT: https://github.com/RIOT-OS/RIOT/issues/6241
Signed-off-by: Philippe Coval <philippe.coval@osg.samsung.com>
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
The previous part of the Makefile didn't work properly. Instead of using
the contents of the VERSION file, it updated the file right before the
tagging and always for the next minor release.
Instead, move everything to a Perl script that updates the VERSION file
only after the tagging and sets up for a patch release (which are more
frequent). Updating of the dev branch is left as an exercise for the
reader.
As a bonus, this will work on Windows too without Unix shell tools.
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
This commit allos the use of the VERSION variable to set the version to
be tagged, instead of just incrementing the last digit in the VERSION
file.
It stops creating the .zip and .tar.gz files since those are kept in
GitHub anyway.
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
If the OOM condition happened on the encoding of the type and item
count, those two functions failed to return an error indicating that
there was an OOM. We had a unit test for this, but due to an off-by-one
error, we never actually tested the condition and just reported a false
positive.
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
User code might have stronger warning settings than the ones we've used
so far. The explict casting will make the compiler not complain, as it
was clearly intentional.
This fixes#45.
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
- Update Makefile.configure to test the availability of fopencookie
- If open_memstream is not available on the system AND funopen or fopencookie are available, compile our own version of open_memstream
- If open_memstream can not be compiled, return a new error (CborErrorJsonNotImplemented)
fixes#42
Signed-off-by: Fabrice Fontaine <fabrice.fontaine@orange.com>
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
There are at least two fixes in the codebase already due to macros that
should have come from stdint.h not being defined. I was blaming the
libc, as stdint.h is a C99 header and C99 requires those macros.
Turns out that the Arduino toolchain compiles everything as C++ and
officially C++98 does not have stdint.h, so "anything goes". The Arduino
docs recommend #define'ing __STDC_LIMIT_MACROS to get those macros.
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
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>