Fix warnings

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos
2026-05-06 11:31:07 +02:00
parent 49564e2e5e
commit 1be7acaedd
11 changed files with 76 additions and 60 deletions

View File

@@ -426,11 +426,19 @@ function(picokeys_apply_strict_flags)
return() return()
endif() endif()
if (MSVC)
set(PICOKEYS_STRICT_FLAGS
-Wall
-Zc:strictStrings
-WX
)
else ()
set(PICOKEYS_STRICT_FLAGS set(PICOKEYS_STRICT_FLAGS
-Wextra
-pipe -pipe
-funsigned-char -funsigned-char
-fstrict-aliasing -fstrict-aliasing
-fdiagnostics-color=auto
-Wextra
-Wchar-subscripts -Wchar-subscripts
-Wundef -Wundef
-Wshadow -Wshadow
@@ -447,7 +455,6 @@ function(picokeys_apply_strict_flags)
-Winit-self -Winit-self
-Wmissing-include-dirs -Wmissing-include-dirs
-Wempty-body -Wempty-body
-fdiagnostics-color=auto
-Wmissing-prototypes -Wmissing-prototypes
-Wstrict-prototypes -Wstrict-prototypes
-Wold-style-definition -Wold-style-definition
@@ -456,6 +463,7 @@ function(picokeys_apply_strict_flags)
-Wmissing-declarations -Wmissing-declarations
-Werror -Werror
) )
endif()
foreach(src IN LISTS PKAS_SOURCES) foreach(src IN LISTS PKAS_SOURCES)
if(PKAS_FILTER_REGEX) if(PKAS_FILTER_REGEX)

View File

