Skip to content

Commit af8c834

Browse files
committed
Fixing strncpy.
1 parent e362aaa commit af8c834

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

libc/include/string.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ static __inline__ char * strncpy(char * s1, const char * s2, size_t n) {
4747
char * r = s1;
4848
char c;
4949
size_t i;
50+
int done = 0;
5051

5152
for (i = 0; i < n; i++) {
52-
if ((c = *s2++)) {
53+
if (!done && (c = *s2++)) {
5354
*s1++ = c;
5455
} else {
5556
*s1++ = 0;
57+
done = 1;
5658
}
5759
}
5860

0 commit comments

Comments
 (0)