chiark / gitweb /
[PATCH] klibc: strlcpy/strlcat - don't alter destination if size == 0
[elogind.git] / klibc / klibc / strlcat.c
index 6111445f0629948c738ecd91b2cd2fe54a86c5db..fdd72ac392c5b910f19c5e66ecc6227f1577e41a 100644 (file)
@@ -16,15 +16,18 @@ size_t strlcat(char *dst, const char *src, size_t size)
     q++;
     bytes++;
   }
     q++;
     bytes++;
   }
+  if (bytes == size)
+    return (bytes + strlen(src));
 
   while ( (ch = *p++) ) {
 
   while ( (ch = *p++) ) {
-    if ( bytes < size )
+    if ( bytes+1 < size )
       *q++ = ch;
 
     bytes++;
   }
 
       *q++ = ch;
 
     bytes++;
   }
 
-  *q = '\0';
+  if (size)
+    *q = '\0';
   return bytes;
 }
 
   return bytes;
 }