Skip to content

Commit

Permalink
Issue 15578 - assert before refcount overflow (#22103)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jtung-apple authored and pull[bot] committed Aug 16, 2023
1 parent be95555 commit 2215732
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/system/SystemPacketBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <stdint.h>

#include <limits.h>
#include <limits>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -431,6 +432,8 @@ void PacketBuffer::AddRef()
pbuf_ref(this);
#else // !CHIP_SYSTEM_CONFIG_USE_LWIP
LOCK_BUF_POOL();
VerifyOrDieWithMsg(this->ref < std::numeric_limits<decltype(this->ref)>::max(), chipSystemLayer,
"packet buffer refcount overflow");
++this->ref;
UNLOCK_BUF_POOL();
#endif // !CHIP_SYSTEM_CONFIG_USE_LWIP
Expand Down

0 comments on commit 2215732

Please sign in to comment.