Turn up compiler warnings to max and fix them; one more indefinite length test
diff --git a/Makefile b/Makefile
index c739908..6e7745f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-CFLAGS=-I inc -I test -Os
+CFLAGS=-I inc -I test -Os -Wall -Werror -pedantic-errors -Wextra -Wshadow
QCBOR_OBJ=src/UsefulBuf.o src/qcbor_encode.o src/qcbor_decode.o src/ieee754.o
diff --git a/cmd_line_main.c b/cmd_line_main.c
index 63c670c..fbf9e22 100644
--- a/cmd_line_main.c
+++ b/cmd_line_main.c
@@ -38,7 +38,10 @@
}
-int main(int argc, const char * argv[]) {
+int main(int argc, const char * argv[])
+{
+ (void)argc; // Suppress unused warning
+ (void)argv; // Supress unused warning
int nNumTestsFailed = run_tests(&fputs_wrapper, stdout, NULL);
diff --git a/inc/UsefulBuf.h b/inc/UsefulBuf.h
index 7bc3023..c2b2e09 100644
--- a/inc/UsefulBuf.h
+++ b/inc/UsefulBuf.h
@@ -467,7 +467,7 @@
if(uAmount > UB.len) {
return NULLUsefulBufC;
}
- return (UsefulBufC){UB.ptr + uAmount, UB.len - uAmount};
+ return (UsefulBufC){(uint8_t *)UB.ptr + uAmount, UB.len - uAmount};
}
diff --git a/src/UsefulBuf.c b/src/UsefulBuf.c
index c8e5d28..dcd7d34 100644
--- a/src/UsefulBuf.c
+++ b/src/UsefulBuf.c
@@ -105,7 +105,7 @@
return NULLUsefulBufC;
}
- memcpy(Dest.ptr + uOffset, Src.ptr, Src.len);
+ memcpy((uint8_t *)Dest.ptr + uOffset, Src.ptr, Src.len);
return((UsefulBufC){Dest.ptr, Src.len + uOffset});
}
diff --git a/src/ieee754.c b/src/ieee754.c
index 7844c1a..b4497cc 100644
--- a/src/ieee754.c
+++ b/src/ieee754.c
@@ -42,11 +42,12 @@
job and the resulting object code is smaller from combining code for the many different
cases (normal, subnormal, infinity, zero...) for the conversions.
- Dead stripping is also really helpful to get code size down.
+ Dead stripping is also really helpful to get code size down when floating point
+ encoding is not needed.
- This code also works solely using shifts and masks and thus has no dependency on
- any math libraries. It will even work if the CPU doesn't have any floating
- point support.
+ This code works solely using shifts and masks and thus has no dependency on
+ any math libraries. It can even work if the CPU doesn't have any floating
+ point support, though that isn't the most useful thing to do.
The memcpy() dependency is only for CopyFloatToUint32() and friends which only
is needed to avoid type punning when converting the actual float bits to
@@ -169,13 +170,6 @@
return u64;
}
-static inline double CopyUint64ToDouble(uint64_t u64)
-{
- double d;
- memcpy(&d, &u64, sizeof(uint64_t));
- return d;
-}
-
static inline float CopyUint32ToFloat(uint32_t u32)
{
float f;
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index 187419b..0f76963 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -437,21 +437,6 @@
/*
Decode text and byte strings
*/
-inline static int DecodeBytesOld(int nMajorType, uint64_t uNumber, UsefulInputBuf *pUInBuf, QCBORItem *pDecodedItem)
-{
- const void *pBytes = UsefulInputBuf_GetBytes(pUInBuf, uNumber);
-
- int nReturn = QCBOR_ERR_HIT_END;
-
- if(pBytes != NULL) {
- pDecodedItem->val.string = (UsefulBufC){pBytes, uNumber};
- pDecodedItem->uDataType = (nMajorType == CBOR_MAJOR_TYPE_BYTE_STRING) ? QCBOR_TYPE_BYTE_STRING : QCBOR_TYPE_TEXT_STRING;
- nReturn = QCBOR_SUCCESS;
- }
-
- return nReturn;
-}
-
inline static int DecodeBytes(QCBORStringAllocator *pAlloc, int nMajorType, uint64_t uNumber, UsefulInputBuf *pUInBuf, QCBORItem *pDecodedItem)
{
UsefulBufC Bytes = UsefulInputBuf_GetUsefulBuf(pUInBuf, uNumber);
@@ -1123,9 +1108,9 @@
pMP->StringAllocator.fFree = MemPool_Free;
pMP->StringAllocator.fDestructor = NULL;
- pMP->pStart = Pool.ptr + sizeof(MemPool);
+ pMP->pStart = (uint8_t *)Pool.ptr + sizeof(MemPool);
pMP->pFree = pMP->pStart;
- pMP->pEnd = Pool.ptr + Pool.len;
+ pMP->pEnd = (uint8_t *)Pool.ptr + Pool.len;
pMP->StringAllocator.pAllocaterContext = pMP;
me->pStringAllocator = pMP;
diff --git a/test/float_tests.c b/test/float_tests.c
index 1bff43c..1d755d5 100644
--- a/test/float_tests.c
+++ b/test/float_tests.c
@@ -567,7 +567,7 @@
}
return 0;
-};
+}
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 25ab721..9bdfe79 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -69,7 +69,7 @@
printf("%s ", szLabel);
}
- int i;
+ size_t i;
for(i = 0; i < nLen; i++) {
uint8_t Z = pEncoded[i];
printf("%02x ", Z);
@@ -132,31 +132,31 @@
if((nCBORError = QCBORDecode_GetNext(pDCtx, &Item)))
return nCBORError;
if(Item.uDataType != QCBOR_TYPE_INT64 || // Todo; fix this for 32-bit machines
- Item.val.uint64 != -9223372036854775807LL - 1)
+ Item.val.int64 != -9223372036854775807LL - 1)
return -1;
if((nCBORError = QCBORDecode_GetNext(pDCtx, &Item)))
return nCBORError;
if(Item.uDataType != QCBOR_TYPE_INT64 ||
- Item.val.uint64 != -4294967297)
+ Item.val.int64 != -4294967297)
return -1;
if((nCBORError = QCBORDecode_GetNext(pDCtx, &Item)))
return nCBORError;
if(Item.uDataType != QCBOR_TYPE_INT64 ||
- Item.val.uint64 != -4294967296)
+ Item.val.int64 != -4294967296)
return -1;
if((nCBORError = QCBORDecode_GetNext(pDCtx, &Item)))
return nCBORError;
if(Item.uDataType != QCBOR_TYPE_INT64 ||
- Item.val.uint64 != -4294967295)
+ Item.val.int64 != -4294967295)
return -1;
if((nCBORError = QCBORDecode_GetNext(pDCtx, &Item)))
return nCBORError;
if(Item.uDataType != QCBOR_TYPE_INT64 ||
- Item.val.uint64 != -4294967294)
+ Item.val.int64 != -4294967294)
return -1;
@@ -1501,7 +1501,7 @@
if(Item.uLabelType == QCBOR_TYPE_INT64) {
if(Item.label.int64 != nLabel) return -1;
} else {
- if(Item.label.uint64 != nLabel) return -1;
+ if(Item.label.uint64 != (uint64_t)nLabel) return -1;
}
}
if(Item.uNestingLevel != uNestingLevel) return -1;
@@ -1650,6 +1650,7 @@
static const uint8_t pIndefiniteArrayBad1[] = {0x9f}; // No closing break
static const uint8_t pIndefiniteArrayBad2[] = {0x9f, 0x9f, 0x02, 0xff}; // Not enough closing breaks
static const uint8_t pIndefiniteArrayBad3[] = {0x9f, 0x02, 0xff, 0xff}; // Too many closing breaks
+static const uint8_t pIndefiniteArrayBad4[] = {0x81, 0x9f}; // Unclosed indeflen inside def len
int indefinite_length_decode_test()
@@ -1708,7 +1709,7 @@
return -1;
}
- nResult = QCBORDecode_Finish(&DC); // TODO: find bug related to this
+ nResult = QCBORDecode_Finish(&DC);
if(nResult != QCBOR_ERR_HIT_END) {
return -2;
}
@@ -1764,6 +1765,29 @@
return -2;
}
+
+ // --- next test -----
+ IndefLen = UsefulBuf_FromByteArrayLiteral(pIndefiniteArrayBad4);
+
+ QCBORDecode_Init(&DC, IndefLen, QCBOR_DECODE_MODE_NORMAL);
+
+ QCBORDecode_SetMemPool(&DC, MemPool, false);
+
+ nResult = QCBORDecode_GetNext(&DC, &Item);
+ if(nResult || Item.uDataType != QCBOR_TYPE_ARRAY) {
+ return -1;
+ }
+
+ nResult = QCBORDecode_GetNext(&DC, &Item);
+ if(nResult || Item.uDataType != QCBOR_TYPE_ARRAY) {
+ return -1;
+ }
+
+ nResult = QCBORDecode_Finish(&DC);
+ if(nResult != QCBOR_ERR_HIT_END) {
+ return -2;
+ }
+
return 0;
}
diff --git a/test/run_tests.c b/test/run_tests.c
index 41f2d8d..1aee18b 100644
--- a/test/run_tests.c
+++ b/test/run_tests.c
@@ -53,7 +53,7 @@
*/
const char *NumToString(int32_t nNum, UsefulBuf StringMem)
{
- const uint32_t uMax = 1000000000;
+ const int32_t nMax = 1000000000;
UsefulOutBuf OutBuf;
UsefulOutBuf_Init(&OutBuf, StringMem);
@@ -62,12 +62,12 @@
UsefulOutBuf_AppendByte(&OutBuf, '-');
nNum = -nNum;
}
- if(nNum > uMax-1) {
+ if(nNum > nMax-1) {
return "XXX";
}
bool bDidSomeOutput = false;
- for(int n = uMax; n > 0; n/=10) {
+ for(int n = nMax; n > 0; n/=10) {
int x = nNum/n;
if(x || bDidSomeOutput){
bDidSomeOutput = true;