22 Commits
Author SHA1 Message Date
Thiago Macieira a088996aa5 Update "make release" target
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>
2016-11-02 22:00:07 -07:00
Thiago Macieira 8fc4528745 Merge branch 'master' into dev
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-11-02 21:30:10 -07:00
Thiago Macieira 0a78b71322 Fix forgotten update of the number of characters left in dumping UTF-8
We forgot to update the counter variable. This fixes #54.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-11-02 21:14:18 -07:00
James Prestwood eed8aa4b6c Fixed duplicate definitions for targets with certain macros already defined
Signed-off-by: James Prestwood <james.prestwood@intel.com>
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-11-02 20:52:29 -07:00
Thiago Macieira 863a480dc4 Fix #51: correct OOM reporting in cbor_encoder_create_{array,map}
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>
2016-10-26 20:48:54 -07:00
alradmsft 9ba4791ad5 Supress data loss warnings in VS2015
Where safe, use explicit casts to supress data loss warnings in VS2015
compiler.

This fixes #45.

Signed-off-by: Alex Radutskiy (alex.radutskiy@microsoft.com)
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-10-20 07:30:56 -07:00
Fabrice Fontaine ad09b6af11 Fix detection of system-cjson
Replace CCLFAGS-system-cjson by CCFLAGS-system-cjson

Fixes:
  - http://autobuild.buildroot.net/results/8fc/8fc7365e0dc777edc57e950a84df7fddc13c6776

