Skip to content

Commit 8fc4528

Browse files
Merge branch 'master' into dev
Signed-off-by: Thiago Macieira <[email protected]>
2 parents 0171135 + 0a78b71 commit 8fc4528

File tree

7 files changed

+24
-11
lines changed

7 files changed

+24
-11
lines changed

Makefile.configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ PROGRAM-cjson += \#include <cJSON.h>\n
1414
PROGRAM-cjson += int main() { return cJSON_False; }
1515
CCFLAGS-cjson = -I$(dir $(MAKEFILE))src/cjson
1616
PROGRAM-system-cjson = $(PROGRAM-cjson)
17-
CCLFAGS-system-cjson = -lcJSON
17+
CCFLAGS-system-cjson = -lcJSON
1818

1919
sink:
2020
@echo >&2 Please run from the top-level Makefile.

src/cborencoder.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ static inline CborError encode_number_no_update(CborEncoder *encoder, uint64_t u
290290
if (ui < Value8Bit) {
291291
*bufstart += shiftedMajorType;
292292
} else {
293-
unsigned more = 0;
293+
uint8_t more = 0;
294294
if (ui > 0xffU)
295295
++more;
296296
if (ui > 0xffffU)
@@ -466,10 +466,7 @@ static CborError create_container(CborEncoder *encoder, CborEncoder *container,
466466
} else {
467467
err = encode_number_no_update(container, length, shiftedMajorType);
468468
}
469-
if (err && !isOomError(err))
470-
return err;
471-
472-
return CborNoError;
469+
return err;
473470
}
474471

475472
/**

src/cborparser.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static CborError extract_length(const CborParser *parser, const uint8_t **ptr, s
155155
return err;
156156
}
157157

158-
*len = v;
158+
*len = (size_t)v;
159159
if (v != *len)
160160
return CborErrorDataTooLarge;
161161
return CborNoError;
@@ -799,13 +799,13 @@ CborError cbor_value_get_int_checked(const CborValue *value, int *result)
799799
if (unlikely(v > (unsigned) -(INT_MIN + 1)))
800800
return CborErrorDataTooLarge;
801801

802-
*result = v;
802+
*result = (int)v;
803803
*result = -*result - 1;
804804
} else {
805805
if (unlikely(v > (uint64_t)INT_MAX))
806806
return CborErrorDataTooLarge;
807807

808-
*result = v;
808+
*result = (int)v;
809809
}
810810
return CborNoError;
811811

src/cborpretty.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ static int utf8EscapedDump(FILE *out, const char *buffer, size_t n)
190190

191191
if (n < charsNeeded - 1)
192192
return CborErrorInvalidUtf8TextString;
193+
n -= charsNeeded - 1;
193194

194195
/* first continuation character */
195196
uint8_t b = (uint8_t)*buffer++;

src/compilersupport_p.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@
6161
# define inline CBOR_INLINE
6262
#endif
6363

64+
#ifndef STRINGIFY
6465
#define STRINGIFY(x) STRINGIFY2(x)
66+
#endif
6567
#define STRINGIFY2(x) #x
6668

6769
#if !defined(UINT32_MAX) || !defined(INT64_MAX)
@@ -151,8 +153,12 @@
151153
#endif
152154

153155
#ifdef __GNUC__
156+
#ifndef likely
154157
# define likely(x) __builtin_expect(!!(x), 1)
158+
#endif
159+
#ifndef unlikely
155160
# define unlikely(x) __builtin_expect(!!(x), 0)
161+
#endif
156162
# define unreachable() __builtin_unreachable()
157163
#elif defined(_MSC_VER)
158164
# define likely(x) (x)
@@ -210,7 +216,9 @@ static inline unsigned short encode_half(double val)
210216
/* underflow, make zero */
211217
return 0;
212218
}
213-
return sign | ((exp + 15) << 10) | mant;
219+
220+
/* safe cast here as bit operations above guarantee not to overflow */
221+
return (unsigned short)(sign | ((exp + 15) << 10) | mant);
214222
#endif
215223
}
216224

tests/encoder/tst_encoder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ void tst_Encoder::shortBuffer()
599599
QFETCH(QByteArray, output);
600600
QByteArray buffer(output.length(), Qt::Uninitialized);
601601

602-
for (int len = 0; len < output.length() - 1; ++len) {
602+
for (int len = 0; len < output.length(); ++len) {
603603
CborEncoder encoder;
604604
cbor_encoder_init(&encoder, reinterpret_cast<quint8 *>(buffer.data()), len, 0);
605605
QCOMPARE(int(encodeVariant(&encoder, input)), int(CborErrorOutOfMemory));

tests/parser/tst_parser.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,13 @@ void addStringsData()
333333
QTest::newRow("textstring256") << raw("\x79\1\0") + QByteArray(256, '3')
334334
<< '"' + QString(256, '3') + '"';
335335

336+
// some strings with UTF-8 content
337+
// we had a bug in the pretty dumper - see issue #54
338+
QTest::newRow("textstringutf8-2char") << raw("\x62\xc2\xa0") << "\"\\u00A0\"";
339+
QTest::newRow("textstringutf8-2char2") << raw("\x64\xc2\xa0\xc2\xa9") << "\"\\u00A0\\u00A9\"";
340+
QTest::newRow("textstringutf8-3char") << raw("\x63\xe2\x88\x80") << "\"\\u2200\"";
341+
QTest::newRow("textstringutf8-4char") << raw("\x64\xf0\x90\x88\x83") << "\"\\uD800\\uDE03\"";
342+
336343
// strings with overlong length
337344
QTest::newRow("emptybytestring*1") << raw("\x58\x00") << "h''";
338345
QTest::newRow("emptytextstring*1") << raw("\x78\x00") << "\"\"";

0 commit comments

Comments
 (0)