Changeset: b70be09e345c for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b70be09e345c Modified Files: monetdb5/modules/mal/pcre.c Branch: Jul2017 Log Message:
Fixed implementation of strcasestr for when the library doesn't provide it. The old implementation had several flaws: if needle is "" it would return NULL instead of haystack; if haystack is "aaab" and needle is "aab" it would return NULL instead of a pointer to the second 'a'. This fixes bug 6547. diffs (35 lines): diff --git a/monetdb5/modules/mal/pcre.c b/monetdb5/modules/mal/pcre.c --- a/monetdb5/modules/mal/pcre.c +++ b/monetdb5/modules/mal/pcre.c @@ -90,24 +90,15 @@ typedef struct RE { static const char * strcasestr(const char *haystack, const char *needle) { - const char *p, *np = 0, *startn = 0; + size_t nlen = strlen(needle); - for (p = haystack; *p; p++) { - if (np) { - if (toupper(*p) == toupper(*np)) { - if (!*++np) - return startn; - } else - np = 0; - } else if (toupper(*p) == toupper(*needle)) { - np = needle + 1; - startn = p; - if (!*np) - return startn; - } + if (nlen == 0) + return haystack; + for (size_t hlen = strlen(haystack); nlen <= hlen; haystack++, hlen--) { + if (strncasecmp(haystack, needle, nlen) == 0) + return haystack; } - - return 0; + return NULL; } #endif _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list