summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Carlier <devnexen@gmail.com>2017-08-24 06:58:15 +0100
committerNikita Popov <nikita.ppv@gmail.com>2017-08-25 22:12:23 +0200
commit24c0a17d7879c2fe2ff8d368e3e43ad3a818db8e (patch)
tree31c7af14943a1f77be4fa519c58d430d977d5837
parent3ef89649976e1c05c981c3004a12cf3d9e001822 (diff)
downloadphp-git-24c0a17d7879c2fe2ff8d368e3e43ad3a818db8e.tar.gz
Sync strlcat() implementation
Sync with last version made few days after.
-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 */