Merge pull request #1245 from AThousandShips/alloc_fix
Fix allocation size overflow check in `CowData`pull/1246/head
commit
a3dfbbde85
|
@ -102,6 +102,10 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
_FORCE_INLINE_ bool _get_alloc_size_checked(size_t p_elements, size_t *out) const {
|
_FORCE_INLINE_ bool _get_alloc_size_checked(size_t p_elements, size_t *out) const {
|
||||||
|
if (unlikely(p_elements == 0)) {
|
||||||
|
*out = 0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
size_t o;
|
size_t o;
|
||||||
size_t p;
|
size_t p;
|
||||||
|
@ -113,13 +117,12 @@ private:
|
||||||
if (__builtin_add_overflow(o, static_cast<size_t>(32), &p)) {
|
if (__builtin_add_overflow(o, static_cast<size_t>(32), &p)) {
|
||||||
return false; // No longer allocated here.
|
return false; // No longer allocated here.
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
#else
|
#else
|
||||||
// Speed is more important than correctness here, do the operations unchecked
|
// Speed is more important than correctness here, do the operations unchecked
|
||||||
// and hope for the best.
|
// and hope for the best.
|
||||||
*out = _get_alloc_size(p_elements);
|
*out = _get_alloc_size(p_elements);
|
||||||
return true;
|
|
||||||
#endif
|
#endif
|
||||||
|
return *out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _unref(void *p_data);
|
void _unref(void *p_data);
|
||||||
|
|
Loading…
Reference in New Issue