From 1be7acaedde498b3251baa177d5ca7264eb5ef0d Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Wed, 6 May 2026 11:31:07 +0200 Subject: [PATCH] Fix warnings Signed-off-by: Pol Henarejos --- picokeys_sdk_import.cmake | 68 +++++++++++++++++++--------------- src/pico_time.c | 15 +++++++- src/pico_time.h | 1 + src/rescue.c | 23 +++++------- src/rng/hwrng.c | 8 ++-- src/rng/random.c | 2 +- src/rng/random.h | 2 +- src/usb/ccid/ccid.c | 2 +- src/usb/emulation/emulation.c | 2 +- src/usb/lwip/rest_server.c | 10 ++--- src/usb/lwip/rest_server_tls.c | 3 +- 11 files changed, 76 insertions(+), 60 deletions(-) diff --git a/picokeys_sdk_import.cmake b/picokeys_sdk_import.cmake index 8a64bb1..05c4d5c 100644 --- a/picokeys_sdk_import.cmake +++ b/picokeys_sdk_import.cmake @@ -426,36 +426,44 @@ function(picokeys_apply_strict_flags) return() endif() - set(PICOKEYS_STRICT_FLAGS - -Wextra - -pipe - -funsigned-char - -fstrict-aliasing - -Wchar-subscripts - -Wundef - -Wshadow - -Wcast-align - -Wwrite-strings - -Wunused - -Wuninitialized - -Wpointer-arith - -Wredundant-decls - -Winline - -Wformat - -Wformat-security - -Wswitch-enum - -Winit-self - -Wmissing-include-dirs - -Wempty-body - -fdiagnostics-color=auto - -Wmissing-prototypes - -Wstrict-prototypes - -Wold-style-definition - -Wbad-function-cast - -Wnested-externs - -Wmissing-declarations - -Werror - ) + if (MSVC) + set(PICOKEYS_STRICT_FLAGS + -Wall + -Zc:strictStrings + -WX + ) + else () + set(PICOKEYS_STRICT_FLAGS + -pipe + -funsigned-char + -fstrict-aliasing + -fdiagnostics-color=auto + -Wextra + -Wchar-subscripts + -Wundef + -Wshadow + -Wcast-align + -Wwrite-strings + -Wunused + -Wuninitialized + -Wpointer-arith + -Wredundant-decls + -Winline + -Wformat + -Wformat-security + -Wswitch-enum + -Winit-self + -Wmissing-include-dirs + -Wempty-body + -Wmissing-prototypes + -Wstrict-prototypes + -Wold-style-definition + -Wbad-function-cast + -Wnested-externs + -Wmissing-declarations + -Werror + ) + endif() foreach(src IN LISTS PKAS_SOURCES) if(PKAS_FILTER_REGEX) diff --git a/src/pico_time.c b/src/pico_time.c index ac1fb7f..6621092 100644 --- a/src/pico_time.c +++ b/src/pico_time.c @@ -64,6 +64,19 @@ int settimeofday(const struct timeval* tp, const struct timezone* tzp) } #endif +struct tm *gmtime_utc(const time_t *timep, struct tm *result) { +#ifdef _WIN32 + struct tm *tmp = gmtime(timep); + if (tmp == NULL) { + return NULL; + } + *result = *tmp; + return result; +#else + return gmtime_r(timep, result); +#endif +} + #ifdef ENABLE_EMULATION bool set_rtc = true; #else @@ -79,7 +92,7 @@ void set_rtc_time(time_t t) { struct timespec tv = {.tv_sec = t, .tv_nsec = 0}; aon_timer_set_time(&tv); #else - struct timeval tv = {.tv_sec = t, .tv_usec = 0}; + struct timeval tv = {.tv_sec = (long)t, .tv_usec = 0}; settimeofday(&tv, NULL); #endif set_rtc = true; diff --git a/src/pico_time.h b/src/pico_time.h index ac7af7d..3c6ff94 100644 --- a/src/pico_time.h +++ b/src/pico_time.h @@ -32,6 +32,7 @@ #include "compat/board.h" #endif +extern struct tm *gmtime_utc(const time_t *timep, struct tm *result); extern bool has_set_rtc(void); extern time_t get_rtc_time(void); extern void set_rtc_time(time_t tv_sec); diff --git a/src/rescue.c b/src/rescue.c index 3cf5a39..e13a4d6 100644 --- a/src/rescue.c +++ b/src/rescue.c @@ -338,23 +338,18 @@ static int cmd_read(void) { } res_APDU_size = 0; time_t tv_sec = get_rtc_time(); -#ifdef PICO_PLATFORM - struct timespec tv = {.tv_sec = tv_sec, .tv_nsec = 0}; -#else - struct timeval tv = {.tv_sec = tv_sec, .tv_usec = 0}; -#endif if (p2 == 0x1) { - struct tm *tm = localtime(&tv.tv_sec); - res_APDU_size += put_uint16_be(tm->tm_year + 1900, res_APDU); - res_APDU[res_APDU_size++] = tm->tm_mon; - res_APDU[res_APDU_size++] = tm->tm_mday; - res_APDU[res_APDU_size++] = tm->tm_wday; - res_APDU[res_APDU_size++] = tm->tm_hour; - res_APDU[res_APDU_size++] = tm->tm_min; - res_APDU[res_APDU_size++] = tm->tm_sec; + struct tm *tm = localtime(&tv_sec); + res_APDU_size += put_uint16_be((uint16_t)(tm->tm_year + 1900), res_APDU); + res_APDU[res_APDU_size++] = (uint8_t)tm->tm_mon; + res_APDU[res_APDU_size++] = (uint8_t)tm->tm_mday; + res_APDU[res_APDU_size++] = (uint8_t)tm->tm_wday; + res_APDU[res_APDU_size++] = (uint8_t)tm->tm_hour; + res_APDU[res_APDU_size++] = (uint8_t)tm->tm_min; + res_APDU[res_APDU_size++] = (uint8_t)tm->tm_sec; } else if (p2 == 0x2) { - res_APDU_size += put_uint32_be((uint32_t)tv.tv_sec, res_APDU); + res_APDU_size += put_uint32_be((uint32_t)tv_sec, res_APDU); } } return SW_OK(); diff --git a/src/rng/hwrng.c b/src/rng/hwrng.c index 6a9b5f9..473354f 100644 --- a/src/rng/hwrng.c +++ b/src/rng/hwrng.c @@ -32,7 +32,7 @@ static void hwrng_start(void) { #if defined(ENABLE_EMULATION) - srand(time(0)); + srand((unsigned int)time(NULL)); #elif defined(ESP_PLATFORM) bootloader_random_enable(); #endif @@ -188,8 +188,7 @@ uint32_t hwrng_get(void) { while (true) { hwrng_lock(); - bool empty = rb->empty; - if (!empty) { + if (!rb->empty) { v = hwrng_buf_del(rb); hwrng_unlock(); break; @@ -210,9 +209,8 @@ void hwrng_wait_full(void) { #endif while (true) { hwrng_lock(); - bool full = rb->full; hwrng_unlock(); - if (full) { + if (rb->full) { break; } #if defined(PICO_PLATFORM) || defined(ESP_PLATFORM) diff --git a/src/rng/random.c b/src/rng/random.c index 1cc2083..939f38b 100644 --- a/src/rng/random.c +++ b/src/rng/random.c @@ -80,7 +80,7 @@ const uint8_t *random_bytes_get(size_t len) { */ int random_fill_iterator(void *arg, unsigned char *out, size_t out_len) { random_fill_iterator_ctx_t *ctx = (random_fill_iterator_ctx_t *) arg; - uint32_t index = ctx ? ctx->index : 0; + uint8_t index = ctx ? ctx->index : 0; uint8_t n; int ret = 0; diff --git a/src/rng/random.h b/src/rng/random.h index 7a1526e..9a5eb8d 100644 --- a/src/rng/random.h +++ b/src/rng/random.h @@ -24,7 +24,7 @@ #include typedef struct { - uint32_t index; + uint8_t index; volatile bool cancel; } random_fill_iterator_ctx_t; diff --git a/src/usb/ccid/ccid.c b/src/usb/ccid/ccid.c index 0b2bd79..7ef4a20 100644 --- a/src/usb/ccid/ccid.c +++ b/src/usb/ccid/ccid.c @@ -345,7 +345,7 @@ void driver_exec_finished_cont_ccid(uint8_t itf, uint16_t size_next, uint16_t of } void ccid_task(void) { - for (int itf = 0; itf < ITF_SC_TOTAL; itf++) { + for (uint8_t itf = 0; itf < ITF_SC_TOTAL; itf++) { int status = card_status(sc_itf_to_usb_itf(itf)); if (status == PICOKEYS_OK) { driver_exec_finished_ccid(itf, finished_data_size); diff --git a/src/usb/emulation/emulation.c b/src/usb/emulation/emulation.c index 92aa49b..74ca2c7 100644 --- a/src/usb/emulation/emulation.c +++ b/src/usb/emulation/emulation.c @@ -336,7 +336,7 @@ uint16_t emul_read(uint8_t itf) { } #endif else { - emul_rx_size += valread; + emul_rx_size += (uint16_t)valread; } return (uint16_t)emul_rx_size; } diff --git a/src/usb/lwip/rest_server.c b/src/usb/lwip/rest_server.c index 8bf10c6..80ec06b 100644 --- a/src/usb/lwip/rest_server.c +++ b/src/usb/lwip/rest_server.c @@ -62,7 +62,7 @@ typedef int socket_t; static struct tcp_pcb *listener_pcb = NULL; #else extern socket_t tls_listener_sock; -static socket_t listener_sock = -1; +static socket_t listener_sock = INVALID_SOCKET; static pthread_t rest_thread; #endif static rest_conn_t conns[REST_MAX_CONNS]; @@ -162,7 +162,7 @@ static void send_json_error(rest_conn_t *conn, int status_code, const char *erro rest_close_conn(conn); return; } - send_json(conn, status_code, rest_status_text_from_code(status_code), json); + send_json(conn, status_code, rest_status_text_from_code((uint16_t)status_code), json); } void rest_task(void) { @@ -395,7 +395,7 @@ static void send_response(rest_conn_t *conn, int status_code, const char *status } #ifdef ENABLE_EMULATION while (sent_total < (size_t)header_len) { - int n = send((socket_t)conn->sock, headers_buf + sent_total, (size_t)header_len - sent_total, 0); + int n = send((socket_t)conn->sock, headers_buf + sent_total, (int)((size_t)header_len - sent_total), 0); if (n <= 0) { rest_close_conn(conn); return; @@ -404,7 +404,7 @@ static void send_response(rest_conn_t *conn, int status_code, const char *status } sent_total = 0; while (sent_total < body_len) { - int n = send((socket_t)conn->sock, body + sent_total, body_len - sent_total, 0); + int n = send((socket_t)conn->sock, body + sent_total, (int)(body_len - sent_total), 0); if (n <= 0) { rest_close_conn(conn); return; @@ -610,7 +610,7 @@ static int parse_request(rest_conn_t *conn, rest_request_t *request) { } headers_size = conn->request_headers_size; - content_length = conn->request_content_length; + content_length = (unsigned long)conn->request_content_length; header_end = conn->request + headers_size - 4; line_end = strstr(conn->request, "\r\n"); diff --git a/src/usb/lwip/rest_server_tls.c b/src/usb/lwip/rest_server_tls.c index c09efed..a7b95a6 100644 --- a/src/usb/lwip/rest_server_tls.c +++ b/src/usb/lwip/rest_server_tls.c @@ -163,6 +163,7 @@ typedef int socklen_t; #else #include typedef int socket_t; +#define INVALID_SOCKET (-1) #include #include #include @@ -171,7 +172,7 @@ typedef int socket_t; #include #endif -socket_t tls_listener_sock = -1; +socket_t tls_listener_sock = INVALID_SOCKET; int emulation_rest_tls_port(void) { const char *port_env = getenv("PICO_REST_TLS_PORT");