#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>
/*
* 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;
/* 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)
}
*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 */