@@ -64,6 +64,19 @@ int settimeofday(const struct timeval* tp, const struct timezone* tzp)
} }
#endif #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 #ifdef ENABLE_EMULATION
bool set_rtc = true; bool set_rtc = true;
#else #else
@@ -79,7 +92,7 @@ void set_rtc_time(time_t t) {
struct timespec tv = {.tv_sec = t, .tv_nsec = 0}; struct timespec tv = {.tv_sec = t, .tv_nsec = 0};
aon_timer_set_time(&tv); aon_timer_set_time(&tv);
#else #else
struct timeval tv = {.tv_sec = t, .tv_usec = 0}; struct timeval tv = {.tv_sec = (long)t, .tv_usec = 0};
settimeofday(&tv, NULL); settimeofday(&tv, NULL);
#endif #endif
set_rtc = true; set_rtc = true;

View File

@@ -32,6 +32,7 @@
#include "compat/board.h" #include "compat/board.h"
#endif #endif
extern struct tm *gmtime_utc(const time_t *timep, struct tm *result);
extern bool has_set_rtc(void); extern bool has_set_rtc(void);
extern time_t get_rtc_time(void); extern time_t get_rtc_time(void);
extern void set_rtc_time(time_t tv_sec); extern void set_rtc_time(time_t tv_sec);

View File

@@ -338,23 +338,18 @@ static int cmd_read(void) {
} }
res_APDU_size = 0; res_APDU_size = 0;
time_t tv_sec = get_rtc_time(); 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) { if (p2 == 0x1) {
struct tm *tm = localtime(&tv.tv_sec); struct tm *tm = localtime(&tv_sec);
res_APDU_size += put_uint16_be(tm->tm_year + 1900, res_APDU); res_APDU_size += put_uint16_be((uint16_t)(tm->tm_year + 1900), res_APDU);
res_APDU[res_APDU_size++] = tm->tm_mon; res_APDU[res_APDU_size++] = (uint8_t)tm->tm_mon;
res_APDU[res_APDU_size++] = tm->tm_mday; res_APDU[res_APDU_size++] = (uint8_t)tm->tm_mday;
res_APDU[res_APDU_size++] = tm->tm_wday; res_APDU[res_APDU_size++] = (uint8_t)tm->tm_wday;
res_APDU[res_APDU_size++] = tm->tm_hour; res_APDU[res_APDU_size++] = (uint8_t)tm->tm_hour;
res_APDU[res_APDU_size++] = tm->tm_min; res_APDU[res_APDU_size++] = (uint8_t)tm->tm_min;
res_APDU[res_APDU_size++] = tm->tm_sec; res_APDU[res_APDU_size++] = (uint8_t)tm->tm_sec;
} }
else if (p2 == 0x2) { 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(); return SW_OK();

View File

@@ -32,7 +32,7 @@
static void hwrng_start(void) { static void hwrng_start(void) {
#if defined(ENABLE_EMULATION) #if defined(ENABLE_EMULATION)
srand(time(0)); srand((unsigned int)time(NULL));
#elif defined(ESP_PLATFORM) #elif defined(ESP_PLATFORM)
bootloader_random_enable(); bootloader_random_enable();
#endif #endif
@@ -188,8 +188,7 @@ uint32_t hwrng_get(void) {
while (true) { while (true) {
hwrng_lock(); hwrng_lock();
bool empty = rb->empty; if (!rb->empty) {
if (!empty) {
v = hwrng_buf_del(rb); v = hwrng_buf_del(rb);
hwrng_unlock(); hwrng_unlock();
break; break;
@@ -210,9 +209,8 @@ void hwrng_wait_full(void) {
#endif #endif
while (true) { while (true) {
hwrng_lock(); hwrng_lock();
bool full = rb->full;
hwrng_unlock(); hwrng_unlock();
if (full) { if (rb->full) {
break; break;
} }
#if defined(PICO_PLATFORM) || defined(ESP_PLATFORM) #if defined(PICO_PLATFORM) || defined(ESP_PLATFORM)

View File

@@ -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) { 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; 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; uint8_t n;
int ret = 0; int ret = 0;

View File

@@ -24,7 +24,7 @@
#include <stdbool.h> #include <stdbool.h>
typedef struct { typedef struct {
uint32_t index; uint8_t index;
volatile bool cancel; volatile bool cancel;
} random_fill_iterator_ctx_t; } random_fill_iterator_ctx_t;

View File

@@ -345,7 +345,7 @@ void driver_exec_finished_cont_ccid(uint8_t itf, uint16_t size_next, uint16_t of
} }
void ccid_task(void) { 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)); int status = card_status(sc_itf_to_usb_itf(itf));
if (status == PICOKEYS_OK) { if (status == PICOKEYS_OK) {
driver_exec_finished_ccid(itf, finished_data_size); driver_exec_finished_ccid(itf, finished_data_size);

View File

@@ -336,7 +336,7 @@ uint16_t emul_read(uint8_t itf) {
} }
#endif #endif
else { else {
emul_rx_size += valread; emul_rx_size += (uint16_t)valread;
} }
return (uint16_t)emul_rx_size; return (uint16_t)emul_rx_size;
} }

View File

@@ -62,7 +62,7 @@ typedef int socket_t;
static struct tcp_pcb *listener_pcb = NULL; static struct tcp_pcb *listener_pcb = NULL;
#else #else
extern socket_t tls_listener_sock; extern socket_t tls_listener_sock;
static socket_t listener_sock = -1; static socket_t listener_sock = INVALID_SOCKET;
static pthread_t rest_thread; static pthread_t rest_thread;
#endif #endif
static rest_conn_t conns[REST_MAX_CONNS]; 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); rest_close_conn(conn);
return; 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) { 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 #ifdef ENABLE_EMULATION
while (sent_total < (size_t)header_len) { 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) { if (n <= 0) {
rest_close_conn(conn); rest_close_conn(conn);
return; return;
@@ -404,7 +404,7 @@ static void send_response(rest_conn_t *conn, int status_code, const char *status
} }
sent_total = 0; sent_total = 0;
while (sent_total < body_len) { 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) { if (n <= 0) {
rest_close_conn(conn); rest_close_conn(conn);
return; return;
@@ -610,7 +610,7 @@ static int parse_request(rest_conn_t *conn, rest_request_t *request) {
} }
headers_size = conn->request_headers_size; 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; header_end = conn->request + headers_size - 4;
line_end = strstr(conn->request, "\r\n"); line_end = strstr(conn->request, "\r\n");

View File

@@ -163,6 +163,7 @@ typedef int socklen_t;
#else #else
#include <strings.h> #include <strings.h>
typedef int socket_t; typedef int socket_t;
#define INVALID_SOCKET (-1)
#include <arpa/inet.h> #include <arpa/inet.h>
#include <errno.h> #include <errno.h>
#include <netinet/in.h> #include <netinet/in.h>
@@ -171,7 +172,7 @@ typedef int socket_t;
#include <unistd.h> #include <unistd.h>
#endif #endif
socket_t tls_listener_sock = -1; socket_t tls_listener_sock = INVALID_SOCKET;
int emulation_rest_tls_port(void) { int emulation_rest_tls_port(void) {
const char *port_env = getenv("PICO_REST_TLS_PORT"); const char *port_env = getenv("PICO_REST_TLS_PORT");