changeset 16853:da29ac12242d

fix broken (off-by-one) behavior of our strl* functions (patch by reimar)
author rfelker
date Tue, 25 Oct 2005 17:13:20 +0000
parents 43b45a561f63
children 3898e1089a29
files osdep/strl.c
diffstat 1 files changed, 5 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/osdep/strl.c	Tue Oct 25 17:08:49 2005 +0000
+++ b/osdep/strl.c	Tue Oct 25 17:13:20 2005 +0000
@@ -11,10 +11,14 @@
 {
 	register unsigned int i;
 
+	if (size > 0) {
+	size--;
 	for (i=0; size > 0 && src[i] != '\0'; ++i, size--)
 		dest[i] = src[i];
 
 	dest[i] = '\0';
+	}
+	while (src[i++]);
 
 	return i;
 }
@@ -23,26 +27,10 @@
 #ifndef HAVE_STRLCAT
 unsigned int strlcat (char *dest, const char *src, unsigned int size)
 {
-#if 0
-	register unsigned int i, j;
-
-	for(i=0; size > 0 && dest[i] != '\0'; size--, i++);
-	for(j=0; size > 0 && src[j] != '\0'; size--, i++, j++)
-		dest[i] = src[j];
-
-	dest[i] = '\0';
-	return i;
-#else
 	register char *d = dest;
-	register const char *s = src;
 
 	for (; size > 0 && *d != '\0'; size--, d++);
-	for (; size > 0 && *s != '\0'; size--, d++, s++)
-		*d = *s;
-
-	*d = '\0';
-	return (d - dest) + (s - src);
-#endif 
+	return (d - dest) + strlcpy(d, src, size);
 }
 #endif