From 9278b9af41150f106ab8460854f789977c247527 Mon Sep 17 00:00:00 2001 From: Doug Evans Date: Fri, 4 Oct 2024 15:42:21 -0700 Subject: [PATCH] i#2522 strcasestr prototype error: Remove `const` from result type The definition of strcasestr is char *strcasestr(const char *text, const char *pattern); but drmemory uses const char *strcasestr(const char *text, const char *pattern); This causes build errors when both /usr/include/string.h and common/utils.h are included in linux. The definition for strcasestr for C has always not had the `const` in the result type (going back to its original addition to glibc in 1997). Thus we're pretty safe in not breaking anything on *nix. The other main use case of drmemory's strcasestr is on Windows, which does not have strcasestr. Tested: $ cmake && make Fixes #2522 --- common/utils.h | 2 +- common/utils_shared.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/utils.h b/common/utils.h index 040d093d..edcea35c 100644 --- a/common/utils.h +++ b/common/utils.h @@ -1011,7 +1011,7 @@ drmem_strndup(const char *src, size_t max, heapstat_t type); #define MAX_OPTION_LEN DR_MAX_OPTIONS_LENGTH #if !defined(MACOS) && !defined(ANDROID) && !defined(NOLINK_STRCASESTR) -const char * +char * strcasestr(const char *text, const char *pattern); #endif diff --git a/common/utils_shared.c b/common/utils_shared.c index 8cfca94a..7e93327b 100755 --- a/common/utils_shared.c +++ b/common/utils_shared.c @@ -51,7 +51,7 @@ strnchr(const char *str, int find, size_t max) * want a libc dependence. */ #if !defined(MACOS) && !defined(ANDROID) && !defined(NOLINK_STRCASESTR) -const char * +char * strcasestr(const char *text, const char *pattern) { const char *cur_text, *cur_pattern, *root; @@ -60,7 +60,7 @@ strcasestr(const char *text, const char *pattern) cur_pattern = pattern; while (true) { if (*cur_pattern == '\0') - return root; + return (char *) root; if (*cur_text == '\0') return NULL; /* XXX DRi#943: toupper is better, for int18n, and we need to call