From c4d3527a1164a446a1fe3088ad8eddba8c63e46a Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Tue, 12 May 2026 21:29:38 +0200 Subject: [PATCH] Fix compiling on MS VS 2022 (64-Bit) without type conversion warnings --- contrib/examples/tftp/tftp_example.c | 6 +++--- src/apps/http/makefsdata/makefsdata.c | 18 ++++++++++++------ src/netif/ppp/auth.c | 2 +- src/netif/ppp/chap-new.c | 2 +- src/netif/ppp/utils.c | 4 ++-- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/contrib/examples/tftp/tftp_example.c b/contrib/examples/tftp/tftp_example.c index f6a28b4f..4bacda0a 100644 --- a/contrib/examples/tftp/tftp_example.c +++ b/contrib/examples/tftp/tftp_example.c @@ -85,11 +85,11 @@ tftp_close(void* handle) static int tftp_read(void* handle, void* buf, int bytes) { - int ret = fread(buf, 1, bytes, (FILE*)handle); - if (ret <= 0) { + size_t ret = fread(buf, 1, bytes, (FILE*)handle); + if ((ret == 0) || (ret > INT_MAX)) { return -1; } - return ret; + return (int)ret; } static int diff --git a/src/apps/http/makefsdata/makefsdata.c b/src/apps/http/makefsdata/makefsdata.c index 62d77a32..c29c4730 100644 --- a/src/apps/http/makefsdata/makefsdata.c +++ b/src/apps/http/makefsdata/makefsdata.c @@ -132,7 +132,7 @@ int process_sub(FILE *data_file, FILE *struct_file); int process_file(FILE *data_file, FILE *struct_file, const char *filename); int file_write_http_header(FILE *data_file, const char *filename, int file_size, u16_t *http_hdr_len, u16_t *http_hdr_chksum, u8_t provide_content_len, int is_compressed); -int file_put_ascii(FILE *file, const char *ascii_string, int len, int *i); +int file_put_ascii(FILE *file, const char *ascii_string, size_t len, int *i); int s_put_ascii(char *buf, const char *ascii_string, int len, int *i); void concat_files(const char *file1, const char *file2, const char *targetfile); int check_path(char *path, size_t size); @@ -590,7 +590,7 @@ static u8_t *get_file_data(const char *filename, int *file_size, int can_be_comp LWIP_ASSERT("buf != NULL", buf != NULL); r = fread(buf, 1, fsize, inFile); LWIP_ASSERT("r == fsize", r == fsize); - *file_size = fsize; + *file_size = rs; *is_compressed = 0; #if MAKEFS_SUPPORT_DEFLATE overallDataBytes += fsize; @@ -715,6 +715,9 @@ static int write_checksums(FILE *struct_file, const char *varname, #if LWIP_TCP_TIMESTAMPS /* when timestamps are used, usable space is 12 bytes less per segment */ chunk_size -= 12; +#if TCP_MSS <= 12 +#error TCP_MSS <= 12 +#endif #endif fprintf(struct_file, "#if HTTPD_PRECALCULATED_CHECKSUM" NEWLINE); @@ -726,7 +729,7 @@ static int write_checksums(FILE *struct_file, const char *varname, i++; } src_offset = 0; - for (offset = hdr_len; ; offset += len) { + for (offset = hdr_len; ; offset += (int)len) { unsigned short chksum; const void *data = (const void *)&file_data[src_offset]; len = LWIP_MIN(chunk_size, (int)file_size - src_offset); @@ -1281,9 +1284,12 @@ int file_write_http_header(FILE *data_file, const char *filename, int file_size, return written; } -int file_put_ascii(FILE *file, const char *ascii_string, int len, int *i) +int file_put_ascii(FILE *file, const char *ascii_string, size_t len, int *i) { - int x; + if (len > INT_MAX) { + return -1; + } + size_t x; for (x = 0; x < len; x++) { unsigned char cur = ascii_string[x]; fprintf(file, "0x%02x,", cur); @@ -1291,7 +1297,7 @@ int file_put_ascii(FILE *file, const char *ascii_string, int len, int *i) fprintf(file, NEWLINE); } } - return len; + return (int)len; } int s_put_ascii(char *buf, const char *ascii_string, int len, int *i) diff --git a/src/netif/ppp/auth.c b/src/netif/ppp/auth.c index 1f271752..cfbf064b 100644 --- a/src/netif/ppp/auth.c +++ b/src/netif/ppp/auth.c @@ -1919,7 +1919,7 @@ int get_secret(ppp_pcb *pcb, const char *client, const char *server, char *secre } MEMCPY(secret, pcb->settings.passwd, len); - *secret_len = len; + *secret_len = (int)len; return 1; #if 0 /* UNUSED */ diff --git a/src/netif/ppp/chap-new.c b/src/netif/ppp/chap-new.c index da12430c..6f6e44f9 100644 --- a/src/netif/ppp/chap-new.c +++ b/src/netif/ppp/chap-new.c @@ -480,7 +480,7 @@ static void chap_respond(ppp_pcb *pcb, int id, memset(secret, 0, secret_len); clen = *outp; - nlen = strlen(pcb->chap_client.name); + nlen = (int)strlen(pcb->chap_client.name); memcpy(outp + clen + 1, pcb->chap_client.name, nlen); outp = (u_char*)p->payload + PPP_HDRLEN; diff --git a/src/netif/ppp/utils.c b/src/netif/ppp/utils.c index 99a5fb1d..d4e4759a 100644 --- a/src/netif/ppp/utils.c +++ b/src/netif/ppp/utils.c @@ -289,7 +289,7 @@ int ppp_vslprintf(char *buf, int buflen, const char *fmt, va_list args) { if (fillch == '0' && prec >= 0) { n = prec; } else { - n = strlen((const char *)p); + n = (int)strlen((const char *)p); if (prec >= 0 && n > prec) n = prec; } @@ -378,7 +378,7 @@ int ppp_vslprintf(char *buf, int buflen, const char *fmt, va_list args) { } len = num + sizeof(num) - 1 - str; } else { - len = strlen(str); + len = (int)strlen(str); if (prec >= 0 && len > prec) len = prec; }