Skip to content

Commit

Permalink
Sync strlcat() implementation
Browse files Browse the repository at this point in the history
Sync with last version made few days after.
  • Loading branch information
devnexen authored and nikic committed Aug 25, 2017
1 parent 3ef8964 commit 24c0a17
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions main/strlcat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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 */
Expand Down

0 comments on commit 24c0a17

Please sign in to comment.