Skip to content

Commit 4ef69bf

Browse files
committed
tests: kernel: mem_heap: enhance k_heap_calloc() API coverage
Enhance k_heap_calloc() API coverage by testing overflow and zero-size edge cases Signed-off-by: Abderrahmane JARMOUNI <git@jarmouni.me>
1 parent f039e2b commit 4ef69bf

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tests/kernel/mem_heap/k_heap_api/src/test_kheap_api.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ ZTEST(k_heap_api, test_k_heap_alloc_pending_null)
275275
*
276276
* @details The test allocates 256 unsigned integers of 4 bytes for a
277277
* total of 1024 bytes from the 2048 byte heap. It checks if allocation
278-
* and initialization are successful or not
278+
* and initialization are successful or not.
279+
* Also tests k_heap_calloc() overflow and zero-size edge cases
279280
*
280281
* @see k_heap_calloc(), k_heap_free()
281282
*/
@@ -290,6 +291,14 @@ ZTEST(k_heap_api, test_k_heap_calloc)
290291
}
291292

292293
k_heap_free(&k_heap_test, p);
294+
295+
/* Overflow: num * size wraps around */
296+
p = k_heap_calloc(&k_heap_test, SIZE_MAX, SIZE_MAX, K_NO_WAIT);
297+
zassert_is_null(p, "k_heap_calloc with overflow should fail");
298+
299+
/* Zero-size, should not crash */
300+
p = k_heap_calloc(&k_heap_test, 0, 0, K_NO_WAIT);
301+
(void)p;
293302
}
294303

295304
/**

0 commit comments

Comments
 (0)