mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #17368 from kaspar030/fix_ztimer64_uninitialized_timer_crash
sys/ztimer64: make _del_entry_from_list() safe for uninit ztimer64_t
This commit is contained in:
commit
b52a8857eb
@ -128,6 +128,9 @@ static int _add_entry_to_list(ztimer64_clock_t *clock, ztimer64_base_t *entry)
|
||||
static int _del_entry_from_list(ztimer64_clock_t *clock, ztimer64_base_t *entry)
|
||||
{
|
||||
DEBUG("_del_entry_from_list()\n");
|
||||
if (!clock->first) {
|
||||
return 0;
|
||||
}
|
||||
assert(_is_set((ztimer64_t *)entry));
|
||||
if (clock->first == entry) {
|
||||
/* special case: removing first entry */
|
||||
|
@ -198,6 +198,24 @@ static void test_ztimer64_checkpoint(void)
|
||||
TEST_ASSERT_EQUAL_INT(2 * ZTIMER64_CHECKPOINT_INTERVAL + UINT32_MAX, now64);
|
||||
}
|
||||
|
||||
static void test_ztimer64_set_uninitialized(void)
|
||||
{
|
||||
/* regression test for setting an uninitialized ztimer64 on an empty clock */
|
||||
ztimer_mock_t zmock;
|
||||
ztimer_clock_t *z = &zmock.super;
|
||||
ztimer64_clock_t z64mock;
|
||||
ztimer64_clock_t *z64 = &z64mock;
|
||||
|
||||
memset(&zmock, '\0', sizeof(ztimer_mock_t));
|
||||
memset(&z64mock, '\0', sizeof(ztimer64_clock_t));
|
||||
/* ztimer base clock is already extended to 32bit */
|
||||
ztimer_mock_init(&zmock, 32);
|
||||
ztimer64_clock_init(z64, z);
|
||||
|
||||
ztimer64_t timer = { .base.target = 1 };
|
||||
ztimer64_set(z64, &timer, 0);
|
||||
}
|
||||
|
||||
Test *tests_ztimer64_tests(void)
|
||||
{
|
||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||
@ -206,6 +224,7 @@ Test *tests_ztimer64_tests(void)
|
||||
new_TestFixture(test_ztimer64_set_0),
|
||||
new_TestFixture(test_ztimer64_set_at),
|
||||
new_TestFixture(test_ztimer64_checkpoint),
|
||||
new_TestFixture(test_ztimer64_set_uninitialized),
|
||||
};
|
||||
|
||||
EMB_UNIT_TESTCALLER(ztimer64_tests, setup, NULL, fixtures);
|
||||
|
Loading…
Reference in New Issue
Block a user