From 49be1f078c467a54d9a61ceea37ab3c43c365975 Mon Sep 17 00:00:00 2001
From: David Carlier <[email protected]>
Date: Tue, 29 Dec 2015 13:21:51 +0000
Subject: [PATCH 5/5] CLEANUP: custom functions: void pointers arithmetic
 removal.

fifth patch which applies to the custom memmem implementation.
---
 src/standard.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/standard.c b/src/standard.c
index 969daf6..9cb12c4 100644
--- a/src/standard.c
+++ b/src/standard.c
@@ -2008,20 +2008,21 @@ char *my_strndup(const char *src, int n)
 const void *my_memmem(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen)
 {
 	const void *c = NULL;
+	unsigned char *pc;
 	unsigned char f;
 
 	if ((haystack == NULL) || (needle == NULL) || (haystacklen < needlelen))
 		return NULL;
 
 	f = *(char *)needle;
-	c = haystack;
-	while ((c = memchr(c, f, haystacklen - (c - haystack))) != NULL) {
-		if ((haystacklen - (c - haystack)) < needlelen)
+	pc = (unsigned char *)haystack;
+	while ((c = memchr(c, f, haystacklen - (pc - (unsigned char *)haystack))) != NULL) {
+		if ((haystacklen - (pc - (unsigned char *)haystack)) < needlelen)
 			return NULL;
 
-		if (memcmp(c, needle, needlelen) == 0)
-			return c;
-		++c;
+		if (memcmp(pc, needle, needlelen) == 0)
+			return (void *)pc;
+		++pc;
 	}
 	return NULL;
 }
-- 
2.5.0

Reply via email to