Skip to content

Commit

Permalink
Fix allocation size overflow check in CowData
Browse files Browse the repository at this point in the history
  • Loading branch information
AThousandShips committed Sep 19, 2023
1 parent 571cd0e commit c48b189
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/templates/cowdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ class CowData {
}

_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__)
size_t o;
size_t p;
Expand All @@ -101,13 +105,12 @@ class CowData {
if (__builtin_add_overflow(o, static_cast<size_t>(32), &p)) {
return false; // No longer allocated here.
}
return true;
#else
// Speed is more important than correctness here, do the operations unchecked
// and hope for the best.
*out = _get_alloc_size(p_elements);
return true;
#endif
return *out;
}

void _unref(void *p_data);
Expand Down

0 comments on commit c48b189

Please sign in to comment.