From 9bda6b29389965f5925c233b4de912beec033969 Mon Sep 17 00:00:00 2001 From: Francisco Molina Date: Tue, 22 Mar 2022 14:53:46 +0100 Subject: [PATCH] tests/periph_flashpage_unittests: use unsgined int for address cast For 16bit platforms casting to int will overflow when ROM size nears 2**16 --- tests/periph_flashpage_unittest/main.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/periph_flashpage_unittest/main.c b/tests/periph_flashpage_unittest/main.c index cba1c50df1..380793e287 100644 --- a/tests/periph_flashpage_unittest/main.c +++ b/tests/periph_flashpage_unittest/main.c @@ -46,11 +46,12 @@ static void test_flashbase_addr(void) void *addr; addr = flashpage_addr(0); - TEST_ASSERT_EQUAL_INT((int)CPU_FLASH_BASE, (int)addr); + TEST_ASSERT_EQUAL_INT((unsigned int)CPU_FLASH_BASE, (unsigned int)addr); addr = flashpage_addr(FLASHPAGE_NUMOF - 1); - TEST_ASSERT_EQUAL_INT((long)CPU_FLASH_BASE + (((unsigned)FLASHPAGE_NUMOF - 1) * FLASHPAGE_SIZE), (int)addr); + TEST_ASSERT_EQUAL_INT((long)CPU_FLASH_BASE + (((unsigned)FLASHPAGE_NUMOF - 1) * FLASHPAGE_SIZE), + (unsigned int)addr); addr = flashpage_addr(12); - TEST_ASSERT_EQUAL_INT((int)CPU_FLASH_BASE + (12 * FLASHPAGE_SIZE), (int)addr); + TEST_ASSERT_EQUAL_INT((unsigned int)CPU_FLASH_BASE + (12 * FLASHPAGE_SIZE), (unsigned int)addr); } static void test_flashbase_page(void) @@ -65,7 +66,9 @@ static void test_flashbase_page(void) TEST_ASSERT_EQUAL_INT(1, page); page = flashpage_page((void *)(CPU_FLASH_BASE + FLASHPAGE_SIZE + 1)); TEST_ASSERT_EQUAL_INT(1, page); - page = flashpage_page((void *)(CPU_FLASH_BASE + ((unsigned)FLASHPAGE_SIZE * (FLASHPAGE_NUMOF - 1)))); + page = + flashpage_page((void *)(CPU_FLASH_BASE + + ((unsigned)FLASHPAGE_SIZE * (FLASHPAGE_NUMOF - 1)))); TEST_ASSERT_EQUAL_INT(FLASHPAGE_NUMOF - 1, page); }