From d9bdfd1644320ab916ea31d95da4bf641042209a Mon Sep 17 00:00:00 2001
From: Quentin Rameau <quinq@fifth.space>
Date: Sun, 11 Nov 2018 09:25:26 +0100
Subject: [PATCH] fix memccpy to not access buffer past given size

memccpy would return a pointer over the given size when c is not
found in the source buffer and n reaches 0.
---
 src/string/memccpy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/string/memccpy.c b/src/string/memccpy.c
index f515581c..00c18e2b 100644
--- a/src/string/memccpy.c
+++ b/src/string/memccpy.c
@@ -29,6 +29,6 @@ void *memccpy(void *restrict dest, const void *restrict src, int c, size_t n)
 #endif
 	for (; n && (*d=*s)!=c; n--, s++, d++);
 tail:
-	if (*s==c) return d+1;
+	if (n && *s==c) return d+1;
 	return 0;
 }
-- 
2.40.0