From fa0fa25764b4737b42fbceab9f56a467263e12b0 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 14 Jun 2025 14:02:25 +0200 Subject: [PATCH] flash: nor: use array size to constraint the loop Instead of using NULL terminated arrays to determine the last element of the array, use the size of the array. Change-Id: Ia3d739b0a9f201ba2e7b1d1244d60c8e5546c9c1 Signed-off-by: Antonio Borneo Reviewed-on: https://review.openocd.org/c/openocd/+/8947 Reviewed-by: Brandon Martin Tested-by: jenkins --- src/flash/nor/drivers.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/flash/nor/drivers.c b/src/flash/nor/drivers.c index 4f468848b..cb807ec62 100644 --- a/src/flash/nor/drivers.c +++ b/src/flash/nor/drivers.c @@ -7,6 +7,8 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif + +#include #include "imp.h" /** @@ -89,12 +91,11 @@ static const struct flash_driver * const flash_drivers[] = { &xcf_flash, &xmc1xxx_flash, &xmc4xxx_flash, - NULL, }; const struct flash_driver *flash_driver_find_by_name(const char *name) { - for (unsigned int i = 0; flash_drivers[i]; i++) { + for (size_t i = 0; i < ARRAY_SIZE(flash_drivers); i++) { if (strcmp(name, flash_drivers[i]->name) == 0) return flash_drivers[i]; }