From 54fdb244d65be7c5df70a00897b5da0069bf77be Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Tue, 20 Mar 2001 00:39:56 +0000 Subject: [PATCH] ICU-827 improve default U_MAX_PTR(base) definition to make sure that it never returns a pointer >base+0x7fffffff X-SVN-Rev: 4187 --- icu4c/source/common/unicode/utypes.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/icu4c/source/common/unicode/utypes.h b/icu4c/source/common/unicode/utypes.h index a34129a767..742a343a02 100644 --- a/icu4c/source/common/unicode/utypes.h +++ b/icu4c/source/common/unicode/utypes.h @@ -188,11 +188,22 @@ typedef uint8_t UVersionInfo[U_MAX_VERSION_LENGTH]; /** * \def U_MAX_PTR * Maximum value of a (void*) - use to indicate the limit of an 'infinite' buffer. - * @param ptr The beginning of a buffer to find the maximum offset from + * In fact, buffer sizes must not exceed 2GB so that the difference between + * the buffer limit and the buffer start can be expressed in an int32_t. + * + * The definition of U_MAX_PTR must fulfill the following conditions: + * - return the largest possible pointer greater than base + * - return a valid pointer according to the machine architecture (AS/400, 64-bit, etc.) + * - avoid wrapping around at high addresses + * - make sure that the returned pointer is not farther from base than 0x7fffffff + * + * For some architectures (like AS/400), a custom macro must be defined in platform.h.in or similar. + * + * @param base The beginning of a buffer to find the maximum offset from * @internal */ #ifndef U_MAX_PTR -#define U_MAX_PTR(ptr) ((void*)-1) +# define U_MAX_PTR(base) ((void *)(((char *)(base)+0x7fffffff)>(char *)(base) ? ((char *)(base)+0x7fffffff) : (char *)-1)) #endif /*===========================================================================*/