From b80f554fd982b65bd3b45bb151655abe634e938b Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Thu, 26 Feb 2026 15:48:43 +0100 Subject: [PATCH] helper/log: Fix build issue on MSYS2 and Cygwin On MSYS2 (native) and Cygwin, the mallinfo struct uses 'size_t' instead of 'int', which leads to a compile-time error with the current code. Update the preprocessor logic so that Cygwin and MSYS2 builds use the 'size_t' format specifier. Checkpatch-ignore: COMMIT_LOG_LONG_LINE Build error on MSYS2: ../src/helper/log.c: In function 'get_free_memory_space': ../src/helper/log.c:78:45: error: format '%d' expects argument of type 'int', but argument 4 has type 'size_t' {aka 'long unsigned int'} [-Werror=format=] 78 | snprintf(s, MEM_STR_LEN, " %d", info.fordblks); | ~^ ~~~~~~~~~~~~~ | | | | int size_t {aka long unsigned int} | %ld Change-Id: I18d772facba6426ab627fb45a6d50bfc19ec9c05 Signed-off-by: Marc Schink Reviewed-on: https://review.openocd.org/c/openocd/+/9479 Reviewed-by: Antonio Borneo Tested-by: jenkins --- src/helper/log.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/helper/log.c b/src/helper/log.c index afba0d172..ce21a907d 100644 --- a/src/helper/log.c +++ b/src/helper/log.c @@ -75,7 +75,11 @@ static void get_free_memory_space(char *s) #elif defined(HAVE_MALLINFO) if (LOG_LEVEL_IS(LOG_LVL_DEBUG_MALLOC)) { struct mallinfo info = mallinfo(); +#if IS_CYGWIN + snprintf(s, MEM_STR_LEN, " %zu", info.fordblks); +#else snprintf(s, MEM_STR_LEN, " %d", info.fordblks); +#endif return; } #endif