From caddf87c236a068f94e5283e10b9411d1cfa39e0 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Tue, 9 Jan 2024 11:43:47 +0100 Subject: [PATCH] Fix Windows emulation build. Signed-off-by: Pol Henarejos --- pico_keys_sdk_import.cmake | 1 + src/apdu.c | 8 ++++---- src/eac.c | 6 +++--- src/usb/emulation/emulation.c | 7 +++++++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/pico_keys_sdk_import.cmake b/pico_keys_sdk_import.cmake index e013847..a145d06 100644 --- a/pico_keys_sdk_import.cmake +++ b/pico_keys_sdk_import.cmake @@ -244,6 +244,7 @@ if (MSVC) -wd5045 -wd4706 -wd4061 + -wd5105 ) add_compile_definitions(_CRT_SECURE_NO_WARNINGS __STDC_WANT_SECURE_LIB__=0 diff --git a/src/apdu.c b/src/apdu.c index 896ff44..4efc0f1 100644 --- a/src/apdu.c +++ b/src/apdu.c @@ -145,9 +145,9 @@ uint16_t apdu_process(uint8_t itf, const uint8_t *buffer, uint16_t buffer_size) } #endif #else - driver_exec_finished_cont_emul(itf, apdu.ne + 2, (uint16_t)(rdata_gr - apdu.ne - usb_get_tx(itf))); + driver_exec_finished_cont_emul(itf, (uint16_t)(apdu.ne + 2), (uint16_t)(rdata_gr - apdu.ne - usb_get_tx(itf))); #endif - apdu.rlen -= apdu.ne; + apdu.rlen -= (uint16_t)apdu.ne; } } else { @@ -228,9 +228,9 @@ uint16_t apdu_next() { else { rdata_gr[1] = (uint8_t)(apdu.rlen - apdu.ne); } - apdu.rlen -= apdu.ne; + apdu.rlen -= (uint16_t)apdu.ne; } - return apdu.ne + 2; + return (uint16_t)(apdu.ne + 2); } return 0; } diff --git a/src/eac.c b/src/eac.c index 578a4b8..1d0ddf8 100644 --- a/src/eac.c +++ b/src/eac.c @@ -113,7 +113,7 @@ int sm_unwrap() { uint16_t tag = 0x0; uint8_t *tag_data = NULL, *p = NULL; uint16_t tag_len = 0; - while (walk_tlv(apdu.data, apdu.nc, &p, &tag, &tag_len, &tag_data)) { + while (walk_tlv(apdu.data, (uint16_t)apdu.nc, &p, &tag, &tag_len, &tag_data)) { if (tag == 0x87 || tag == 0x85) { body = tag_data; body_size = tag_len; @@ -209,7 +209,7 @@ uint16_t sm_get_le() { uint16_t tag = 0x0; uint8_t *tag_data = NULL, *p = NULL; uint16_t tag_len = 0; - while (walk_tlv(apdu.data, apdu.nc, &p, &tag, &tag_len, &tag_data)) { + while (walk_tlv(apdu.data, (uint16_t)apdu.nc, &p, &tag, &tag_len, &tag_data)) { if (tag == 0x97) { uint16_t le = 0; for (uint16_t t = 1; t <= tag_len; t++) { @@ -266,7 +266,7 @@ int sm_verify() { uint16_t tag = 0x0; uint8_t *tag_data = NULL, *p = NULL; uint16_t tag_len = 0; - while (walk_tlv(apdu.data, apdu.nc, &p, &tag, &tag_len, &tag_data)) { + while (walk_tlv(apdu.data, (uint16_t)apdu.nc, &p, &tag, &tag_len, &tag_data)) { if (tag & 0x1) { input[input_len++] = (uint8_t)tag; uint8_t tlen = format_tlv_len(tag_len, input + input_len); diff --git a/src/usb/emulation/emulation.c b/src/usb/emulation/emulation.c index 49a8fa5..bb370c2 100644 --- a/src/usb/emulation/emulation.c +++ b/src/usb/emulation/emulation.c @@ -334,7 +334,14 @@ uint16_t emul_read(uint8_t itf) { uint16_t len = 0; fd_set input; FD_ZERO(&input); +#ifdef _WIN32 + __pragma(warning(push)) + __pragma(warning(disable:4548)) +#endif FD_SET(sock, &input); +#ifdef _WIN32 + __pragma(warning(pop)) +#endif struct timeval timeout; timeout.tv_sec = 0; timeout.tv_usec = 0 * 1000;