Fixed a bug in strlcat() where it would not properly detect a no-change
authorWayne Davison <wayned@samba.org>
Tue, 20 Jan 2004 00:29:49 +0000 (00:29 +0000)
committerWayne Davison <wayned@samba.org>
Tue, 20 Jan 2004 00:29:49 +0000 (00:29 +0000)
condition if called with an initial string longer than the specified
size limit (due to an unsigned var's inability to go negative).

lib/compat.c

index a783a01..6dd2328 100644 (file)
        size_t len2 = strlen(s);
        size_t ret = len1 + len2;
 
-       if (len1+len2 >= bufsize) {
-               len2 = bufsize - (len1+1);
-       }
-       if (len2 > 0) {
+       if (len1 < bufsize - 1) {
+               if (len2 >= bufsize - len1)
+                       len2 = bufsize - len1 - 1;
                memcpy(d+len1, s, len2);
                d[len1+len2] = 0;
        }