tweaks: check for an empty needle in a central place
Searching for an empty string should be impossible, it should never happen, but it is bit too hard to verify this at the moment.master
parent
1a79b3d514
commit
c42d6d378a
16
src/chars.c
16
src/chars.c
|
@ -456,12 +456,7 @@ char *mbstrcasestr(const char *haystack, const char *needle)
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_UTF8
|
#ifdef ENABLE_UTF8
|
||||||
if (use_utf8) {
|
if (use_utf8) {
|
||||||
size_t needle_len;
|
size_t needle_len = mbstrlen(needle);
|
||||||
|
|
||||||
if (*needle == '\0')
|
|
||||||
return (char *)haystack;
|
|
||||||
|
|
||||||
needle_len = mbstrlen(needle);
|
|
||||||
|
|
||||||
while (*haystack != '\0') {
|
while (*haystack != '\0') {
|
||||||
if (mbstrncasecmp(haystack, needle, needle_len) == 0)
|
if (mbstrncasecmp(haystack, needle, needle_len) == 0)
|
||||||
|
@ -484,9 +479,6 @@ char *revstrstr(const char *haystack, const char *needle,
|
||||||
size_t needle_len = strlen(needle);
|
size_t needle_len = strlen(needle);
|
||||||
size_t tail_len = strlen(pointer);
|
size_t tail_len = strlen(pointer);
|
||||||
|
|
||||||
if (needle_len == 0)
|
|
||||||
return (char *)pointer;
|
|
||||||
|
|
||||||
if (tail_len < needle_len)
|
if (tail_len < needle_len)
|
||||||
pointer += tail_len - needle_len;
|
pointer += tail_len - needle_len;
|
||||||
|
|
||||||
|
@ -507,9 +499,6 @@ char *revstrcasestr(const char *haystack, const char *needle,
|
||||||
size_t needle_len = strlen(needle);
|
size_t needle_len = strlen(needle);
|
||||||
size_t tail_len = strlen(pointer);
|
size_t tail_len = strlen(pointer);
|
||||||
|
|
||||||
if (needle_len == 0)
|
|
||||||
return (char *)pointer;
|
|
||||||
|
|
||||||
if (tail_len < needle_len)
|
if (tail_len < needle_len)
|
||||||
pointer += tail_len - needle_len;
|
pointer += tail_len - needle_len;
|
||||||
|
|
||||||
|
@ -532,9 +521,6 @@ char *mbrevstrcasestr(const char *haystack, const char *needle,
|
||||||
size_t needle_len = mbstrlen(needle);
|
size_t needle_len = mbstrlen(needle);
|
||||||
size_t tail_len = mbstrlen(pointer);
|
size_t tail_len = mbstrlen(pointer);
|
||||||
|
|
||||||
if (needle_len == 0)
|
|
||||||
return (char *)pointer;
|
|
||||||
|
|
||||||
if (tail_len < needle_len)
|
if (tail_len < needle_len)
|
||||||
pointer += tail_len - needle_len;
|
pointer += tail_len - needle_len;
|
||||||
|
|
||||||
|
|
|
@ -237,6 +237,10 @@ bool is_separate_word(size_t position, size_t length, const char *buf)
|
||||||
const char *strstrwrapper(const char *haystack, const char *needle,
|
const char *strstrwrapper(const char *haystack, const char *needle,
|
||||||
const char *start)
|
const char *start)
|
||||||
{
|
{
|
||||||
|
/* Just in case we search for an empty needle. :/ */
|
||||||
|
if (*needle == '\0')
|
||||||
|
return (char *)start;
|
||||||
|
|
||||||
if (ISSET(USE_REGEXP)) {
|
if (ISSET(USE_REGEXP)) {
|
||||||
if (ISSET(BACKWARDS_SEARCH)) {
|
if (ISSET(BACKWARDS_SEARCH)) {
|
||||||
size_t last_find, ceiling, far_end;
|
size_t last_find, ceiling, far_end;
|
||||||
|
|
Loading…
Reference in New Issue