From 2215732f6bc8631629a7ccd3395ad52ace638449 Mon Sep 17 00:00:00 2001 From: Jeff Tung <100387939+jtung-apple@users.noreply.github.com> Date: Fri, 26 Aug 2022 21:15:51 -0700 Subject: [PATCH] Issue 15578 - assert before refcount overflow (#22103) * Issue 15578 - assert before refcount overflow * changed assert to VerifyOrDieWithMsg for better error reporting and code doc * use numeric_limits to avoid problems with underlying type change * restyled --- src/system/SystemPacketBuffer.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/system/SystemPacketBuffer.cpp b/src/system/SystemPacketBuffer.cpp index 3f6c136bcb152b..f47a54278433e2 100644 --- a/src/system/SystemPacketBuffer.cpp +++ b/src/system/SystemPacketBuffer.cpp @@ -42,6 +42,7 @@ #include #include +#include #include #include #include @@ -431,6 +432,8 @@ void PacketBuffer::AddRef() pbuf_ref(this); #else // !CHIP_SYSTEM_CONFIG_USE_LWIP LOCK_BUF_POOL(); + VerifyOrDieWithMsg(this->ref < std::numeric_limitsref)>::max(), chipSystemLayer, + "packet buffer refcount overflow"); ++this->ref; UNLOCK_BUF_POOL(); #endif // !CHIP_SYSTEM_CONFIG_USE_LWIP