From 8698d5b8f0d80aad5580ea815aa1e4bd7df2f54d Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Tue, 5 Dec 2023 12:47:59 +0100 Subject: [PATCH 01/12] CMake: Build everything with -Werror When COMPILE_WARNING_AS_ERROR is set, compile everything with -Werror and not just Libiio. Signed-off-by: Paul Cercueil --- CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f57a5fbd..29f6ccc8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -305,7 +305,7 @@ if (MSVC) # Azure Pipelines: TF_BUILD=True if(COMPILE_WARNING_AS_ERROR) message(STATUS "Setting -Werror") - target_compile_options(iio PRIVATE /WX) + target_compile_options(iio PUBLIC /WX) endif() elseif (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") option(WITH_GCOV "Build with gcov profiling flags" OFF) @@ -318,7 +318,7 @@ elseif (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") endif() if(COMPILE_WARNING_AS_ERROR) message(STATUS "Setting -Werror") - target_compile_options(iio PRIVATE -Werror) + target_compile_options(iio PUBLIC -Werror) endif() else() message(STATUS "Unknown compiler ${CMAKE_C_COMPILER_ID}") @@ -602,6 +602,9 @@ if (IIOD_CLIENT OR WITH_IIOD) # Link against exported symbols of Libiio and not the # DLL-exported symbols target_compile_definitions(iiod-responder PRIVATE LIBIIO_STATIC) + + # Use the same compile options as Libiio + target_compile_options(iiod-responder PUBLIC $) endif() if (IIOD_CLIENT) From f73a1340a7a8842c97bd78c39486c86c4f72b146 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Tue, 5 Dec 2023 15:26:52 +0100 Subject: [PATCH 02/12] iiod: Fix invalid print format time_t is implementation defined, and therefore there is no printf format specifier that is guaranteed to work on every platform. Address this issue by using %ld and casting the value to long. Signed-off-by: Paul Cercueil --- iiod/dns-sd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iiod/dns-sd.c b/iiod/dns-sd.c index 44521a481..465907fe7 100644 --- a/iiod/dns-sd.c +++ b/iiod/dns-sd.c @@ -320,7 +320,8 @@ static void start_avahi_thd(struct thread_pool *pool, void *d) if (avahi.client) break; again: - IIO_INFO("Avahi didn't start, try again in %d seconds later\n", ts.tv_sec); + IIO_INFO("Avahi didn't start, try again in %ld seconds later\n", + (long)ts.tv_sec); nanosleep(&ts, NULL); ts.tv_sec++; /* If it hasn't started in 20 times over 210 seconds (3.5 min), From 07969fe785bc61053a2408068e5251c797789a24 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Mon, 11 Dec 2023 12:22:02 +0100 Subject: [PATCH 03/12] iiod: Fix forward declaration of yylex() Specify the arguments to the yylex() function in its forward prototype, as old-style prototypes that don't specify the number of arguments are deprecated in C. Signed-off-by: Paul Cercueil --- iiod/parser.y | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iiod/parser.y b/iiod/parser.y index ccd60968d..5b1c2bda0 100644 --- a/iiod/parser.y +++ b/iiod/parser.y @@ -28,7 +28,9 @@ typedef void *yyscan_t; #include #include -int yylex(); +union YYSTYPE; + +int yylex(union YYSTYPE *type, yyscan_t scanner); int yylex_init_extra(void *d, yyscan_t *scanner); int yylex_destroy(yyscan_t yyscanner); From 0bc984eab12a7a3197bec1d871c6f4fc3ab4d4ea Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Mon, 11 Dec 2023 12:42:34 +0100 Subject: [PATCH 04/12] iiod-responder: Use int32_t instead of intptr_t for return codes The return codes are stored within the "struct iiod_command" as a int32_t, there is no point to use a intptr_t in the public API. Signed-off-by: Paul Cercueil --- iiod-responder.c | 6 +++--- iiod-responder.h | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/iiod-responder.c b/iiod-responder.c index e571ae51b..37c5b9e28 100644 --- a/iiod-responder.c +++ b/iiod-responder.c @@ -461,7 +461,7 @@ static int iiod_io_cond_wait(const struct iiod_io *io) return -ETIMEDOUT; } -intptr_t iiod_io_wait_for_response(struct iiod_io *io) +int32_t iiod_io_wait_for_response(struct iiod_io *io) { struct iiod_responder *priv = io->responder; int ret = 0; @@ -509,13 +509,13 @@ int iiod_io_send_command(struct iiod_io *io, return iiod_io_wait_for_command_done(io); } -int iiod_io_send_response_async(struct iiod_io *io, intptr_t code, +int iiod_io_send_response_async(struct iiod_io *io, int32_t code, const struct iiod_buf *buf, size_t nb) { return iiod_enqueue_command(io, IIOD_OP_RESPONSE, 0, code, buf, nb); } -int iiod_io_send_response(struct iiod_io *io, intptr_t code, +int iiod_io_send_response(struct iiod_io *io, int32_t code, const struct iiod_buf *buf, size_t nb) { int ret; diff --git a/iiod-responder.h b/iiod-responder.h index 42c8c1221..70cca5d37 100644 --- a/iiod-responder.h +++ b/iiod-responder.h @@ -126,7 +126,7 @@ int iiod_command_data_read(struct iiod_command_data *data, int iiod_io_send_command(struct iiod_io *io, const struct iiod_command *cmd, const struct iiod_buf *buf, size_t nb); -int iiod_io_send_response(struct iiod_io *io, intptr_t code, +int iiod_io_send_response(struct iiod_io *io, int32_t code, const struct iiod_buf *buf, size_t nb); /* Send command, then read the response. */ @@ -148,7 +148,7 @@ iiod_io_exec_simple_command(struct iiod_io *io, int iiod_io_send_command_async(struct iiod_io *io, const struct iiod_command *cmd, const struct iiod_buf *buf, size_t nb); -int iiod_io_send_response_async(struct iiod_io *io, intptr_t code, +int iiod_io_send_response_async(struct iiod_io *io, int32_t code, const struct iiod_buf *buf, size_t nb); /* Wait for an async. command or response to be done sending */ @@ -158,7 +158,7 @@ _Bool iiod_io_command_is_done(struct iiod_io *io); /* Simplified version of iiod_io_send_response, to just send a code. */ static inline int -iiod_io_send_response_code(struct iiod_io *io, intptr_t code) +iiod_io_send_response_code(struct iiod_io *io, int32_t code) { return iiod_io_send_response(io, code, NULL, 0); } @@ -168,7 +168,7 @@ int iiod_io_get_response_async(struct iiod_io *io, const struct iiod_buf *buf, size_t nb); /* Wait for iiod_io_get_response_async to be done. */ -intptr_t iiod_io_wait_for_response(struct iiod_io *io); +int32_t iiod_io_wait_for_response(struct iiod_io *io); _Bool iiod_io_has_response(struct iiod_io *io); From a78b9c2fe5e6bcc3eb0adf61bf59764bc28d867c Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Mon, 11 Dec 2023 12:44:14 +0100 Subject: [PATCH 05/12] iiod-responder: Use explicit uint64_t -> unsigned int cast We compute a difference between two 64-bit values, and given that the result corresponds to a timeout value in milliseconds, we can guarantee that it will fit in 32-bits. Use an explicit downcast to unsigned int to tell the compiler that we know it's okay. Signed-off-by: Paul Cercueil --- iiod-responder.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iiod-responder.c b/iiod-responder.c index 37c5b9e28..5f535900f 100644 --- a/iiod-responder.c +++ b/iiod-responder.c @@ -455,8 +455,10 @@ static int iiod_io_cond_wait(const struct iiod_io *io) diff_ms = (read_counter_us() - io->r_io.start_time) / 1000; - if (diff_ms < timeout_ms) - return iio_cond_wait(io->cond, io->lock, timeout_ms - diff_ms); + if (diff_ms < timeout_ms) { + return iio_cond_wait(io->cond, io->lock, + (unsigned int)(timeout_ms - diff_ms)); + } return -ETIMEDOUT; } From a661f3352a9423c711fe05b7565cd2f3475b3483 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Mon, 11 Dec 2023 12:54:20 +0100 Subject: [PATCH 06/12] utils: iio_common: Avoid signed/unsigned comparisons Set argc parameter to dup_argv/free_argw as unsigned int, to avoid signed/unsigned comparisons. Signed-off-by: Paul Cercueil --- utils/iio_common.c | 4 ++-- utils/iio_common.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/utils/iio_common.c b/utils/iio_common.c index bcaae5055..2df1eed90 100644 --- a/utils/iio_common.c +++ b/utils/iio_common.c @@ -150,7 +150,7 @@ unsigned long int sanitize_clamp(const char *name, const char *argv, return (unsigned long int) val; } -char ** dup_argv(char * name, int argc, char * argv[]) +char ** dup_argv(char * name, unsigned int argc, char * argv[]) { unsigned int i; char** new_argv; @@ -179,7 +179,7 @@ char ** dup_argv(char * name, int argc, char * argv[]) exit(0); } -void free_argw(int argc, char * argw[]) +void free_argw(unsigned int argc, char * argw[]) { unsigned int i; diff --git a/utils/iio_common.h b/utils/iio_common.h index 26fc3a73d..f6964b82e 100644 --- a/utils/iio_common.h +++ b/utils/iio_common.h @@ -57,8 +57,8 @@ struct option * add_common_options(const struct option * longopts); void usage(char *name, const struct option *options, const char *options_descriptions[]); void version(char *name); -char ** dup_argv(char * name, int argc, char * argv[]); -void free_argw(int argc, char * argw[]); +char ** dup_argv(char * name, unsigned int argc, char * argv[]); +void free_argw(unsigned int argc, char * argw[]); uint64_t get_time_us(void); From d853b31eb802939da1bbfabc9e391b291db63dc9 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Tue, 5 Dec 2023 15:04:49 +0100 Subject: [PATCH 07/12] utils: iio_event: Fix invalid print format Use PRId64 from to print the int64_t value. Signed-off-by: Paul Cercueil --- utils/iio_event.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/iio_event.c b/utils/iio_event.c index 0001f9d26..cb609a90c 100644 --- a/utils/iio_event.c +++ b/utils/iio_event.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -63,7 +64,7 @@ static void print_event(const struct iio_device *dev, enum iio_event_type type = iio_event_get_type(event); enum iio_event_direction dir = iio_event_get_direction(event); - printf("Event: time: %lld", event->timestamp); + printf("Event: time: %"PRId64, event->timestamp); /* Flawfinder: ignore */ chn = iio_event_get_channel(event, dev, false); if (chn) From f1579eac49768bb7563fbe0fedabcce69c92c670 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Mon, 11 Dec 2023 13:12:07 +0100 Subject: [PATCH 08/12] utils: iio_event: Remove unused goto label Signed-off-by: Paul Cercueil --- utils/iio_event.c | 1 - 1 file changed, 1 deletion(-) diff --git a/utils/iio_event.c b/utils/iio_event.c index cb609a90c..6a924cc42 100644 --- a/utils/iio_event.c +++ b/utils/iio_event.c @@ -176,7 +176,6 @@ int main(int argc, char **argv) out_ctx_destroy: if (ctx) iio_context_destroy(ctx); -out_free_argw: free_argw(argc, argw); return ret; } From deef74e617e07c97618b9fb7f9d43e0a6a5902a9 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Mon, 11 Dec 2023 13:12:30 +0100 Subject: [PATCH 09/12] utils: iio_genxml: Remove unused local variable Signed-off-by: Paul Cercueil --- utils/iio_genxml.c | 1 - 1 file changed, 1 deletion(-) diff --git a/utils/iio_genxml.c b/utils/iio_genxml.c index 53bc8da90..9f2aaa796 100644 --- a/utils/iio_genxml.c +++ b/utils/iio_genxml.c @@ -34,7 +34,6 @@ int main(int argc, char **argv) char **argw, *uri; const char *xml; struct iio_context *ctx; - size_t xml_len; struct option *opts; size_t buf_len; int c, ret = EXIT_FAILURE; From 06da950afbc2b4c40063b13b32f15c1f648df610 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Mon, 11 Dec 2023 13:10:56 +0100 Subject: [PATCH 10/12] utils: iio_info: Work around MSVC not handling error codes MSVC does not support escape sequences and will complain if it finds some, even when those are actually dead code. Signed-off-by: Paul Cercueil --- utils/iio_info.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/utils/iio_info.c b/utils/iio_info.c index c5348ce52..04dd75106 100644 --- a/utils/iio_info.c +++ b/utils/iio_info.c @@ -60,10 +60,19 @@ static int dev_is_buffer_capable(const struct iio_device *dev) static bool colors; +#ifndef _MSC_BUILD #define FMT_ERR "\e[1;31mERROR: %s\e[0m" #define FMT_DEV "\e[1;32m%s\e[0m" #define FMT_CHN "\e[0;33m%s\e[0m" #define FMT_ATTR "\e[1;34m%s\e[0m" +#else +/* MSVC doesn't like escape codes. But those will never be used anyway, + * as color support is disabled when building with MSVC. */ +#define FMT_ERR "%s" +#define FMT_DEV "%s" +#define FMT_CHN "%s" +#define FMT_ATTR "%s" +#endif /* Keeps Codacy happy */ #define print_fmt(fmt, ...) printf(fmt, __VA_ARGS__) /* Flawfinder: ignore */ From 4fb278367bbb4df80f7db025f75b7d80c5c210e0 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Mon, 11 Dec 2023 13:22:55 +0100 Subject: [PATCH 11/12] utils: iio_info: Explicitely cast error codes to int iio_strerror() expects an "int" value for the error code. Visual Studio will complain if we are passing a ssize_t, as it is a downcast. However, we know that error codes all fit in "int", so the downcast is safe. Signed-off-by: Paul Cercueil --- utils/iio_info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/iio_info.c b/utils/iio_info.c index 04dd75106..4f44fa374 100644 --- a/utils/iio_info.c +++ b/utils/iio_info.c @@ -90,7 +90,7 @@ static void print_attr(const struct iio_attr *attr, if (!value) { ret = iio_attr_read_raw(attr, buf, sizeof(buf) - 1); if (ret < 0) - iio_strerror(ret, buf, sizeof(buf)); + iio_strerror((int)ret, buf, sizeof(buf)); value = buf; } From 9e274d36256fe2efe8aad68d5dd3cfb09c943f53 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Mon, 11 Dec 2023 13:34:30 +0100 Subject: [PATCH 12/12] utils: iio_info: Remove unused local variables Signed-off-by: Paul Cercueil --- utils/iio_info.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/iio_info.c b/utils/iio_info.c index 4f44fa374..e80148d4a 100644 --- a/utils/iio_info.c +++ b/utils/iio_info.c @@ -170,10 +170,10 @@ static void print_channel(const struct iio_channel *chn) int main(int argc, char **argv) { - char **argw, *buf; + char **argw; const struct iio_device *dev, *trig; const struct iio_channel *ch; - const char *key, *value, *name, *label, *type_name; + const char *name, *label; unsigned int i, j, k, nb_devices, nb_channels, nb_ctx_attrs, nb_attrs; struct iio_channels_mask *mask; const struct iio_attr *attr;