summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main/strlcat.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/main/strlcat.c b/main/strlcat.c
index d3c8972d68..c87f3fdd41 100644
--- a/main/strlcat.c
+++ b/main/strlcat.c
@@ -22,7 +22,7 @@
#ifdef USE_STRLCAT_PHP_IMPL
-/* $OpenBSD: strlcat.c,v 1.17 2016/10/14 18:19:04 dtucker Exp $ */
+/* $OpenBSD: strlcat.c,v 1.18 2016/10/16 17:37:39 dtucker Exp $ */
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -61,8 +61,9 @@ static char *rcsid = "$OpenBSD: strlcat.c,v 1.17 2016/10/14 18:19:04 dtucker Exp
/*
* Appends src to string dst of size siz (unlike strncat, siz is the
* full size of dst, not space left). At most siz-1 characters
- * will be copied. Always NUL terminates (unless siz == 0).
- * Returns strlen(src); if retval >= siz, truncation occurred.
+ * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
+ * Returns strlen(src) + MIN(siz, strlen(initial dst).
+ * If retval >= siz, truncation occurred.
*/
PHPAPI size_t php_strlcat(dst, src, siz)
char *dst;
@@ -77,7 +78,7 @@ PHPAPI size_t php_strlcat(dst, src, siz)
/* Find the end of dst and adjust bytes left but don't go past end */
while (n-- != 0 && *dst != '\0')
dst++;
- dlen = (uintptr_t)dst - (uintptr_t)d;
+ dlen = dst - d;
n = siz - dlen;
if (n-- == 0)
@@ -91,12 +92,7 @@ PHPAPI size_t php_strlcat(dst, src, siz)
}
*dst = '\0';
- /*
- * Cast pointers to unsigned type before calculation, to avoid signed
- * overflow when the string ends where the MSB has changed.
- * Return value does not include NUL.
- */
- return(dlen + ((uintptr_t)src - (uintptr_t)s));
+ return(dlen + (src - s));
}
#endif /* !HAVE_STRLCAT */