From 0ff3c1c34d408ba289edaa2364af2d22c966c5cd Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Fri, 12 Jun 2020 16:44:17 +0300 Subject: [PATCH] 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. --- AK/RefCounted.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/AK/RefCounted.h b/AK/RefCounted.h index d221e3f5dd..1c010fa162 100644 --- a/AK/RefCounted.h +++ b/AK/RefCounted.h @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -65,6 +66,7 @@ public: { auto old_ref_count = m_ref_count++; ASSERT(old_ref_count > 0); + ASSERT(!Checked::addition_would_overflow(old_ref_count, 1)); } ALWAYS_INLINE RefCountType ref_count() const