From 0f5b08d83ad8ae7eebe7b57e8f6b11a98b3186dc Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Tue, 9 Jul 2024 16:21:43 +0200 Subject: [PATCH] test: add rc overflow test --- tests/z_refcount_test.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/z_refcount_test.c b/tests/z_refcount_test.c index 34f75b69e..e08508ba4 100644 --- a/tests/z_refcount_test.c +++ b/tests/z_refcount_test.c @@ -214,6 +214,18 @@ void test_weak_upgrade(void) { assert(_dummy_weak_drop(&dwk1)); } +void test_overflow(void) { + _dummy_rc_t drc1 = _dummy_rc_new(); + // Artificially set weak count to max value + drc1.in->_weak_cnt = INT32_MAX; + + _dummy_rc_t drc2 = _dummy_rc_clone(&drc1); + assert(drc2.in == NULL); + + _dummy_weak_t dwk1 = _dummy_rc_clone_as_weak(&drc1); + assert(dwk1.in == NULL); +} + int main(void) { test_rc_null(); test_rc_size(); @@ -230,5 +242,6 @@ int main(void) { test_weak_clone(); test_weak_copy(); test_weak_upgrade(); + test_overflow(); return 0; }