fix valid pointer detection on mac
@@ -217,9 +217,15 @@ static _Atomic(uintptr_t)mi_segment_map[MI_SEGMENT_MAP_WSIZE]; // 2KiB per TB w
static size_t mi_segment_map_index_of(const mi_segment_t* segment, size_t* bitidx) {
mi_assert_internal(_mi_ptr_segment(segment) == segment); // is it aligned on MI_SEGMENT_SIZE?
- uintptr_t segindex = ((uintptr_t)segment % MI_MAX_ADDRESS) / MI_SEGMENT_SIZE;
- *bitidx = segindex % (8*MI_INTPTR_SIZE);
- return (segindex / (8*MI_INTPTR_SIZE));
+ if ((uintptr_t)segment >= MI_MAX_ADDRESS) {
+ *bitidx = 0;
+ return 0;
+ }
+ else {
+ uintptr_t segindex = ((uintptr_t)segment) / MI_SEGMENT_SIZE;
+ *bitidx = segindex % MI_INTPTR_BITS;
+ return (segindex / MI_INTPTR_BITS);
+ }
}
void _mi_segment_map_allocated_at(const mi_segment_t* segment) {
@@ -257,6 +263,9 @@ static mi_segment_t* _mi_segment_of(const void* p) {
return segment; // yes, allocated by us
}
if (index==0) return NULL;
+
+ // TODO: maintain max/min allocated range for efficiency for more efficient rejection of invalid pointers?
+
// search downwards for the first segment in case it is an interior pointer
// could be slow but searches in MI_INTPTR_SIZE * MI_SEGMENT_SIZE (512MiB) steps trough
// valid huge objects
