From 7f53d7f74891ff082409c81f1eb43a5d0f0c30ea Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Thu, 14 May 2026 19:18:39 +0200 Subject: [PATCH] Fix warnings Signed-off-by: Pol Henarejos --- src/apdu.h | 3 ++- src/asn1.h | 4 +++- src/compat/queue.h | 3 +++ src/crypto_utils.c | 8 ++++---- src/fs/low_flash.c | 3 ++- src/fs/phy.h | 3 ++- src/pico_time.c | 10 ++++------ src/rng/hwrng.c | 8 +++++--- src/usb/lwip/rest.h | 17 ++++++++++++----- src/usb/lwip/rest_server.c | 12 +++++++++--- src/usb/lwip/rest_server.h | 15 +++++++++++---- src/usb/lwip/rest_server_tls.c | 2 ++ 12 files changed, 59 insertions(+), 29 deletions(-) diff --git a/src/apdu.h b/src/apdu.h index f0c8375..88c9526 100644 --- a/src/apdu.h +++ b/src/apdu.h @@ -34,10 +34,11 @@ extern bool app_exists(const uint8_t *aid, size_t aid_len); extern int register_app(int (*)(app_t *, uint8_t), const uint8_t *); extern int select_app(const uint8_t *aid, size_t aid_len); +PACK( typedef struct cmd { uint8_t ins; int (*cmd_handler)(void); -} cmd_t; +}) cmd_t; extern uint8_t num_apps; extern app_t apps[16]; diff --git a/src/asn1.h b/src/asn1.h index 761b3e3..b78e1ac 100644 --- a/src/asn1.h +++ b/src/asn1.h @@ -20,11 +20,13 @@ #include #include +#include "compat/compat.h" +PACK( typedef struct asn1_ctx { uint8_t *data; uint16_t len; -} asn1_ctx_t; +}) asn1_ctx_t; extern int asn1_ctx_init(uint8_t *, uint16_t, asn1_ctx_t *); extern int asn1_ctx_clear(asn1_ctx_t *ctx); diff --git a/src/compat/queue.h b/src/compat/queue.h index 1e5ba3f..f6cabd8 100644 --- a/src/compat/queue.h +++ b/src/compat/queue.h @@ -34,6 +34,9 @@ typedef struct { size_t max_elem; uint8_t buf[1024]; bool is_init; +#ifdef _MSC_VER + char padding[sizeof(void *) - sizeof(bool)]; +#endif } queue_t; static inline void queue_free(queue_t *a) { diff --git a/src/crypto_utils.c b/src/crypto_utils.c index 4e6a513..99f3bd9 100644 --- a/src/crypto_utils.c +++ b/src/crypto_utils.c @@ -254,15 +254,15 @@ int aes_decrypt_cfb_256(const uint8_t *key, const uint8_t *iv, uint8_t *data, ui return aes_decrypt(key, iv, 256, PICOKEYS_AES_MODE_CFB, data, len); } -struct lv_data { +PACK(struct lv_data { unsigned char *value; uint8_t len; -}; +}); -struct ec_curve_mbed_id { +PACK(struct ec_curve_mbed_id { struct lv_data curve; mbedtls_ecp_group_id id; -}; +}); struct ec_curve_mbed_id ec_curves_mbed[] = { { { (unsigned char *) "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFE\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", diff --git a/src/fs/low_flash.c b/src/fs/low_flash.c index 9db5807..54f3139 100644 --- a/src/fs/low_flash.c +++ b/src/fs/low_flash.c @@ -74,13 +74,14 @@ extern uint32_t FLASH_SIZE_BYTES; extern const uintptr_t start_data_pool; extern const uintptr_t end_rom_pool; +PACK( typedef struct page_flash { uint8_t page[FLASH_SECTOR_SIZE]; uintptr_t address; bool ready; bool erase; size_t page_size; //this param is for easy erase. It allows to erase with a single call. IT DOES NOT APPLY TO WRITE -} page_flash_t; +}) page_flash_t; static page_flash_t flash_pages[TOTAL_FLASH_PAGES]; diff --git a/src/fs/phy.h b/src/fs/phy.h index 7b25cb2..c144a27 100644 --- a/src/fs/phy.h +++ b/src/fs/phy.h @@ -69,6 +69,7 @@ #include #include +PACK( typedef struct phy_data { union { struct { @@ -99,7 +100,7 @@ typedef struct phy_data { bool enabled_usb_itf_present; bool led_driver_present; -} phy_data_t; +}) phy_data_t; #define PHY_MAX_SIZE ((2+4)+(2+4)+(2+32)+(2+2)+(2+1)+(2+1)+(2+1)+(2+1)+(2+1)) diff --git a/src/pico_time.c b/src/pico_time.c index 6621092..bfff039 100644 --- a/src/pico_time.c +++ b/src/pico_time.c @@ -23,13 +23,12 @@ #ifdef _MSC_VER #include -struct timezone +PACK(struct timezone { __int32 tz_minuteswest; /* minutes W of Greenwich */ bool tz_dsttime; /* type of dst correction */ -}; -int gettimeofday(struct timeval* tp, struct timezone* tzp) -{ +}); +int gettimeofday(struct timeval* tp, struct timezone* tzp) { (void)tzp; // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's // This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC) @@ -49,8 +48,7 @@ int gettimeofday(struct timeval* tp, struct timezone* tzp) tp->tv_usec = (long)(system_time.wMilliseconds * 1000); return 0; } -int settimeofday(const struct timeval* tp, const struct timezone* tzp) -{ +int settimeofday(const struct timeval* tp, const struct timezone* tzp) { (void)tzp; SYSTEMTIME st; FILETIME ft; diff --git a/src/rng/hwrng.c b/src/rng/hwrng.c index 473354f..79f2b5f 100644 --- a/src/rng/hwrng.c +++ b/src/rng/hwrng.c @@ -71,13 +71,15 @@ static int hwrng_mix_process(void) { return 0; } -struct hwrng_buf { +PACK( +typedef struct hwrng_buf { uint32_t *buf; - uint8_t head, tail; + uint8_t head; + uint8_t tail; uint8_t size; unsigned int full : 1; unsigned int empty : 1; -}; +}) hwrng_buf_t; static mutex_t hwrng_mutex; static bool hwrng_mutex_initialized = false; diff --git a/src/usb/lwip/rest.h b/src/usb/lwip/rest.h index 8510c75..f59b2f5 100644 --- a/src/usb/lwip/rest.h +++ b/src/usb/lwip/rest.h @@ -72,13 +72,14 @@ typedef enum { REST_PARAM_STRING } rest_param_type_t; +PACK( typedef struct { union { int32_t int_param; char *str_param; } param; rest_param_type_t type; -} rest_param_t; +}) rest_param_t; typedef enum { REST_ROUTE_NONE = 0x0, @@ -110,6 +111,7 @@ typedef enum { REST_SESSION_TERMINATED = 0x6, } rest_session_status_t; +PACK( typedef struct { uint8_t public_key[32]; uint8_t id[16]; @@ -121,13 +123,14 @@ typedef struct { rest_session_status_t status; uint8_t token[32]; uint8_t user_id; -} rest_session_t; +}) rest_session_t; typedef struct { const char *key; const char *value; } rest_query_t; +PACK( typedef struct { rest_http_method_t method; char path[REST_MAX_PATH_SIZE]; @@ -140,19 +143,23 @@ typedef struct { uint8_t query_count; rest_session_t *session; rest_request_conn_type_t conn_type; -} rest_request_t; +}) rest_request_t; typedef struct { - uint16_t status_code; const char *content_type; char *body; // heap ! size_t body_len; cJSON *json; char *headers[REST_HEADER_TOTAL_COUNT]; + uint16_t status_code; +#ifdef _MSC_VER + char _padding[6]; +#endif } rest_response_t; typedef int (*rest_route_handler_t)(const rest_request_t *request, rest_response_t *response); +PACK( typedef struct { rest_http_method_t method; const char *path; @@ -160,7 +167,7 @@ typedef struct { rest_route_flags_t flags; rest_route_param_parser_t param_parser; rest_session_role_t role; // Minimum required role to access this route (only relevant if REST_ROUTE_REQUIRE_AUTH flag is set) -} rest_route_t; +}) rest_route_t; typedef struct { rest_route_handler_t handler; diff --git a/src/usb/lwip/rest_server.c b/src/usb/lwip/rest_server.c index da1de84..5676294 100644 --- a/src/usb/lwip/rest_server.c +++ b/src/usb/lwip/rest_server.c @@ -31,6 +31,7 @@ #endif typedef SOCKET socket_t; typedef int socklen_t; +typedef SSIZE_T ssize_t; #define close closesocket #include #define strcasecmp _stricmp @@ -70,16 +71,20 @@ static pthread_t rest_thread; #endif static rest_conn_t conns[REST_MAX_CONNS]; +PACK( typedef struct { volatile long pending; rest_conn_t *conn; rest_route_handler_t handler; rest_request_t request; -} rest_core1_job_t; +}) rest_core1_job_t; typedef struct { - bool ready; rest_response_t response; + bool ready; +#ifdef _MSC_VER + char _padding[sizeof(void *) - sizeof(bool)]; +#endif } rest_core1_result_t; static rest_core1_job_t rest_core1_job = {0}; @@ -110,10 +115,11 @@ static void rest_core1_job_pending_store(bool pending) { #endif } +PACK( typedef struct { rest_header_id_t id; const char *name; -} rest_header_descriptor_t; +}) rest_header_descriptor_t; static const rest_header_descriptor_t rest_http_headers[REST_HEADER_TOTAL_COUNT] = { { REST_HEADER_USER_AGENT, "User-Agent" }, diff --git a/src/usb/lwip/rest_server.h b/src/usb/lwip/rest_server.h index b229d3d..8c46eae 100644 --- a/src/usb/lwip/rest_server.h +++ b/src/usb/lwip/rest_server.h @@ -51,24 +51,31 @@ typedef enum { } rest_conn_type_t; typedef struct { - bool in_use; #ifdef ENABLE_EMULATION intptr_t sock; #else struct tcp_pcb *pcb; #endif - char request[REST_MAX_REQUEST_SIZE + 1]; size_t request_len; rest_conn_type_t conn_type; +#ifdef _MSC_VER + char _padding[sizeof(void *) - sizeof(rest_conn_type_t)]; +#endif mbedtls_ssl_context ssl; unsigned char rx_cipher[REST_MAX_REQUEST_SIZE]; size_t rx_cipher_len; + size_t request_headers_size; + size_t request_content_length; + bool in_use; bool handshake_done; bool request_complete; bool request_dispatched; bool request_headers_parsed; - size_t request_headers_size; - size_t request_content_length; + char request[REST_MAX_REQUEST_SIZE + 1]; +#ifdef ENABLE_EMULATION + char _padding2[2]; +#endif + } rest_conn_t; err_t rest_server_init(rest_conn_type_t conn_type); diff --git a/src/usb/lwip/rest_server_tls.c b/src/usb/lwip/rest_server_tls.c index 5aa6198..51ac356 100644 --- a/src/usb/lwip/rest_server_tls.c +++ b/src/usb/lwip/rest_server_tls.c @@ -20,8 +20,10 @@ #ifdef _MSC_VER #include +#include #define strcasecmp _stricmp #define strncasecmp _strnicmp +typedef SSIZE_T ssize_t; #else #include #endif