SashaXser
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
6 additions and
8 deletions
-
src/goodbyedpi.c
|
|
@ -238,15 +238,13 @@ static char* dumb_memmem(const char* haystack, unsigned int hlen, |
|
|
|
if (nlen > hlen) return NULL; |
|
|
|
if (nlen == 0) return (char*)haystack; |
|
|
|
|
|
|
|
for (unsigned int i = 0; i <= hlen - nlen; i++) { |
|
|
|
for (unsigned int j = 0; j < nlen; j++) { |
|
|
|
if (haystack[i + j] != needle[j]) { |
|
|
|
break; |
|
|
|
} |
|
|
|
unsigned int skip[256]; |
|
|
|
for (size_t i = 0; i < 256; ++i) skip[i] = nlen; |
|
|
|
for (size_t i = 0; i < nlen - 1; ++i) skip[(unsigned char)needle[i]] = nlen - i - 1; |
|
|
|
|
|
|
|
if (j == nlen - 1) { |
|
|
|
return (char*)(haystack + i); |
|
|
|
} |
|
|
|
for (size_t i = nlen - 1; i < hlen; i += skip[(unsigned char)haystack[i]]) { |
|
|
|
if (memcmp(haystack + i - nlen + 1, needle, nlen) == 0) { |
|
|
|
return (char*)(haystack + i - nlen + 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|