When scanning the versions[] array we use a dummy entry to detect when
we're finished. Use ARRAY_SIZE() instead, which is almost as easy, a
little safer, and doesn't cause clang-tidy 21.1.7 to complain.
Signed-off-by: David Gibson
Reviewed-by: Laurent Vivier
---
migrate.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/migrate.c b/migrate.c
index 48d63a07..a70ea7b7 100644
--- a/migrate.c
+++ b/migrate.c
@@ -123,7 +123,6 @@ static const struct migrate_version versions[] = {
* MSS and omitted timestamps, which meant it usually wouldn't work.
* Therefore we don't attempt to support compatibility with it.
*/
- { 0 },
};
/* Current encoding version */
@@ -180,6 +179,7 @@ static const struct migrate_version *migrate_target_read_header(int fd)
const struct migrate_version *v;
struct migrate_header h;
uint32_t id, compat_id;
+ unsigned i;
if (read_all_buf(fd, &h, sizeof(h)))
return NULL;
@@ -196,9 +196,9 @@ static const struct migrate_version *migrate_target_read_header(int fd)
return NULL;
}
- for (v = versions; v->id; v++)
- if (v->id <= id && v->id >= compat_id)
- return v;
+ for (i = 0; i < ARRAY_SIZE(versions); v++)
+ if (versions[i].id <= id && versions[i].id >= compat_id)
+ return &versions[i];
errno = ENOTSUP;
err("Unsupported device state version: %u", id);
--
2.52.0