From e59345cc9499a4ca7e5bb66579e50af7dc841425 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 16 Nov 2021 21:29:16 -0500 Subject: [PATCH] common: fix compilation when strnlen, strnup and memrchr are not available MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add a few casts to fix build failure when these functions are not available. For example: CXX lttng-conf.o In file included from /home/smarchi/src/lttng-tools/src/common/macros.h:15:0, from /home/smarchi/src/lttng-tools/src/common/error.h:19, from /home/smarchi/src/lttng-tools/src/common/common.h:12, from /home/smarchi/src/lttng-tools/src/bin/lttng/conf.cpp:18: /home/smarchi/src/lttng-tools/src/common/compat/string.h: In function ‘size_t lttng_strnlen(const char*, size_t)’: /home/smarchi/src/lttng-tools/src/common/compat/string.h:28:14: error: invalid conversion from ‘const void*’ to ‘const char*’ [-fpermissive] end = memchr(str, 0, max); ~~~~~~^~~~~~~~~~~~~ This can be tested by modifying config.cache and setting the relevant config variables to "no". Change-Id: Ieb6debf32c82927767ad32d2f4aa62fb829a9f9f Signed-off-by: Simon Marchi Signed-off-by: Jérémie Galarneau --- src/common/compat/string.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/compat/string.h b/src/common/compat/string.h index c9aa7f7fa..fd4f2f021 100644 --- a/src/common/compat/string.h +++ b/src/common/compat/string.h @@ -25,7 +25,7 @@ size_t lttng_strnlen(const char *str, size_t max) size_t ret; const char *end; - end = memchr(str, 0, max); + end = (const char *) memchr(str, 0, max); if (end) { ret = (size_t) (end - str); @@ -61,7 +61,7 @@ char *lttng_strndup(const char *s, size_t n) navail = n + 1; } - ret = malloc(navail); + ret = (char *) malloc(navail); if (!ret) { goto end; } @@ -120,7 +120,7 @@ static inline void *lttng_memrchr(const void *s, int c, size_t n) { int i; - const char *str = s; + const char *str = (const char *) s; for (i = n-1; i >= 0; i--) { if (str[i] == (char)c) { return (void *)(str+i); -- 2.34.1