From 1acc763f8abc805a5a68ff035a1f538b0d6ccf65 Mon Sep 17 00:00:00 2001 From: dtucker <> Date: Sun, 16 Oct 2016 17:37:39 +0000 Subject: 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. --- src/lib/libc/string/strnlen.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'src/lib/libc/string/strnlen.c') 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 @@ -/* $OpenBSD: strnlen.c,v 1.7 2016/10/14 18:19:04 dtucker Exp $ */ +/* $OpenBSD: strnlen.c,v 1.8 2016/10/16 17:37:39 dtucker Exp $ */ /* * Copyright (c) 2010 Todd C. Miller @@ -19,7 +19,6 @@ #include #include -#include size_t strnlen(const char *str, size_t maxlen) @@ -29,10 +28,6 @@ strnlen(const char *str, size_t maxlen) for (cp = str; maxlen != 0 && *cp != '\0'; cp++, maxlen--) ; - /* - * Cast pointers to unsigned type before calculation, to avoid signed - * overflow when the string ends where the MSB has changed. - */ - return (size_t)((uintptr_t)cp - (uintptr_t)str); + return (size_t)(cp - str); } DEF_WEAK(strnlen); -- cgit v1.2.3-55-g6feb