Skip to content

Commit e79be02

Browse files
JarmouniAcarlescufi
authored andcommitted
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 <[email protected]>
1 parent 7f57759 commit e79be02

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
@@ -277,7 +277,8 @@ ZTEST(k_heap_api, test_k_heap_alloc_pending_null)
277277
*
278278
* @details The test allocates 256 unsigned integers of 4 bytes for a
279279
* total of 1024 bytes from the 2048 byte heap. It checks if allocation
280-
* and initialization are successful or not
280+
* and initialization are successful or not.
281+
* Also tests k_heap_calloc() overflow and zero-size edge cases
281282
*
282283
* @see k_heap_calloc(), k_heap_free()
283284
*/
@@ -292,6 +293,14 @@ ZTEST(k_heap_api, test_k_heap_calloc)
292293
}
293294

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

297306
/**

0 commit comments

Comments
 (0)