refactor: add missing headers, remove compiler warnings (#86)
* refactor: add missing headers
* refactor: reduce warnings
* chore: remove more unsed stuff
* refactor: remove some sign compare warnings
* fix: less warnings
* fix: more warnings
* refactor: remove UNUSED_PARAM
* fix: typos
* revert: removing f var from test.c
* revert: remove debug info from testing files
* revert: changing build script
* fix: tests
diff --git a/test/context.c b/test/context.c
index dbdea88..8fc925e 100644
--- a/test/context.c
+++ b/test/context.c
@@ -29,22 +29,19 @@
bool CheckMemory(MyContext * pContext)
{
MyItem * p;
- int i;
-
// Walk memory and check every block
for (p = (MyItem *) pContext->pFirst; p != NULL; p = p->pNext) {
if (p->pad[0] == (byte) 0xab) {
// Block has been freed
- for (i = 0; i < p->size + 8; i++) {
+ for (unsigned i = 0; i < p->size + 8; i++) {
if (p->pad[i] != (byte) 0xab) {
fprintf(stderr, "Freed block is modified");
assert(false);
}
}
- }
- else if (p->pad[0] == (byte) 0xef) {
- for (i = 0; i < 4; i++) {
+ } else if (p->pad[0] == (byte) 0xef) {
+ for (unsigned i = 0; i < 4; i++) {
if ((p->pad[i] != (byte) 0xef) || (p->pad[i + 4 + p->size] != (byte) 0xef)) {
fprintf(stderr, "Curent block was overrun");
assert(false);
diff --git a/test/encrypt.c b/test/encrypt.c
index 14eff3e..5a569cc 100644
--- a/test/encrypt.c
+++ b/test/encrypt.c
@@ -421,12 +421,13 @@
if (!fAlgSupport) {
fFail = true;
fAlgSupport = false;
+ } else if ((pFail != NULL) && (pFail->type != CN_CBOR_TRUE)) {
+ fFail = true;
}
- else if ((pFail != NULL) && (pFail->type != CN_CBOR_TRUE)) fFail = true;
- size_t cb;
- byte * pb;
- pb = COSE_Encrypt_GetContent(hEnc, &cb, NULL);
+ size_t cb;
+ byte * pb;
+ pb = COSE_Encrypt_GetContent(hEnc, &cb, NULL);
}
else {
if (fAlgSupport) {
diff --git a/test/json.c b/test/json.c
index 9a99ecd..d3bd7bc 100644
--- a/test/json.c
+++ b/test/json.c
@@ -217,10 +217,10 @@
for (unsigned int i = 0, j = 0; i < input_length;) {
- uint32_t sextet_a = data[i] == '=' ? 0 & i++ : decoding_table[(int) data[i++]];
- uint32_t sextet_b = data[i] == '=' ? 0 & i++ : decoding_table[(int) data[i++]];
- uint32_t sextet_c = data[i] == '=' ? 0 & i++ : decoding_table[(int) data[i++]];
- uint32_t sextet_d = data[i] == '=' ? 0 & i++ : decoding_table[(int) data[i++]];
+ uint32_t sextet_a = data[i] == '=' ? 0 & i++ : (unsigned)decoding_table[(int) data[i++]];
+ uint32_t sextet_b = data[i] == '=' ? 0 & i++ : (unsigned)decoding_table[(int) data[i++]];
+ uint32_t sextet_c = data[i] == '=' ? 0 & i++ : (unsigned)decoding_table[(int) data[i++]];
+ uint32_t sextet_d = data[i] == '=' ? 0 & i++ : (unsigned)decoding_table[(int) data[i++]];
uint32_t triple = (sextet_a << 3 * 6)
+ (sextet_b << 2 * 6)
diff --git a/test/test.c b/test/test.c
index bc110f1..c6a5911 100644
--- a/test/test.c
+++ b/test/test.c
@@ -10,6 +10,7 @@
#include <cose/cose_configure.h>
#include <cn-cbor/cn-cbor.h>
#include <assert.h>
+#include <cose_int.h>
#ifndef _MSC_VER
#include <dirent.h>
@@ -18,7 +19,6 @@
#endif
#include "json.h"
-
#include "test.h"
#ifdef USE_MBED_TLS
@@ -330,19 +330,23 @@
bool SetAttributes(HCOSE hHandle, const cn_cbor * pAttributes, int which, int msgType, bool fPublicKey)
{
- const cn_cbor * pKey;
- const cn_cbor * pValue;
- int keyNew;
- cn_cbor * pValueNew;
- bool f = false;
+ int keyNew = 0;
+ cn_cbor * pValueNew = NULL;
+ bool fRet = true;
- if (pAttributes == NULL) return true;
- if (pAttributes->type != CN_CBOR_MAP) return false;
+ if (pAttributes == NULL) {
+ return true;
+ }
+ if (pAttributes->type != CN_CBOR_MAP) {
+ return false;
+ }
- for (pKey = pAttributes->first_child; pKey != NULL; pKey = pKey->next->next) {
- pValue = pKey->next;
+ for (const cn_cbor * pKey = pAttributes->first_child; pKey != NULL; pKey = pKey->next->next) {
+ const cn_cbor * pValue = pKey->next;
- if (pKey->type != CN_CBOR_TEXT) return false;
+ if (pKey->type != CN_CBOR_TEXT) {
+ return false;
+ }
if (strcmp(pKey->v.str, "alg") == 0) {
keyNew = COSE_Header_Algorithm;
@@ -391,57 +395,56 @@
switch (msgType) {
#if INCLUDE_MAC
case Attributes_MAC_protected:
- f = COSE_Mac_map_put_int((HCOSE_MAC)hHandle, keyNew, pValueNew, which, NULL);
+ fRet &= COSE_Mac_map_put_int((HCOSE_MAC)hHandle, keyNew, pValueNew, which, NULL);
break;
#endif
#if INCLUDE_MAC0
case Attributes_MAC0_protected:
- f = COSE_Mac0_map_put_int((HCOSE_MAC0)hHandle, keyNew, pValueNew, which, NULL);
+ fRet &= COSE_Mac0_map_put_int((HCOSE_MAC0)hHandle, keyNew, pValueNew, which, NULL);
break;
#endif
#if INCLUDE_ENCRYPT || INCLUDE_MAC
case Attributes_Recipient_protected:
- f = COSE_Recipient_map_put_int((HCOSE_RECIPIENT)hHandle, keyNew, pValueNew, which, NULL);
+ fRet &= COSE_Recipient_map_put_int((HCOSE_RECIPIENT)hHandle, keyNew, pValueNew, which, NULL);
break;
#endif
#if INCLUDE_ENCRYPT
case Attributes_Enveloped_protected:
- f = COSE_Enveloped_map_put_int((HCOSE_ENVELOPED)hHandle, keyNew, pValueNew, which, NULL);
+ fRet &= COSE_Enveloped_map_put_int((HCOSE_ENVELOPED)hHandle, keyNew, pValueNew, which, NULL);
break;
#endif
#if INCLUDE_ENCRYPT0
case Attributes_Encrypt_protected:
- f = COSE_Encrypt_map_put_int((HCOSE_ENCRYPT)hHandle, keyNew, pValueNew, which, NULL);
+ fRet &= COSE_Encrypt_map_put_int((HCOSE_ENCRYPT)hHandle, keyNew, pValueNew, which, NULL);
break;
#endif
#if INCLUDE_SIGN
case Attributes_Sign_protected:
- f = COSE_Sign_map_put_int((HCOSE_SIGN)hHandle, keyNew, pValueNew, which, NULL);
+ fRet &= COSE_Sign_map_put_int((HCOSE_SIGN)hHandle, keyNew, pValueNew, which, NULL);
break;
#endif
#if INCLUDE_SIGN
case Attributes_Signer_protected:
- f = COSE_Signer_map_put_int((HCOSE_SIGNER)hHandle, keyNew, pValueNew, which, NULL);
+ fRet &= COSE_Signer_map_put_int((HCOSE_SIGNER)hHandle, keyNew, pValueNew, which, NULL);
break;
#endif
#if INCLUDE_SIGN1
case Attributes_Sign1_protected:
- f = COSE_Sign1_map_put_int((HCOSE_SIGN1)hHandle, keyNew, pValueNew, which, NULL);
+ fRet &= COSE_Sign1_map_put_int((HCOSE_SIGN1)hHandle, keyNew, pValueNew, which, NULL);
break;
#endif
-
+ assert(fRet);
}
- // assert(f);
}
- return true;
+ return fRet;
}
bool SetSendingAttributes(HCOSE hMsg, const cn_cbor * pIn, int base)
@@ -561,7 +564,7 @@
cn_cbor * p;
cn_cbor * pKey;
cn_cbor * pValue;
- int i;
+ size_t i;
int kty;
unsigned char * pb;
size_t cb;
@@ -589,7 +592,7 @@
if (pKey->type == CN_CBOR_TEXT) {
for (i = 0; i < sizeof(RgStringKeys)/sizeof(RgStringKeys[0]); i++) {
- if ((pKey->length == strlen(RgStringKeys[i].szKey)) &&
+ if (((size_t)pKey->length == strlen(RgStringKeys[i].szKey)) &&
(strncmp(pKey->v.str, RgStringKeys[i].szKey, strlen(RgStringKeys[i].szKey)) == 0) &&
((RgStringKeys[i].kty == 0) || (RgStringKeys[i].kty == kty))) {
switch (RgStringKeys[i].operation) {
@@ -632,9 +635,6 @@
}
-
-bool cn_cbor_array_replace(cn_cbor * cb_array, cn_cbor * cb_value, int index, CBOR_CONTEXT_COMMA cn_cbor_errback *errp);
-
bool Test_cn_cbor_array_replace()
{
cn_cbor * pRoot;
diff --git a/test/test.h b/test/test.h
index 8c187af..0c77899 100644
--- a/test/test.h
+++ b/test/test.h
@@ -1,9 +1,6 @@
#pragma once
-#ifndef _countof
-
-#define _countof(x) (sizeof(x)/sizeof(x[0]))
-#endif
+#include <stdbool.h>
#ifdef USE_CBOR_CONTEXT
cn_cbor_context * context;