diff --git a/rangecheck.h b/rangecheck.h index b6b8bdd..70b0f3f 100644 --- a/rangecheck.h +++ b/rangecheck.h @@ -1,6 +1,7 @@ #ifndef RANGECHECK_H #define RANGECHECK_H +#include #include /* return 0 for range error / overflow, 1 for ok */ @@ -16,14 +17,14 @@ __static inline int range_ptrinbuf(const void* buf,size_t len,const void* ptr) { register const char* c=(const char*)buf; /* no pointer arithmetic on void* */ return (c && /* is buf non-NULL? */ #if (__GNUC__ == 4) && (__GNUC_MINOR__ == 1) - ((size_t)c)+len>(size_t)c && /* gcc 4.1 miscompiles this test */ + ((uintptr_t)c)+len>(uintptr_t)c && /* gcc 4.1 miscompiles this test */ #else c+len>c && /* catch integer overflows and fail if buffer is 0 bytes long */ /* because then ptr can't point _in_ the buffer */ #endif - (size_t)((const char*)ptr-c)=(size_t)buf); /* gcc 4.1 miscompiles this test */ + return (buf && (uintptr_t)buf+len>=(uintptr_t)buf); /* gcc 4.1 miscompiles this test */ #else return (buf && (const char*)buf+len>=(const char*)buf); #endif