diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-09-20 20:56:47 +0200 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-09-20 20:56:47 +0200 |
commit | bcfaf0bb8ff5f436e4b446949c35688c427469c9 (patch) | |
tree | 2f4f99b686442e6f2bfe6df149448800f7d5b49e /Objects/stringlib/find_max_char.h | |
parent | 828dd65503425f5873d6faf7833494e93a551d37 (diff) | |
download | cpython-bcfaf0bb8ff5f436e4b446949c35688c427469c9.tar.gz |
Issue #15144: Fix possible integer overflow when handling pointers as integer values, by using Py_uintptr_t instead of size_t.
Patch by Serhiy Storchaka.
Diffstat (limited to 'Objects/stringlib/find_max_char.h')
-rw-r--r-- | Objects/stringlib/find_max_char.h | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/Objects/stringlib/find_max_char.h b/Objects/stringlib/find_max_char.h index 9e344a0de9..06559c8a9f 100644 --- a/Objects/stringlib/find_max_char.h +++ b/Objects/stringlib/find_max_char.h @@ -2,9 +2,6 @@ #if STRINGLIB_IS_UNICODE -/* Mask to check or force alignment of a pointer to C 'long' boundaries */ -#define LONG_PTR_MASK (size_t) (SIZEOF_LONG - 1) - /* Mask to quickly check whether a C 'long' contains a non-ASCII, UTF8-encoded char. */ #if (SIZEOF_LONG == 8) @@ -21,10 +18,11 @@ Py_LOCAL_INLINE(Py_UCS4) STRINGLIB(find_max_char)(const STRINGLIB_CHAR *begin, const STRINGLIB_CHAR *end) { const unsigned char *p = (const unsigned char *) begin; - const unsigned char *aligned_end = (const unsigned char *) ((size_t) end & ~LONG_PTR_MASK); + const unsigned char *aligned_end = + (const unsigned char *) _Py_ALIGN_DOWN(end, SIZEOF_LONG); while (p < end) { - if (!((size_t) p & LONG_PTR_MASK)) { + if (_Py_IS_ALIGNED(p, SIZEOF_LONG)) { /* Help register allocation */ register const unsigned char *_p = p; while (_p < aligned_end) { @@ -43,7 +41,6 @@ STRINGLIB(find_max_char)(const STRINGLIB_CHAR *begin, const STRINGLIB_CHAR *end) return 127; } -#undef LONG_PTR_MASK #undef ASCII_CHAR_MASK #else /* STRINGLIB_SIZEOF_CHAR == 1 */ @@ -72,7 +69,7 @@ STRINGLIB(find_max_char)(const STRINGLIB_CHAR *begin, const STRINGLIB_CHAR *end) register Py_UCS4 mask; Py_ssize_t n = end - begin; const STRINGLIB_CHAR *p = begin; - const STRINGLIB_CHAR *unrolled_end = begin + (n & ~ (Py_ssize_t) 3); + const STRINGLIB_CHAR *unrolled_end = begin + _Py_SIZE_ROUND_DOWN(n, 4); Py_UCS4 max_char; max_char = MAX_CHAR_ASCII; |