Преглед на файлове

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.
Quentin Rameau преди 6 години
родител
ревизия
d9bdfd1644
променени са 1 файла, в които са добавени 1 реда и са изтрити 1 реда
  1. 1 1
      src/string/memccpy.c

+ 1 - 1
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;
 }