diff --git a/CMakeLists.txt b/CMakeLists.txt index 07eff8d90..f6253eabd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,7 @@ set_target_properties(iio ${IIO_COMPAT_LIB} PROPERTIES ) if (WIN32) if (MSVC) + target_link_options(iio PUBLIC /DEBUG) set(LIBIIO_WIN32_PREFIX lib) endif() @@ -131,7 +132,9 @@ set(LEVEL_Debug 5) set(DEFAULT_LOG_LEVEL ${LEVEL_${LOG_LEVEL}}) if (MSVC) - target_compile_options(iio PRIVATE /W4 /wd4200 /wd4127 /wd4100) + target_compile_options(iio PRIVATE /Zi /W4 /wd4200 /wd4127 /wd4100) + # Zi produces a separate PDB file that contains all the symbolic debugging information + # W4 displays level 1, 2, 3, and 4 (informational) warnings that aren't off by default # C4200: nonstandard extension used : zero-sized array in struct (usb.h) # C4127: conditional expression is constant (IIO_ERROR and IIO_DEBUG macros) # C4100: unreferenced parameter; same as -Wno-unused-parameter diff --git a/dns_sd.c b/dns_sd.c index 870cb7fa6..1eedd52bf 100644 --- a/dns_sd.c +++ b/dns_sd.c @@ -89,7 +89,7 @@ static int dnssd_add_scan_result(const struct iio_context_params *params, char *hostname, char *addr_str, uint16_t port) { struct iio_context *ctx; - char uri[sizeof("ip:") + MAXHOSTNAMELEN + sizeof (":65535") + 1]; + char uri[sizeof("ip:") + FQDN_LEN + sizeof (":65535") + 1]; char description[255], *p; const char *hw_model, *serial; unsigned int i; diff --git a/dns_sd.h b/dns_sd.h index 9f6915b63..160c97882 100644 --- a/dns_sd.h +++ b/dns_sd.h @@ -15,14 +15,12 @@ #ifdef _WIN32 #include -#ifndef MAXHOSTNAMELEN -#define MAXHOSTNAMELEN (MAX_COMPUTERNAME_LENGTH+1) -#endif /* MAXHOSTNAMELEN */ #else #include #endif #define DNS_SD_ADDRESS_STR_MAX (40) /* IPv6 Max = 4*8 + 7 + 1 for NUL */ +#define FQDN_LEN (255) /* RFC 1035 */ /* MacOS doesn't include ENOMEDIUM (No medium found) like Linux does */ #ifndef ENOMEDIUM diff --git a/dns_sd_bonjour.c b/dns_sd_bonjour.c index cd33b58d1..c05f9e6bb 100644 --- a/dns_sd_bonjour.c +++ b/dns_sd_bonjour.c @@ -33,8 +33,8 @@ static void __cfnet_browser_cb(CFNetServiceBrowserRef browser, const struct iio_context_params *params = bdata->params; char address_v4[DNS_SD_ADDRESS_STR_MAX+1] = ""; char address_v6[DNS_SD_ADDRESS_STR_MAX+1] = ""; - char hostname[MAXHOSTNAMELEN]; - char name[MAXHOSTNAMELEN]; + char hostname[FQDN_LEN]; + char name[FQDN_LEN]; bool have_v4 = false; bool have_v6 = false; struct sockaddr_in *sa; diff --git a/network-windows.c b/network-windows.c index 71dcf39f6..1fd8a79b4 100644 --- a/network-windows.c +++ b/network-windows.c @@ -11,9 +11,6 @@ #include #include #define close(s) closesocket(s) -#ifndef MAXHOSTNAMELEN -#define MAXHOSTNAMELEN (MAX_COMPUTERNAME_LENGTH+1) -#endif /* MAXHOSTNAMELEN */ int set_blocking_mode(int s, bool blocking) { diff --git a/network.c b/network.c index 2e3e20d0c..3e1a11b30 100644 --- a/network.c +++ b/network.c @@ -640,7 +640,7 @@ static struct iio_context * network_create_context(const struct iio_context_para char *description, *end, *port = NULL; const char *ctx_attrs[] = { "ip,ip-addr", "uri" }; const char *ctx_values[2]; - char uri[MAXHOSTNAMELEN + 3]; + char uri[FQDN_LEN + 3]; char port_str[6]; uint16_t port_num = IIOD_PORT; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0b067acdf..941235416 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -23,6 +23,7 @@ if (MSVC) target_sources(iio_tests_helper PRIVATE ../deps/wingetopt/src/getopt.c) target_include_directories(iio_tests_helper PUBLIC ../deps/wingetopt/src) target_compile_definitions(iio_tests_helper PRIVATE _CRT_SECURE_NO_WARNINGS) + target_link_options(iio_tests_helper PUBLIC /DEBUG) endif() set_target_properties(iio_tests_helper PROPERTIES C_STANDARD 99 @@ -42,6 +43,9 @@ foreach (test ${IIO_TESTS_TARGETS}) target_compile_definitions(${test} PRIVATE IIO_CHECK_RET) endif() target_link_libraries(${test} LINK_PRIVATE iio iio_tests_helper) + if (MSVC) + target_link_options(${test} PUBLIC /DEBUG) + endif() endforeach() if(PTHREAD_LIBRARIES) diff --git a/tests/iio_common.c b/tests/iio_common.c index d89f4f443..dfd9273dc 100644 --- a/tests/iio_common.c +++ b/tests/iio_common.c @@ -448,7 +448,7 @@ uint64_t get_time_us(void) { struct timespec tp; -#ifdef _WIN32 +#ifdef _MSC_BUILD timespec_get(&tp, TIME_UTC); #else clock_gettime(CLOCK_REALTIME, &tp); diff --git a/utilities.c b/utilities.c index baced1b5b..53c2db80f 100644 --- a/utilities.c +++ b/utilities.c @@ -236,7 +236,7 @@ char *iio_strndup(const char *str, size_t n) #ifdef HAS_STRNDUP return strndup(str, n); #else - size_t len = strnlen(str, n + 1); + size_t len = strnlen(str, n); char *buf = malloc(len + 1); if (buf) { /* len = size of buf, so memcpy is OK */ @@ -310,7 +310,7 @@ char * iio_getenv (char * envvar) if (!hostname) return NULL; - tmp = MAXHOSTNAMELEN + sizeof("serial:") + sizeof(":65535") - 2; + tmp = FQDN_LEN + sizeof("serial:") + sizeof(":65535") - 2; len = strnlen(hostname, tmp); /* Should be smaller than max length */