From 87fbce804ca66be1874a44b31a7a96ddc8b49166 Mon Sep 17 00:00:00 2001 From: n-a-c-h Date: Tue, 20 May 2008 01:54:20 +0000 Subject: [PATCH] Fix handling of one case, should be a good memmem() now. git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@517 a31d4220-a93d-0410-bf67-fe4944624d44 --- src/win32/protect.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/win32/protect.c b/src/win32/protect.c index 0e026903..18a412bf 100644 --- a/src/win32/protect.c +++ b/src/win32/protect.c @@ -8,18 +8,25 @@ static uint8_t *memmem(const uint8_t *haystack, size_t haystacklen, const uint8_t *needle, size_t needlelen) { - if (needlelen <= haystacklen) + if (needlelen) { - haystacklen -= needlelen-1; - while (haystacklen--) + if (needlelen <= haystacklen) { - if (!memcmp(haystack, needle, needlelen)) + haystacklen -= needlelen-1; + while (haystacklen--) { - return((uint8_t *)haystack); + if (!memcmp(haystack, needle, needlelen)) + { + return((uint8_t *)haystack); + } + ++haystack; } - ++haystack; } } + else + { + return((uint8_t *)haystack); + } return(0); }