The klibc strncat doesnt behave like described in the man page.
It doesnt terminate the string if size < strlen(src).
It doesnt make dst longer than size.
#include <string.h>
#include <stdio.h>
int main(void)
{
unsigned char olh[42];
memset(olh, 'A', sizeof(olh));
sprintf(olh, "abc");
fprintf(stderr, "olh: '%s'\n", olh);
bar(olh, "123456789", 7);
fprintf(stderr, "olh: '%s'\n", olh);
return 0;
}
olh: 'abc'
olh: 'abc1234AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
diff --git a/klibc/strncat.c b/klibc/strncat.c
index 0dd9deb..4d8458d 100644
--- a/klibc/strncat.c
+++ b/klibc/strncat.c
@@ -12,14 +12,12 @@
char ch;
size_t nn = q-dst;
- if ( __likely(nn <= n) )
- n -= nn;
-
while (n--) {
*q++ = ch = *p++;
if ( !ch )
- break;
+ return dst;
}
+ *q = '\0';
return dst;
}