diff options
author | dtucker <> | 2016-10-16 17:37:39 +0000 |
---|---|---|
committer | dtucker <> | 2016-10-16 17:37:39 +0000 |
commit | 1acc763f8abc805a5a68ff035a1f538b0d6ccf65 (patch) | |
tree | 9802b0cedab21e98c8a7def7761445293fbcba80 | |
parent | a5593cbfdf09c39fb89451e83f00de99d806660f (diff) | |
download | openbsd-1acc763f8abc805a5a68ff035a1f538b0d6ccf65.tar.gz openbsd-1acc763f8abc805a5a68ff035a1f538b0d6ccf65.tar.bz2 openbsd-1acc763f8abc805a5a68ff035a1f538b0d6ccf65.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.
-rw-r--r-- | src/lib/libc/string/strlcat.c | 12 | ||||
-rw-r--r-- | src/lib/libc/string/strlcpy.c | 10 | ||||
-rw-r--r-- | src/lib/libc/string/strnlen.c | 9 |
3 files changed, 7 insertions, 24 deletions
diff --git a/src/lib/libc/string/strlcat.c b/src/lib/libc/string/strlcat.c index 410f448b56..6bf2a41f79 100644 --- a/src/lib/libc/string/strlcat.c +++ b/src/lib/libc/string/strlcat.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: strlcat.c,v 1.17 2016/10/14 18:19:04 dtucker Exp $ */ | 1 | /* $OpenBSD: strlcat.c,v 1.18 2016/10/16 17:37:39 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com> | 4 | * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com> |
@@ -18,7 +18,6 @@ | |||
18 | 18 | ||
19 | #include <sys/types.h> | 19 | #include <sys/types.h> |
20 | #include <string.h> | 20 | #include <string.h> |
21 | #include <stdint.h> | ||
22 | 21 | ||
23 | /* | 22 | /* |
24 | * Appends src to string dst of size dsize (unlike strncat, dsize is the | 23 | * 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) | |||
38 | /* Find the end of dst and adjust bytes left but don't go past end. */ | 37 | /* Find the end of dst and adjust bytes left but don't go past end. */ |
39 | while (n-- != 0 && *dst != '\0') | 38 | while (n-- != 0 && *dst != '\0') |
40 | dst++; | 39 | dst++; |
41 | dlen = (uintptr_t)dst - (uintptr_t)odst; | 40 | dlen = dst - odst; |
42 | n = dsize - dlen; | 41 | n = dsize - dlen; |
43 | 42 | ||
44 | if (n-- == 0) | 43 | if (n-- == 0) |
@@ -52,11 +51,6 @@ strlcat(char *dst, const char *src, size_t dsize) | |||
52 | } | 51 | } |
53 | *dst = '\0'; | 52 | *dst = '\0'; |
54 | 53 | ||
55 | /* | 54 | return(dlen + (src - osrc)); /* count does not include NUL */ |
56 | * Cast pointers to unsigned type before calculation, to avoid signed | ||
57 | * overflow when the string ends where the MSB has changed. | ||
58 | * Return value does not include NUL. | ||
59 | */ | ||
60 | return (dlen + ((uintptr_t)src - (uintptr_t)osrc)); | ||
61 | } | 55 | } |
62 | DEF_WEAK(strlcat); | 56 | DEF_WEAK(strlcat); |
diff --git a/src/lib/libc/string/strlcpy.c b/src/lib/libc/string/strlcpy.c index f282834680..367768928d 100644 --- a/src/lib/libc/string/strlcpy.c +++ b/src/lib/libc/string/strlcpy.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: strlcpy.c,v 1.14 2016/10/14 18:19:04 dtucker Exp $ */ | 1 | /* $OpenBSD: strlcpy.c,v 1.15 2016/10/16 17:37:39 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com> | 4 | * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com> |
@@ -18,7 +18,6 @@ | |||
18 | 18 | ||
19 | #include <sys/types.h> | 19 | #include <sys/types.h> |
20 | #include <string.h> | 20 | #include <string.h> |
21 | #include <stdint.h> | ||
22 | 21 | ||
23 | /* | 22 | /* |
24 | * Copy string src to buffer dst of size dsize. At most dsize-1 | 23 | * Copy string src to buffer dst of size dsize. At most dsize-1 |
@@ -47,11 +46,6 @@ strlcpy(char *dst, const char *src, size_t dsize) | |||
47 | ; | 46 | ; |
48 | } | 47 | } |
49 | 48 | ||
50 | /* | 49 | return(src - osrc - 1); /* count does not include NUL */ |
51 | * Cast pointers to unsigned type before calculation, to avoid signed | ||
52 | * overflow when the string ends where the MSB has changed. | ||
53 | * Return value does not include NUL. | ||
54 | */ | ||
55 | return((uintptr_t)src - (uintptr_t)osrc - 1); | ||
56 | } | 50 | } |
57 | DEF_WEAK(strlcpy); | 51 | DEF_WEAK(strlcpy); |
diff --git a/src/lib/libc/string/strnlen.c b/src/lib/libc/string/strnlen.c index 33c3b6e2ca..db809756ac 100644 --- a/src/lib/libc/string/strnlen.c +++ b/src/lib/libc/string/strnlen.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: strnlen.c,v 1.7 2016/10/14 18:19:04 dtucker Exp $ */ | 1 | /* $OpenBSD: strnlen.c,v 1.8 2016/10/16 17:37:39 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com> | 4 | * Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com> |
@@ -19,7 +19,6 @@ | |||
19 | #include <sys/types.h> | 19 | #include <sys/types.h> |
20 | 20 | ||
21 | #include <string.h> | 21 | #include <string.h> |
22 | #include <stdint.h> | ||
23 | 22 | ||
24 | size_t | 23 | size_t |
25 | strnlen(const char *str, size_t maxlen) | 24 | strnlen(const char *str, size_t maxlen) |
@@ -29,10 +28,6 @@ strnlen(const char *str, size_t maxlen) | |||
29 | for (cp = str; maxlen != 0 && *cp != '\0'; cp++, maxlen--) | 28 | for (cp = str; maxlen != 0 && *cp != '\0'; cp++, maxlen--) |
30 | ; | 29 | ; |
31 | 30 | ||
32 | /* | 31 | return (size_t)(cp - str); |
33 | * Cast pointers to unsigned type before calculation, to avoid signed | ||
34 | * overflow when the string ends where the MSB has changed. | ||
35 | */ | ||
36 | return (size_t)((uintptr_t)cp - (uintptr_t)str); | ||
37 | } | 32 | } |
38 | DEF_WEAK(strnlen); | 33 | DEF_WEAK(strnlen); |