AK: Assert refcount doesn't overflow

We don't really have a good way to prevent this kind of overflow,
but let's at least immediately panic in this case.
This commit is contained in:
Sergey Bugaev 2020-06-12 16:44:17 +03:00 committed by Andreas Kling
parent c80e657dda
commit 0ff3c1c34d
Notes: sideshowbarker 2024-07-19 05:42:11 +09:00

View file

@ -28,6 +28,7 @@
#include <AK/Assertions.h>
#include <AK/Atomic.h>
#include <AK/Checked.h>
#include <AK/Platform.h>
#include <AK/StdLibExtras.h>
@ -65,6 +66,7 @@ public:
{
auto old_ref_count = m_ref_count++;
ASSERT(old_ref_count > 0);
ASSERT(!Checked<RefCountType>::addition_would_overflow(old_ref_count, 1));
}
ALWAYS_INLINE RefCountType ref_count() const