more number conversion working
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index 03e8b28..203e000 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -2684,7 +2684,7 @@
* UINT64_MAX < 10 ^^ 19. More than that will cause
* exit with the overflow error
*/
- while(nExponent > 0) {
+ while(nExponent > 1) {
if(uResult > UINT64_MAX / 10) {
return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW; // Error overflow
}
@@ -2851,7 +2851,7 @@
-static inline QCBORError ConvertPositiveBigNumToUnSigned(const UsefulBufC BigNum, uint64_t *pResult)
+static inline QCBORError ConvertPositiveBigNumToUnsigned(const UsefulBufC BigNum, uint64_t *pResult)
{
return ConvertBigNumToUnsigned(BigNum, UINT64_MAX, pResult);
}
@@ -2877,6 +2877,7 @@
return uError;
}
/* Cast is safe because ConvertBigNum is told to limit to INT64_MAX */
+ // TODO: this code is incorrect. See RFC 7049
*pResult = -(int64_t)uResult;
return QCBOR_SUCCESS;
}
@@ -3016,10 +3017,15 @@
int64_t nMantissa;
pMe->uLastError = (uint8_t)ConvertPositiveBigNumToSigned(Item.val.expAndMantissa.Mantissa.bigNum, &nMantissa);
if(!pMe->uLastError) {
- pMe->uLastError = (uint8_t)ExponentiateNN(nMantissa,
- Item.val.expAndMantissa.nExponent,
- pValue,
- &Exponentitate10UU);
+ int64_t nMultiplier;
+ pMe->uLastError = (uint8_t)ExponentiateNN(10,
+ Item.val.expAndMantissa.nExponent,
+ &nMultiplier,
+ &Exponentitate10UU);
+ if(!pMe->uLastError) {
+ // TODO: overflow
+ *pValue = nMantissa * nMultiplier;
+ }
}
} else {
pMe->uLastError = QCBOR_ERR_CONVERSION_NOT_REQUESTED;
@@ -3172,7 +3178,7 @@
case QCBOR_TYPE_POSBIGNUM:
if(uOptions & QCBOR_CONVERT_TYPE_BIG_NUM) {
- pMe->uLastError = (uint8_t)ConvertPositiveBigNumToUnSigned(Item.val.bigNum, pValue);
+ pMe->uLastError = (uint8_t)ConvertPositiveBigNumToUnsigned(Item.val.bigNum, pValue);
} else {
pMe->uLastError = QCBOR_ERR_CONVERSION_NOT_REQUESTED;
}
@@ -3214,13 +3220,17 @@
case QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM:
if(uOptions & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
- int64_t nMantissa;
- pMe->uLastError = (uint8_t)ConvertPositiveBigNumToSigned(Item.val.expAndMantissa.Mantissa.bigNum, &nMantissa);
+ uint64_t uMantissa;
+ pMe->uLastError = (uint8_t)ConvertPositiveBigNumToUnsigned(Item.val.expAndMantissa.Mantissa.bigNum, &uMantissa);
if(!pMe->uLastError) {
- pMe->uLastError = (uint8_t)ExponentitateNU(nMantissa,
+ uint64_t uMultiplier;
+ pMe->uLastError = (uint8_t)ExponentitateNU(10,
Item.val.expAndMantissa.nExponent,
- pValue,
+ &uMultiplier,
Exponentitate10UU);
+ if(!pMe->uLastError) {
+ *pValue = uMantissa * uMultiplier;
+ }
}
} else {
pMe->uLastError = QCBOR_ERR_CONVERSION_NOT_REQUESTED;