fortify-headers

standalone fortify-source implementation
git clone git://git.2f30.org/fortify-headers
Log | Files | Refs | README | LICENSE

commit 4b4dfea25d660a8a27e95ea531686001246b3d1e
parent 4f9058faae6a2ef889e9dcf113e483e27e6c1b08
Author: sin <sin@2f30.org>
Date:   Wed, 11 Mar 2015 09:17:56 +0000

Fix invalid conversion in C++ code

/usr/include/fortify/string.h: In function 'void* __fortify_memcpy(void*, const void*, size_t)':
/usr/include/fortify/string.h:13:12: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
/usr/include/fortify/string.h:14:18: error: invalid conversion from 'const void*' to 'const char*' [-fpermissive]

Since we are relying on GCC anyway, assume void * arithmetic is OK.

Diffstat:
Minclude/string.h | 6++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/include/string.h b/include/string.h @@ -10,13 +10,11 @@ void * __fortify_memcpy(void *dest, const void *src, size_t n) { size_t bos = __builtin_object_size(dest, 0); - char *d = dest; - const char *s = src; /* trap if pointers are overlapping but not if dest == src. * gcc seems to like to generate code that relies on dest == src */ - if ((d < s && d + n > s) || - (s < d && s + n > d)) + if ((dest < src && dest + n > src) || + (src < dest && src + n > dest)) __builtin_trap(); if (n > bos) __builtin_trap();