From 1dd835d6987a2db23a669a812f152ea843804038 Mon Sep 17 00:00:00 2001 From: yparitcher Date: Sun, 6 Jan 2019 11:41:56 -0500 Subject: [PATCH] add -Wextra: further code cleanup please fix Wno-unused-parameter -Wno-missing-field-initializers in the future --- fido2/ctap.c | 9 +++++---- fido2/ctap_parse.c | 24 +++++++++++++----------- fido2/ctap_parse.h | 2 +- fido2/ctaphid.c | 10 +++++----- fido2/device.h | 2 +- fido2/log.c | 2 +- fido2/main.c | 2 +- pc/device.c | 2 +- targets/stm32l432/bootloader/main.c | 2 +- targets/stm32l432/build/application.mk | 2 +- targets/stm32l432/build/bootloader.mk | 2 +- targets/stm32l432/src/crypto.c | 4 ++-- targets/stm32l432/src/device.c | 2 +- targets/stm32l432/src/flash.c | 2 +- 14 files changed, 35 insertions(+), 32 deletions(-) diff --git a/fido2/ctap.c b/fido2/ctap.c index bc09e9c..4cbdeb7 100644 --- a/fido2/ctap.c +++ b/fido2/ctap.c @@ -309,7 +309,7 @@ static int is_matching_rk(CTAP_residentKey * rk, CTAP_residentKey * rk2) } -static int ctap_make_auth_data(struct rpId * rp, CborEncoder * map, uint8_t * auth_data_buf, int len, CTAP_userEntity * user, uint8_t credtype, int32_t algtype, int32_t * sz, int store) +static int ctap_make_auth_data(struct rpId * rp, CborEncoder * map, uint8_t * auth_data_buf, unsigned int len, CTAP_userEntity * user, uint8_t credtype, int32_t algtype, int32_t * sz, int store) { CborEncoder cose_key; int auth_data_sz, ret; @@ -380,8 +380,8 @@ static int ctap_make_auth_data(struct rpId * rp, CborEncoder * map, uint8_t * au memmove(&rk.id, &authData->attest.id, sizeof(CredentialId)); memmove(&rk.user, user, sizeof(CTAP_userEntity)); - int index = STATE.rk_stored; - int i; + unsigned int index = STATE.rk_stored; + unsigned int i; for (i = 0; i < index; i++) { ctap_load_rk(i, &rk2); @@ -549,7 +549,8 @@ int ctap_authenticate_credential(struct rpId * rp, CTAP_credentialDescriptor * d uint8_t ctap_make_credential(CborEncoder * encoder, uint8_t * request, int length) { CTAP_makeCredential MC; - int ret, i; + int ret; + unsigned int i; uint8_t auth_data_buf[300]; CTAP_credentialDescriptor * excl_cred = (CTAP_credentialDescriptor *) auth_data_buf; uint8_t * sigbuf = auth_data_buf + 32; diff --git a/fido2/ctap_parse.c b/fido2/ctap_parse.c index ccbbcbb..f76dde7 100644 --- a/fido2/ctap_parse.c +++ b/fido2/ctap_parse.c @@ -79,7 +79,7 @@ uint8_t parse_user(CTAP_makeCredential * MC, CborValue * val) size_t sz, map_length; uint8_t key[24]; int ret; - int i; + unsigned int i; CborValue map; @@ -270,7 +270,7 @@ uint8_t parse_pub_key_cred_params(CTAP_makeCredential * MC, CborValue * val) uint8_t cred_type; int32_t alg_type; int ret; - int i; + unsigned int i; CborValue arr; @@ -319,7 +319,7 @@ uint8_t parse_pub_key_cred_params(CTAP_makeCredential * MC, CborValue * val) return CTAP2_ERR_UNSUPPORTED_ALGORITHM; } -uint8_t parse_fixed_byte_string(CborValue * map, uint8_t * dst, int len) +uint8_t parse_fixed_byte_string(CborValue * map, uint8_t * dst, unsigned int len) { size_t sz; int ret; @@ -344,7 +344,7 @@ uint8_t parse_fixed_byte_string(CborValue * map, uint8_t * dst, int len) uint8_t parse_verify_exclude_list(CborValue * val) { - int i; + unsigned int i; int ret; CborValue arr; size_t size; @@ -393,7 +393,7 @@ uint8_t parse_rp(struct rpId * rp, CborValue * val) size_t sz, map_length; char key[8]; int ret; - int i; + unsigned int i; CborValue map; @@ -481,7 +481,7 @@ uint8_t parse_options(CborValue * val, uint8_t * rk, uint8_t * uv, uint8_t * up) size_t sz, map_length; char key[8]; int ret; - int i; + unsigned int i; _Bool b; CborValue map; @@ -559,7 +559,7 @@ uint8_t parse_options(CborValue * val, uint8_t * rk, uint8_t * uv, uint8_t * up) uint8_t ctap_parse_make_credential(CTAP_makeCredential * MC, CborEncoder * encoder, uint8_t * request, int length) { int ret; - int i; + unsigned int i; int key; size_t map_length; CborParser parser; @@ -775,7 +775,8 @@ uint8_t parse_allow_list(CTAP_getAssertion * GA, CborValue * it) { CborValue arr; size_t len; - int i,ret; + int ret; + unsigned int i; CTAP_credentialDescriptor * cred; if (cbor_value_get_type(it) != CborArrayType) @@ -817,7 +818,7 @@ uint8_t parse_allow_list(CTAP_getAssertion * GA, CborValue * it) uint8_t ctap_parse_get_assertion(CTAP_getAssertion * GA, uint8_t * request, int length) { int ret; - int i; + unsigned int i; int key; size_t map_length; CborParser parser; @@ -943,7 +944,8 @@ uint8_t parse_cose_key(CborValue * it, uint8_t * x, uint8_t * y, int * kty, int { CborValue map; size_t map_length; - int i,ret,key; + int ret,key; + unsigned int i; int xkey = 0,ykey = 0; *kty = 0; *crv = 0; @@ -1038,7 +1040,7 @@ uint8_t parse_cose_key(CborValue * it, uint8_t * x, uint8_t * y, int * kty, int uint8_t ctap_parse_client_pin(CTAP_clientPin * CP, uint8_t * request, int length) { int ret; - int i; + unsigned int i; int key; size_t map_length; size_t sz; diff --git a/fido2/ctap_parse.h b/fido2/ctap_parse.h index f6b1739..3a177af 100644 --- a/fido2/ctap_parse.h +++ b/fido2/ctap_parse.h @@ -24,7 +24,7 @@ const char * cbor_value_get_type_string(const CborValue *value); uint8_t parse_user(CTAP_makeCredential * MC, CborValue * val); uint8_t parse_pub_key_cred_param(CborValue * val, uint8_t * cred_type, int32_t * alg_type); uint8_t parse_pub_key_cred_params(CTAP_makeCredential * MC, CborValue * val); -uint8_t parse_fixed_byte_string(CborValue * map, uint8_t * dst, int len); +uint8_t parse_fixed_byte_string(CborValue * map, uint8_t * dst, unsigned int len); uint8_t parse_rp_id(struct rpId * rp, CborValue * val); uint8_t parse_rp(struct rpId * rp, CborValue * val); uint8_t parse_options(CborValue * val, uint8_t * rk, uint8_t * uv, uint8_t * up); diff --git a/fido2/ctaphid.c b/fido2/ctaphid.c index 5343b0f..3f787ae 100644 --- a/fido2/ctaphid.c +++ b/fido2/ctaphid.c @@ -98,7 +98,7 @@ static uint32_t get_new_cid() static int8_t add_cid(uint32_t cid) { - int i; + uint32_t i; for(i = 0; i < CID_MAX-1; i++) { if (!CIDS[i].busy) @@ -114,7 +114,7 @@ static int8_t add_cid(uint32_t cid) static int8_t cid_exists(uint32_t cid) { - int i; + uint32_t i; for(i = 0; i < CID_MAX-1; i++) { if (CIDS[i].cid == cid) @@ -127,7 +127,7 @@ static int8_t cid_exists(uint32_t cid) static int8_t cid_refresh(uint32_t cid) { - int i; + uint32_t i; for(i = 0; i < CID_MAX-1; i++) { if (CIDS[i].cid == cid) @@ -142,7 +142,7 @@ static int8_t cid_refresh(uint32_t cid) static int8_t cid_del(uint32_t cid) { - int i; + uint32_t i; for(i = 0; i < CID_MAX-1; i++) { if (CIDS[i].cid == cid) @@ -380,7 +380,7 @@ static int ctaphid_buffer_packet(uint8_t * pkt_raw, uint8_t * cmd, uint32_t * ci printf1(TAG_HID, "Recv packet\n"); printf1(TAG_HID, " CID: %08x \n", pkt->cid); printf1(TAG_HID, " cmd: %02x\n", pkt->pkt.init.cmd); - if (!is_cont_pkt(pkt)) printf1(TAG_HID, " length: %d\n", ctaphid_packet_len(pkt)); + if (!is_cont_pkt(pkt)) {printf1(TAG_HID, " length: %d\n", ctaphid_packet_len(pkt));} int ret; uint32_t oldcid; diff --git a/fido2/device.h b/fido2/device.h index 4e02e78..e75f250 100644 --- a/fido2/device.h +++ b/fido2/device.h @@ -46,7 +46,7 @@ void device_manage(); // sets status that's uses for sending status updates ~100ms. // A timer should be set up to call `ctaphid_update_status` -void device_set_status(int status); +void device_set_status(uint32_t status); // Returns if button is currently pressed int device_is_button_pressed(); diff --git a/fido2/log.c b/fido2/log.c index 1840535..c3aadf0 100644 --- a/fido2/log.c +++ b/fido2/log.c @@ -57,7 +57,7 @@ __attribute__((weak)) void set_logging_tag(uint32_t tag) void LOG(uint32_t tag, const char * filename, int num, const char * fmt, ...) { - int i; + unsigned int i; if (((tag & 0x7fffffff) & LOGMASK) == 0) { diff --git a/fido2/main.c b/fido2/main.c index 0b05d83..dbe6301 100644 --- a/fido2/main.c +++ b/fido2/main.c @@ -19,7 +19,7 @@ #if !defined(TEST) -int main(int argc, char * argv[]) +int main() { uint8_t hidmsg[64]; uint32_t t1 = 0; diff --git a/pc/device.c b/pc/device.c index 9747aa4..b4d5379 100644 --- a/pc/device.c +++ b/pc/device.c @@ -26,7 +26,7 @@ void authenticator_initialize(); uint32_t __device_status = 0; -void device_set_status(int status) +void device_set_status(uint32_t status) { if (status != CTAPHID_STATUS_IDLE && __device_status != status) { diff --git a/targets/stm32l432/bootloader/main.c b/targets/stm32l432/bootloader/main.c index a49ebdb..ad5cbf1 100644 --- a/targets/stm32l432/bootloader/main.c +++ b/targets/stm32l432/bootloader/main.c @@ -38,7 +38,7 @@ void BOOT_boot(void) ((pFunction)bootAddress[1])(); } -int main(int argc, char * argv[]) +int main() { uint8_t hidmsg[64]; uint32_t t1 = 0; diff --git a/targets/stm32l432/build/application.mk b/targets/stm32l432/build/application.mk index fdddba2..37c4ea5 100644 --- a/targets/stm32l432/build/application.mk +++ b/targets/stm32l432/build/application.mk @@ -43,7 +43,7 @@ endif DEFINES = -DDEBUG_LEVEL=$(DEBUG) -D$(CHIP) -DAES256=1 -DUSE_FULL_LL_DRIVER -DAPP_CONFIG=\"app.h\" $(EXTRA_DEFINES) # DEFINES += -DTEST_SOLO_STM32 -DTEST -DTEST_FIFO=1 -CFLAGS=$(INC) -c $(DEFINES) -Wall -fdata-sections -ffunction-sections $(HW) -g $(VERSION_FLAGS) +CFLAGS=$(INC) -c $(DEFINES) -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -fdata-sections -ffunction-sections $(HW) -g $(VERSION_FLAGS) LDFLAGS_LIB=$(HW) $(SEARCH) -specs=nano.specs -specs=nosys.specs -Wl,--gc-sections -u _printf_float -lnosys LDFLAGS=$(HW) $(LDFLAGS_LIB) -T$(LDSCRIPT) -Wl,-Map=$(TARGET).map,--cref -Wl,-Bstatic -ltinycbor diff --git a/targets/stm32l432/build/bootloader.mk b/targets/stm32l432/build/bootloader.mk index d65ac03..24f2751 100644 --- a/targets/stm32l432/build/bootloader.mk +++ b/targets/stm32l432/build/bootloader.mk @@ -41,7 +41,7 @@ endif DEFINES = -DDEBUG_LEVEL=$(DEBUG) -D$(CHIP) -DAES256=1 -DUSE_FULL_LL_DRIVER -DAPP_CONFIG=\"bootloader.h\" $(EXTRA_DEFINES) # DEFINES += -DTEST_SOLO_STM32 -DTEST -DTEST_FIFO=1 -CFLAGS=$(INC) -c $(DEFINES) -Wall -fdata-sections -ffunction-sections $(HW) -g $(VERSION_FLAGS) +CFLAGS=$(INC) -c $(DEFINES) -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -fdata-sections -ffunction-sections $(HW) -g $(VERSION_FLAGS) LDFLAGS_LIB=$(HW) $(SEARCH) -specs=nano.specs -specs=nosys.specs -Wl,--gc-sections -lnosys LDFLAGS=$(HW) $(LDFLAGS_LIB) -T$(LDSCRIPT) -Wl,-Map=$(TARGET).map,--cref -Wl,-Bstatic diff --git a/targets/stm32l432/src/crypto.c b/targets/stm32l432/src/crypto.c index 269a1df..7de78fa 100644 --- a/targets/stm32l432/src/crypto.c +++ b/targets/stm32l432/src/crypto.c @@ -99,7 +99,7 @@ void crypto_sha256_final(uint8_t * hash) void crypto_sha256_hmac_init(uint8_t * key, uint32_t klen, uint8_t * hmac) { uint8_t buf[64]; - int i; + unsigned int i; memset(buf, 0, sizeof(buf)); if (key == CRYPTO_MASTER_KEY) @@ -133,7 +133,7 @@ void crypto_sha256_hmac_init(uint8_t * key, uint32_t klen, uint8_t * hmac) void crypto_sha256_hmac_final(uint8_t * key, uint32_t klen, uint8_t * hmac) { uint8_t buf[64]; - int i; + unsigned int i; crypto_sha256_final(hmac); memset(buf, 0, sizeof(buf)); if (key == CRYPTO_MASTER_KEY) diff --git a/targets/stm32l432/src/device.c b/targets/stm32l432/src/device.c index c6dbd90..59b19d6 100644 --- a/targets/stm32l432/src/device.c +++ b/targets/stm32l432/src/device.c @@ -63,7 +63,7 @@ uint32_t millis() return (((uint32_t)TIM6->CNT) + (__90_ms * 90)); } -void device_set_status(int status) +void device_set_status(uint32_t status) { __disable_irq(); __last_update = millis(); diff --git a/targets/stm32l432/src/flash.c b/targets/stm32l432/src/flash.c index 8d64e31..c37439d 100644 --- a/targets/stm32l432/src/flash.c +++ b/targets/stm32l432/src/flash.c @@ -133,7 +133,7 @@ void flash_write_dword(uint32_t addr, uint64_t data) void flash_write(uint32_t addr, uint8_t * data, size_t sz) { - int i; + unsigned int i; uint8_t buf[8]; while (FLASH->SR & (1<<16)) ;