From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202512 header.b=Tqc28v+B; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 8973E5A0772 for ; Wed, 07 Jan 2026 02:46:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202512; t=1767750367; bh=Li6lA/N6Xghna5fNIVrTQrkPf6Ar0pGPJzp1v4bTnDA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tqc28v+BSZXbMBXcZYIudcGH05LEbkwl4T5QWuwc4ySb8MxTKsvu26D9HoD5nq9LO 4irfCMjef0OGgxOMhezHj6BuTJq2rSXWjE+J/OYAuSmhGTxKT38zSbf46jDT5tDbEw LxSPLvKpUy4FFwy9zH3h5FdL7uCjI7CCZ3zZKH1yK1bayJTXXcaGnXTx8OZbr1OZte 0n1JbdHMjt/QNpba3jdlr7Pn2ad2yToXRD60MEb0MyzwrMWCuasQ9ZpkpuM23Onw1c ZMjZChEKjxyxsGUkn3skVbluK3gpLvq6KDz0tVx4/rON3ri7ztT4qEgrA9kRbgawnL yRfzx+IuPDKww== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4dm9qM6g4nz4wQy; Wed, 07 Jan 2026 12:46:07 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v3 2/5] migrate: Don't use terminator element for versions[] array Date: Wed, 7 Jan 2026 12:46:03 +1100 Message-ID: <20260107014606.1513722-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260107014606.1513722-1-david@gibson.dropbear.id.au> References: <20260107014606.1513722-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: PBX7M6NAINZI56KXWMCL5CB2QX4NPZTX X-Message-ID-Hash: PBX7M6NAINZI56KXWMCL5CB2QX4NPZTX X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson , Laurent Vivier X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/migrate.c b/migrate.c index 48d63a07..13bacab7 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 */ @@ -177,9 +176,9 @@ static int migrate_source(struct ctx *c, int fd) */ 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 +195,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); i++) + 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