Signed-off-by: Fabrice Fontaine <fabrice.fontaine@orange.com>
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-10-11 16:17:18 +02:00
Thiago Macieira 0171135ec3 Merge branch 'master' into dev
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-10-11 09:37:26 +02:00
Thiago Macieira 7f554dd5b1 Update .gitignore files
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-10-07 15:13:31 +02:00
Thiago Macieira 806f0c99b0 cbor.h: Add explicit casts to conversions from uint64_t to size_t
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>
2016-10-07 15:10:18 +02:00
Thiago Macieira a27578f7bc Merge branch 'master' into dev
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-10-03 20:52:21 +02:00
David Antler a50c0122f2 Update VERSION file
Signed-off-by: David Antler <david.a.antler@intel.com>
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-10-03 20:52:02 +02:00
Thiago Macieira 075562fe4a Merge branch 'master' into dev 2016-08-31 12:25:11 -07:00
Fabrice Fontaine 04ada5890c Properly manage open_memstream availability
- 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>
2016-08-31 10:39:48 -07:00
Thiago Macieira 930b265d36 Merge branch 'master' into dev
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2016-08-04 14:39:05 -07:00
Thiago Macieira 86c8186775 Properly fix support for stdint.h on Arduino
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>
2016-08-04 14:28:01 -07:00
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>
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
17 changed files with 128 additions and 51 deletions
+2 -1
View File
@@ -24,6 +24,7 @@ pcviewer.cfg
*.*#
core
.qmake.cache
.qmake.stash
.qmake.vars
.device.vars
tags
@@ -76,5 +77,5 @@ doc
lib
src/cjson
src/doxygen.log
!Makefile
!/Makefile
.config
+30 -13
View File
@@ -29,7 +29,6 @@ TINYCBOR_SOURCES = \
src/cborparser_dup_string.c \
src/cborpretty.c \
src/cbortojson.c \
$(if $(open_memstream-pass),,src/open_memstream.c) \
#
CBORDUMP_SOURCES = tools/cbordump/cbordump.c
@@ -72,6 +71,17 @@ endif
-include .config
# if open_memstream is unavailable on the system, try to implement our own
# version using funopen or fopencookie
ifeq ($(open_memstream-pass),)
ifeq ($(funopen-pass)$(fopencookie-pass),)
CFLAGS += -DWITHOUT_OPEN_MEMSTREAM
$(warning warning: funopen and fopencookie unavailable, open_memstream can not be implemented and conversion to JSON will not work properly!)
else
TINYCBOR_SOURCES += src/open_memstream.c
endif
endif
# json2cbor depends on an external library (cJSON)
ifneq ($(cjson-pass)$(system-cjson-pass),)
JSON2CBOR_SOURCES = tools/json2cbor/json2cbor.c
@@ -123,15 +133,17 @@ $(PACKAGE).tar.gz: | .git
$(PACKAGE).zip: | .git
GIT_DIR=$(SRCDIR).git $(GIT_ARCHIVE) --format=zip -o "$(PACKAGE).zip" HEAD
$(DESTDIR)%/:
$(INSTALL) -d $@
$(DESTDIR)$(libdir)/%: lib/% | $(DESTDIR)$(libdir)/
$(DESTDIR)$(libdir)/%: lib/%
$(INSTALL) -d $(@D)
$(INSTALL_DATA) $< $@
$(DESTDIR)$(bindir)/%: bin/% | $(DESTDIR)$(bindir)/
$(DESTDIR)$(bindir)/%: bin/%
$(INSTALL) -d $(@D)
$(INSTALL_PROGRAM) $< $@
$(DESTDIR)$(pkgconfigdir)/%: % | $(DESTDIR)$(pkgconfigdir)/
$(DESTDIR)$(pkgconfigdir)/%: %
$(INSTALL) -d $(@D)
$(INSTALL_DATA) $< $@
$(DESTDIR)$(includedir)/tinycbor/%: src/% | $(DESTDIR)$(includedir)/tinycbor/
$(DESTDIR)$(includedir)/tinycbor/%: src/%
$(INSTALL) -d $(@D)
$(INSTALL_DATA) $< $@
install-strip:
@@ -160,16 +172,22 @@ docs:
dist: $(PACKAGE).tar.gz $(PACKAGE).zip
distcheck: .git
-$(RM) -r $$TMPDIR/tinycbor-distcheck
GIT_DIR=$(SRCDIR).git git archive --prefix=tinycbor-distcheck/ --format=tar HEAD | tar -xf - -C $$TMPDIR
cd $$TMPDIR/tinycbor-distcheck && $(MAKE) silentcheck
$(RM) -r $$TMPDIR/tinycbor-distcheck
-$(RM) -r $${TMPDIR-/tmp}/tinycbor-distcheck
GIT_DIR=$(SRCDIR).git git archive --prefix=tinycbor-distcheck/ --format=tar HEAD | tar -xf - -C $${TMPDIR-/tmp}
cd $${TMPDIR-/tmp}/tinycbor-distcheck && $(MAKE) silentcheck
$(RM) -r $${TMPDIR-/tmp}/tinycbor-distcheck
release: .git
$(MAKE) -f $(MAKEFILE) distcheck
ifeq ($(VERSION),)
git -C $(SRCDIR). show HEAD:VERSION | \
perl -l -n -e '@_ = split /\./; print "$$_[0]." . ($$_[1] + 1)' > $(SRCDIR)VERSION
git -C $(SRCDIR). commit -s -m "Update version number" VERSION
else
echo "$(VERSION)" > VERSION
endif
if test -n "`git diff VERSION`"; then \
git -C $(SRCDIR). commit -s -m "Update version number" VERSION; \
fi
{ echo "TinyCBOR release `cat $(SRCDIR)VERSION`"; \
echo; \
echo '# Write something nice about this release here'; \
@@ -182,7 +200,6 @@ release: .git
} > $(SRCDIR).git/TAG_EDITMSG
@`git -C $(SRCDIR). var GIT_EDITOR` $(SRCDIR).git/TAG_EDITMSG
git -C $(SRCDIR). tag -a -F $(SRCDIR).git/TAG_EDITMSG $(GITTAGFLAGS) v`cat $(SRCDIR)VERSION`
$(MAKE) -f $(MAKEFILE) dist
.PHONY: all check silentcheck configure install uninstall
.PHONY: mostlyclean clean distclean
+3 -2
View File
@@ -1,10 +1,11 @@
ALLTESTS = open_memstream funopen gc_sections \
ALLTESTS = open_memstream funopen fopencookie gc_sections \
system-cjson cjson
MAKEFILE := $(lastword $(MAKEFILE_LIST))
OUT :=
PROGRAM-open_memstream = extern int open_memstream(); int main() { return open_memstream(); }
PROGRAM-funopen = extern int funopen(); int main() { return funopen(); }
PROGRAM-fopencookie = extern int fopencookie(); int main() { return fopencookie(); }
PROGRAM-gc_sections = int main() {}
CCFLAGS-gc_sections = -Wl,--gc-sections
@@ -13,7 +14,7 @@ PROGRAM-cjson += \#include <cJSON.h>\n
PROGRAM-cjson += int main() { return cJSON_False; }
CCFLAGS-cjson = -I$(dir $(MAKEFILE))src/cjson
PROGRAM-system-cjson = $(PROGRAM-cjson)
CCLFAGS-system-cjson = -lcJSON
CCFLAGS-system-cjson = -lcJSON
sink:
@echo >&2 Please run from the top-level Makefile.
+1 -1
View File
@@ -1 +1 @@
0.2
0.4
+7 -6
View File
@@ -149,6 +149,7 @@ typedef enum CborError {
/* errors in converting to JSON */
CborErrorJsonObjectKeyIsAggregate,
CborErrorJsonObjectKeyNotString,
CborErrorJsonNotImplemented,
CborErrorOutOfMemory = ~0U / 2 + 1,
CborErrorInternalError = ~0U
@@ -162,7 +163,7 @@ struct CborEncoder
union {
uint8_t *ptr;
ptrdiff_t bytes_needed;
};
} data;
const uint8_t *end;
size_t added;
int flags;
@@ -204,12 +205,12 @@ CBOR_API CborError cbor_encoder_close_container_checked(CborEncoder *encoder, co
CBOR_INLINE_API size_t cbor_encoder_get_buffer_size(const CborEncoder *encoder, const uint8_t *buffer)
{
return (size_t)(encoder->ptr - buffer);
return (size_t)(encoder->data.ptr - buffer);
}
CBOR_INLINE_API size_t cbor_encoder_get_extra_bytes_needed(const CborEncoder *encoder)
{
return encoder->end ? 0 : (size_t)encoder->bytes_needed;
return encoder->end ? 0 : (size_t)encoder->data.bytes_needed;
}
/* Parser API */
@@ -360,7 +361,7 @@ CBOR_INLINE_API CborError cbor_value_get_string_length(const CborValue *value, s
if (!cbor_value_is_length_known(value))
return CborErrorUnknownLength;
uint64_t v = _cbor_value_extract_int64_helper(value);
*length = v;
*length = (size_t)v;
if (*length != v)
return CborErrorDataTooLarge;
return CborNoError;
@@ -415,7 +416,7 @@ CBOR_INLINE_API CborError cbor_value_get_array_length(const CborValue *value, si
if (!cbor_value_is_length_known(value))
return CborErrorUnknownLength;
uint64_t v = _cbor_value_extract_int64_helper(value);
*length = v;
*length = (size_t)v;
if (*length != v)
return CborErrorDataTooLarge;
return CborNoError;
@@ -427,7 +428,7 @@ CBOR_INLINE_API CborError cbor_value_get_map_length(const CborValue *value, size
if (!cbor_value_is_length_known(value))
return CborErrorUnknownLength;
uint64_t v = _cbor_value_extract_int64_helper(value);
*length = v;
*length = (size_t)v;
if (*length != v)
return CborErrorDataTooLarge;
return CborNoError;
+17 -16
View File
@@ -24,6 +24,10 @@
#define _BSD_SOURCE 1
#define _DEFAULT_SOURCE 1
#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS 1
#endif
#include "cbor.h"
#include "cborconstants_p.h"
#include "compilersupport_p.h"
@@ -197,7 +201,7 @@
*/
void cbor_encoder_init(CborEncoder *encoder, uint8_t *buffer, size_t size, int flags)
{
encoder->ptr = buffer;
encoder->data.ptr = buffer;
encoder->end = buffer + size;
encoder->added = 0;
encoder->flags = flags;
@@ -235,7 +239,7 @@ static inline void put64(void *where, uint64_t v)
static inline bool would_overflow(CborEncoder *encoder, size_t len)
{
ptrdiff_t remaining = (ptrdiff_t)encoder->end;
remaining -= remaining ? (ptrdiff_t)encoder->ptr : encoder->bytes_needed;
remaining -= remaining ? (ptrdiff_t)encoder->data.ptr : encoder->data.bytes_needed;
remaining -= (ptrdiff_t)len;
return unlikely(remaining < 0);
}
@@ -243,26 +247,26 @@ static inline bool would_overflow(CborEncoder *encoder, size_t len)
static inline void advance_ptr(CborEncoder *encoder, size_t n)
{
if (encoder->end)
encoder->ptr += n;
encoder->data.ptr += n;
else
encoder->bytes_needed += n;
encoder->data.bytes_needed += n;
}
static inline CborError append_to_buffer(CborEncoder *encoder, const void *data, size_t len)
{
if (would_overflow(encoder, len)) {
if (encoder->end != NULL) {
len -= encoder->end - encoder->ptr;
len -= encoder->end - encoder->data.ptr;
encoder->end = NULL;
encoder->bytes_needed = 0;
encoder->data.bytes_needed = 0;
}
advance_ptr(encoder, len);
return CborErrorOutOfMemory;
}
memcpy(encoder->ptr, data, len);
encoder->ptr += len;
memcpy(encoder->data.ptr, data, len);
encoder->data.ptr += len;
return CborNoError;
}
@@ -286,7 +290,7 @@ static inline CborError encode_number_no_update(CborEncoder *encoder, uint64_t u
if (ui < Value8Bit) {
*bufstart += shiftedMajorType;
} else {
unsigned more = 0;
uint8_t more = 0;
if (ui > 0xffU)
++more;
if (ui > 0xffffU)
@@ -447,7 +451,7 @@ __attribute__((noinline))
static CborError create_container(CborEncoder *encoder, CborEncoder *container, size_t length, uint8_t shiftedMajorType)
{
CborError err;
container->ptr = encoder->ptr;
container->data.ptr = encoder->data.ptr;
container->end = encoder->end;
++encoder->added;
container->added = 0;
@@ -462,10 +466,7 @@ static CborError create_container(CborEncoder *encoder, CborEncoder *container,
} else {
err = encode_number_no_update(container, length, shiftedMajorType);
}
if (err && !isOomError(err))
return err;
return CborNoError;
return err;
}
/**
@@ -527,9 +528,9 @@ CborError cbor_encoder_create_map(CborEncoder *encoder, CborEncoder *mapEncoder,
CborError cbor_encoder_close_container(CborEncoder *encoder, const CborEncoder *containerEncoder)
{
if (encoder->end)
encoder->ptr = containerEncoder->ptr;
encoder->data.ptr = containerEncoder->data.ptr;
else
encoder->bytes_needed = containerEncoder->bytes_needed;
encoder->data.bytes_needed = containerEncoder->data.bytes_needed;
encoder->end = containerEncoder->end;
if (containerEncoder->flags & CborIteratorFlag_UnknownLength)
return append_byte_to_buffer(encoder, BreakByte);
+6 -2
View File
@@ -24,6 +24,10 @@
#define _BSD_SOURCE 1
#define _DEFAULT_SOURCE 1
#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS 1
#endif
#include "cbor.h"
#include "cborconstants_p.h"
#include "compilersupport_p.h"
@@ -55,14 +59,14 @@
*/
CborError cbor_encoder_close_container_checked(CborEncoder *encoder, const CborEncoder *containerEncoder)
{
const uint8_t *ptr = encoder->ptr;
const uint8_t *ptr = encoder->data.ptr;
CborError err = cbor_encoder_close_container(encoder, containerEncoder);
if (containerEncoder->flags & CborIteratorFlag_UnknownLength || encoder->end == NULL)
return err;
/* check what the original length was */
uint64_t actually_added;
err = extract_number(&ptr, encoder->ptr, &actually_added);
err = extract_number(&ptr, encoder->data.ptr, &actually_added);
if (err)
return err;
+2
View File
@@ -155,6 +155,8 @@ const char *cbor_error_string(CborError error)
case CborErrorJsonObjectKeyNotString:
return _("conversion to JSON failed: key in object is not a string");
case CborErrorJsonNotImplemented:
return _("conversion to JSON failed: open_memstream unavailable");
case CborErrorInternalError:
return _("internal error");
+7 -3
View File
@@ -24,6 +24,10 @@
#define _BSD_SOURCE 1
#define _DEFAULT_SOURCE 1
#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS 1
#endif
#include "cbor.h"
#include "cborconstants_p.h"
#include "compilersupport_p.h"
@@ -151,7 +155,7 @@ static CborError extract_length(const CborParser *parser, const uint8_t **ptr, s
return err;
}
*len = v;
*len = (size_t)v;
if (v != *len)
return CborErrorDataTooLarge;
return CborNoError;
@@ -795,13 +799,13 @@ CborError cbor_value_get_int_checked(const CborValue *value, int *result)
if (unlikely(v > (unsigned) -(INT_MIN + 1)))
return CborErrorDataTooLarge;
*result = v;
*result = (int)v;
*result = -*result - 1;
} else {
if (unlikely(v > (uint64_t)INT_MAX))
return CborErrorDataTooLarge;
*result = v;
*result = (int)v;
}
return CborNoError;
+4
View File
@@ -24,6 +24,10 @@
#define _BSD_SOURCE 1
#define _DEFAULT_SOURCE 1
#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS 1
#endif
#include "cbor.h"
#include <stdlib.h>
+5
View File
@@ -24,6 +24,10 @@
#define _BSD_SOURCE 1
#define _DEFAULT_SOURCE 1
#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS 1
#endif
#include "cbor.h"
#include "compilersupport_p.h"
#include "math_support_p.h"
@@ -186,6 +190,7 @@ static int utf8EscapedDump(FILE *out, const char *buffer, size_t n)
if (n < charsNeeded - 1)
return CborErrorInvalidUtf8TextString;
n -= charsNeeded - 1;
/* first continuation character */
uint8_t b = (uint8_t)*buffer++;
+10
View File
@@ -26,6 +26,10 @@
#define _DEFAULT_SOURCE 1
#define _GNU_SOURCE 1
#define _POSIX_C_SOURCE 200809L
#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS 1
#endif
#include "cbor.h"
#include "cborjson.h"
#include "compilersupport_p.h"
@@ -398,6 +402,11 @@ static CborError stringify_map_key(char **key, CborValue *it, int flags, CborTyp
{
(void)flags; /* unused */
(void)type; /* unused */
#ifdef WITHOUT_OPEN_MEMSTREAM
(void)key; /* unused */
(void)it; /* unused */
return CborErrorJsonNotImplemented;
#else
size_t size;
FILE *memstream = open_memstream(key, &size);
@@ -408,6 +417,7 @@ static CborError stringify_map_key(char **key, CborValue *it, int flags, CborTyp
if (unlikely(fclose(memstream) < 0 || *key == NULL))
return CborErrorInternalError;
return err;
#endif
}
static CborError array_to_json(FILE *out, CborValue *it, int flags, ConversionStatus *status)
+13 -4
View File
@@ -61,13 +61,16 @@
# define inline CBOR_INLINE
#endif
#ifndef STRINGIFY
#define STRINGIFY(x) STRINGIFY2(x)
#endif
#define STRINGIFY2(x) #x
#ifndef UINT32_MAX
/* C99 requires it in stdint.h, but some systems lack it */
# define UINT32_MAX (0xffffffffU)
#if !defined(UINT32_MAX) || !defined(INT64_MAX)
/* C89? We can define UINT32_MAX portably, but not INT64_MAX */
# error "Your system has stdint.h but that doesn't define UINT32_MAX or INT64_MAX"
#endif
#ifndef DBL_DECIMAL_DIG
/* DBL_DECIMAL_DIG is C11 */
# define DBL_DECIMAL_DIG 17
@@ -150,8 +153,12 @@
#endif
#ifdef __GNUC__
#ifndef likely
# define likely(x) __builtin_expect(!!(x), 1)
#endif
#ifndef unlikely
# define unlikely(x) __builtin_expect(!!(x), 0)
#endif
# define unreachable() __builtin_unreachable()
#elif defined(_MSC_VER)
# define likely(x) (x)
@@ -209,7 +216,9 @@ static inline unsigned short encode_half(double val)
/* underflow, make zero */
return 0;
}
return sign | ((exp + 15) << 10) | mant;
/* safe cast here as bit operations above guarantee not to overflow */
return (unsigned short)(sign | ((exp + 15) << 10) | mant);
#endif
}
+11
View File
@@ -1,4 +1,15 @@
Makefile
debug
moc_predefs.h
release
target_wrapper.*
# The executables
cpp/cpp
cpp/cpp.exe
encoder/encoder
encoder/encoder.exe
parser/parser
parser/parser.exe
tojson/tojson
tojson/tojson.exe
+1 -1
View File
@@ -599,7 +599,7 @@ void tst_Encoder::shortBuffer()
QFETCH(QByteArray, output);
QByteArray buffer(output.length(), Qt::Uninitialized);
for (int len = 0; len < output.length() - 1; ++len) {
for (int len = 0; len < output.length(); ++len) {
CborEncoder encoder;
cbor_encoder_init(&encoder, reinterpret_cast<quint8 *>(buffer.data()), len, 0);
QCOMPARE(int(encodeVariant(&encoder, input)), int(CborErrorOutOfMemory));
+7
View File
@@ -333,6 +333,13 @@ void addStringsData()
QTest::newRow("textstring256") << raw("\x79\1\0") + QByteArray(256, '3')
<< '"' + QString(256, '3') + '"';
// some strings with UTF-8 content
// we had a bug in the pretty dumper - see issue #54
QTest::newRow("textstringutf8-2char") << raw("\x62\xc2\xa0") << "\"\\u00A0\"";
QTest::newRow("textstringutf8-2char2") << raw("\x64\xc2\xa0\xc2\xa9") << "\"\\u00A0\\u00A9\"";
QTest::newRow("textstringutf8-3char") << raw("\x63\xe2\x88\x80") << "\"\\u2200\"";
QTest::newRow("textstringutf8-4char") << raw("\x64\xf0\x90\x88\x83") << "\"\\uD800\\uDE03\"";
// strings with overlong length
QTest::newRow("emptybytestring*1") << raw("\x58\x00") << "h''";
QTest::newRow("emptytextstring*1") << raw("\x78\x00") << "\"\"";
+2 -2
View File
@@ -332,7 +332,7 @@ encode_double:
return err;
*encoder = container; // restore state
encoder->ptr = newbuffer + (container.ptr - buffer);
encoder->data.ptr = newbuffer + (container.data.ptr - buffer);
encoder->end = newbuffer + buffersize;
buffer = newbuffer;
goto encode_double;
@@ -483,7 +483,7 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
fwrite(buffer, 1, encoder.ptr - buffer, stdout);
fwrite(buffer, 1, encoder.data.ptr - buffer, stdout);
free(buffer);
return EXIT_SUCCESS;
}