]> granicus.if.org Git - php/commitdiff
Sync strlcat() implementation
authorDavid Carlier <devnexen@gmail.com>
Thu, 24 Aug 2017 05:58:15 +0000 (06:58 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 25 Aug 2017 20:12:23 +0000 (22:12 +0200)
Sync with last version made few days after.

main/strlcat.c

index d3c8972d68d0339a7bf21948312e38cffd825e73..c87f3fdd41b72812e8f69d3fe955dca12d0979f4 100644 (file)
@@ -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 */