diff options
author | 2016-10-16 17:37:39 +0000 | |
---|---|---|
committer | 2016-10-16 17:37:39 +0000 | |
commit | 5cc8e0fffcd2953afeae0870adb6697854383066 (patch) | |
tree | 6bf25cec149a4691b0eadd57259c3179775897bc /lib/libc/string/strlcat.c | |
parent | Strip trailing obj/ from kernel build directories, so kernels (diff) | |
download | wireguard-openbsd-5cc8e0fffcd2953afeae0870adb6697854383066.tar.xz wireguard-openbsd-5cc8e0fffcd2953afeae0870adb6697854383066.zip |
Roll back uintptr_t cast changes after discussions with tedu, otto and
others.
C11 6.5.6.9 says:
When two pointers are subtracted, both shall point to elements of the
same array object, or one past the last element of the array object; the
result is the difference of the subscripts of the two array elements.
In these cases the objects are arrays of char so the result is defined,
and we believe that the report is based on a compiler incorrectly trapping
on defined behaviour.
Diffstat (limited to 'lib/libc/string/strlcat.c')
-rw-r--r-- | lib/libc/string/strlcat.c | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/lib/libc/string/strlcat.c b/lib/libc/string/strlcat.c index 410f448b56a..6bf2a41f799 100644 --- a/lib/libc/string/strlcat.c +++ b/lib/libc/string/strlcat.c @@ -1,4 +1,4 @@ -/* $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, 2015 Todd C. Miller <Todd.Miller@courtesan.com> @@ -18,7 +18,6 @@ #include <sys/types.h> #include <string.h> -#include <stdint.h> /* * Appends src to string dst of size dsize (unlike strncat, dsize is the @@ -38,7 +37,7 @@ strlcat(char *dst, const char *src, size_t dsize) /* 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)odst; + dlen = dst - odst; n = dsize - dlen; if (n-- == 0) @@ -52,11 +51,6 @@ strlcat(char *dst, const char *src, size_t dsize) } *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)osrc)); + return(dlen + (src - osrc)); /* count does not include NUL */ } DEF_WEAK(strlcat); |