From: Antonio Borneo Date: Sat, 14 Jun 2025 12:02:25 +0000 (+0200) Subject: flash: nor: use array size to constraint the loop X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=fa0fa25764b4737b42fbceab9f56a467263e12b0;p=users%2Fborneoa%2Fopenocd-next.git 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 --- 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]; }