Skip to content

Commit

Permalink
i#2522 strcasestr prototype error: Remove const from result type
Browse files Browse the repository at this point in the history
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
  • Loading branch information
xdje42 committed Oct 4, 2024
1 parent 384f6aa commit 9278b9a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions common/utils_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 9278b9a

Please sign in to comment.