From 1fb8ec4b0d871f44eeb025b2ea2a1fbfa961234b Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Tue, 20 Jan 2004 00:29:49 +0000 Subject: [PATCH] Fixed a bug in strlcat() where it would not properly detect a no-change 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 | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/compat.c b/lib/compat.c index a783a01c..6dd2328a 100644 --- a/lib/compat.c +++ b/lib/compat.c @@ -138,10 +138,9 @@ 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; } -- 2.34.1