more integer conversion tests and fixes
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index f5995fe..03e8b28 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -2820,10 +2820,10 @@
const uint8_t *pByte = BigNum.ptr;
size_t uLen = BigNum.len;
while(uLen--) {
- if(uResult > uMax >> 8) {
+ if(uResult > (uMax >> 8)) {
return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
}
- uResult = (uResult << 8) + *pByte;
+ uResult = (uResult << 8) + *pByte++;
}
*pResult = uResult;
@@ -2843,7 +2843,7 @@
is too large to fit. No error will be logged.
TODO: should an error be logged? */
while(uLen--) {
- dResult = (dResult * 256.0) + (double)*pByte;
+ dResult = (dResult * 256.0) + (double)*pByte++;
}
return dResult;
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index d0589cb..d96c8a8 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -4002,6 +4002,38 @@
static const struct NumberConversion NumberConversions[] = {
{
+ "Positive bignum 0x01020304 indefinite length string",
+ {(uint8_t[]){0xC2, 0x5f, 0x42, 0x01, 0x02, 0x41, 0x03, 0x41, 0x04, 0xff}, 10},
+ 0x01020304,
+ QCBOR_SUCCESS,
+ 0x01020304,
+ QCBOR_SUCCESS,
+ 16909060.0,
+ QCBOR_SUCCESS
+ },
+ {
+ "Decimal Fraction [9223372036854775807, -4759477275222530853137]",
+ {(uint8_t[]){0xC4, 0x82, 0x1B, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+ 0xC3, 0x4A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10,}, 23},
+ 0,
+ QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW,
+ 0,
+ QCBOR_ERR_NUMBER_SIGN_CONVERSION,
+ -INFINITY,
+ QCBOR_SUCCESS
+ },
+ {
+ "big float [9223372036854775806, 9223372036854775806]",
+ {(uint8_t[]){0xC5, 0x82, 0x1B, 0x7f, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
+ 0x1B, 0x7f, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE}, 20},
+ 0,
+ QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW,
+ 0,
+ QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW,
+ INFINITY,
+ QCBOR_SUCCESS
+ },
+ {
"Big float 3 * 2^^2",
{(uint8_t[]){0xC5, 0x82, 0x02, 0x03}, 4},
12,
@@ -4011,9 +4043,8 @@
12.0,
QCBOR_SUCCESS
},
- // | 18446744073709551615 | 0x1bffffffffffffffff
{
- "18446744073709551615",
+ "Positive integer 18446744073709551615",
{(uint8_t[]){0x1b, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 9},
0,
QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW,
@@ -4034,7 +4065,7 @@
QCBOR_SUCCESS
}, */
{
- "positive bignum 0xffff",
+ "Positive bignum 0xffff",
{(uint8_t[]){0xC2, 0x42, 0xff, 0xff}, 4},
65536-1,
QCBOR_SUCCESS,
@@ -4054,7 +4085,7 @@
QCBOR_SUCCESS
},
{
- "-18446744073709551616",
+ "Negative integer -18446744073709551616",
{(uint8_t[]){0x3b, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, 9},
-9223372036854775807-1, // INT64_MIN
QCBOR_SUCCESS,
@@ -4064,7 +4095,7 @@
QCBOR_SUCCESS
},
{
- "Floating point value 100.3",
+ "Double Floating point value 100.3",
{(uint8_t[]){0xfb, 0x40, 0x59, 0x13, 0x33, 0x33, 0x33, 0x33, 0x33}, 9},
100L,
QCBOR_SUCCESS,
@@ -4084,7 +4115,7 @@
QCBOR_SUCCESS
},
{
- "Floating point value -4",
+ "half-precision Floating point value -4",
{(uint8_t[]){0xf9, 0xc4, 0x00}, 3},
-4,
QCBOR_SUCCESS,
@@ -4107,7 +4138,7 @@
-int32_t IntegerConvertTest2()
+int32_t IntegerConvertTest()
{
const size_t nNumTests = sizeof(NumberConversions)/sizeof(struct NumberConversion);
@@ -4180,13 +4211,8 @@
return 0;
}
-int32_t IntegerConvertTest()
+int32_t IntegerConvertTestOld()
{
- int32_t nReturn = IntegerConvertTest2();
- if(nReturn) {
- return nReturn;
- }
-
QCBORDecodeContext DCtx;
QCBORError nCBORError;