From nobody Tue Nov 26 08:23:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709560008; cv=none; d=zohomail.com; s=zohoarc; b=Bx93K01C0UEm8gW+FsbOGDY3hH5b+IlnpgK39AKPowqhkruRLXUhZ2tumQjx3MNnF/gerI5YuGz/9to/p2OGKfwoVmNTLHA9Is+sLQAVrlVnMP0zHKgOMXHZXMClaxZBdCTMwLQHibxm3xf8urOJEnonXxtDwWWHZnas8ZRCejQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709560008; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6J5oh8U2LJyvNNXLz/CYBSqH4JLeLvNtvRZckNxhbIQ=; b=PEJZwBmqgvpBF3Xj+N1ovZSuPYx+luLNIcO2rP+c4QpCnp1oB3qRuKANwEL2bLLputicfw3Im42oCcvTzB+csRoolFgO0rNNtgJjO07W6lIudqOccep9DqpjBTXTtb2cfz3X6tSMvGtVlaJZjTo8khk+inYJqcj5uuqtNMNNzdU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709560008751725.3035298440176; Mon, 4 Mar 2024 05:46:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rh8dm-0000dA-0H; Mon, 04 Mar 2024 08:46:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rh8di-0000co-8H for qemu-devel@nongnu.org; Mon, 04 Mar 2024 08:45:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rh8dR-0000uk-Cn for qemu-devel@nongnu.org; Mon, 04 Mar 2024 08:45:57 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-610-NvctdcphMQ6OuGfgzJmTFQ-1; Mon, 04 Mar 2024 08:45:37 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 52C6A85A58F; Mon, 4 Mar 2024 13:45:37 +0000 (UTC) Received: from srv1.redhat.com (unknown [10.45.226.165]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4A91B24D; Mon, 4 Mar 2024 13:45:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709559940; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6J5oh8U2LJyvNNXLz/CYBSqH4JLeLvNtvRZckNxhbIQ=; b=c6CgDlHECR/tGcfR9gT7lekT2/JhLLuqCnaQ5B6mQJay5O2a4i2YhisHYRCZ2w1HQIVuWR p8+TrtZri9r5SIp5wOPlgby7VdTle7OtFOYNopnXK1qZ1zksmDxP7+VRai1YUX6TwrujKi oXLLB2spweOixNrqWytByszi+x32HdE= X-MC-Unique: NvctdcphMQ6OuGfgzJmTFQ-1 From: Konstantin Kostiuk To: qemu-devel@nongnu.org Cc: Dehan Meng , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Michael Roth , Yan Vugenfirer Subject: [PATCH v4 2/3] qga/commands-win32: Do not set matrix_lookup_t/win_10_0_t arrays size Date: Mon, 4 Mar 2024 15:45:31 +0200 Message-ID: <20240304134532.28506-3-kkostiuk@redhat.com> In-Reply-To: <20240304134532.28506-1-kkostiuk@redhat.com> References: <20240304134532.28506-1-kkostiuk@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kkostiuk@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1709560009107100001 From: Philippe Mathieu-Daud=C3=A9 ga_get_win_name() iterates over all elements in the arrays by checking the 'version' field is non-NULL. Since the arrays are guarded by a NULL terminating element, we don't need to specify their size: static char *ga_get_win_name(...) { ... const ga_matrix_lookup_t *table =3D WIN_VERSION_MATRIX[tbl_idx]; const ga_win_10_0_t *win_10_0_table =3D ... ... while (table->version !=3D NULL) { ^^^^^^^^^^^^^^^ while (win_10_0_table->version !=3D NULL) { ^^^^^^^^^^^^^^^ This will simplify maintenance when adding new entries to these arrays. Split WIN_VERSION_MATRIX into WIN_CLIENT_VERSION_MATRIX and WIN_SERVER_VERSION_MATRIX because multidimensional array must have bounds for all dimensions except the first. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-ID: <20240222152835.72095-3-philmd@linaro.org> Reviewed-by: Konstantin Kostiuk Signed-off-by: Konstantin Kostiuk Reviewed-by: Yan Vugenfirer --- qga/commands-win32.c | 52 +++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 79b5a580c9..a830f1494e 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -2124,45 +2124,42 @@ typedef struct _ga_matrix_lookup_t { const char *version_id; } ga_matrix_lookup_t; -static const ga_matrix_lookup_t WIN_VERSION_MATRIX[2][7] =3D { - { - /* Desktop editions */ - { 5, 0, "Microsoft Windows 2000", "2000"}, - { 5, 1, "Microsoft Windows XP", "xp"}, - { 6, 0, "Microsoft Windows Vista", "vista"}, - { 6, 1, "Microsoft Windows 7" "7"}, - { 6, 2, "Microsoft Windows 8", "8"}, - { 6, 3, "Microsoft Windows 8.1", "8.1"}, - { 0, 0, 0} - },{ - /* Server editions */ - { 5, 2, "Microsoft Windows Server 2003", "2003"}, - { 6, 0, "Microsoft Windows Server 2008", "2008"}, - { 6, 1, "Microsoft Windows Server 2008 R2", "2008r2"}, - { 6, 2, "Microsoft Windows Server 2012", "2012"}, - { 6, 3, "Microsoft Windows Server 2012 R2", "2012r2"}, - { 0, 0, 0}, - { 0, 0, 0} - } +static const ga_matrix_lookup_t WIN_CLIENT_VERSION_MATRIX[] =3D { + { 5, 0, "Microsoft Windows 2000", "2000"}, + { 5, 1, "Microsoft Windows XP", "xp"}, + { 6, 0, "Microsoft Windows Vista", "vista"}, + { 6, 1, "Microsoft Windows 7" "7"}, + { 6, 2, "Microsoft Windows 8", "8"}, + { 6, 3, "Microsoft Windows 8.1", "8.1"}, + { } +}; + +static const ga_matrix_lookup_t WIN_SERVER_VERSION_MATRIX[] =3D { + { 5, 2, "Microsoft Windows Server 2003", "2003"}, + { 6, 0, "Microsoft Windows Server 2008", "2008"}, + { 6, 1, "Microsoft Windows Server 2008 R2", "2008r2"}, + { 6, 2, "Microsoft Windows Server 2012", "2012"}, + { 6, 3, "Microsoft Windows Server 2012 R2", "2012r2"}, + { }, }; typedef struct _ga_win_10_0_t { int first_build; - const char *version; - const char *version_id; + char const *version; + char const *version_id; } ga_win_10_0_t; -static const ga_win_10_0_t WIN_10_0_SERVER_VERSION_MATRIX[4] =3D { +static const ga_win_10_0_t WIN_10_0_SERVER_VERSION_MATRIX[] =3D { {14393, "Microsoft Windows Server 2016", "2016"}, {17763, "Microsoft Windows Server 2019", "2019"}, {20344, "Microsoft Windows Server 2022", "2022"}, - {0, 0} + { } }; -static const ga_win_10_0_t WIN_10_0_CLIENT_VERSION_MATRIX[3] =3D { +static const ga_win_10_0_t WIN_10_0_CLIENT_VERSION_MATRIX[] =3D { {10240, "Microsoft Windows 10", "10"}, {22000, "Microsoft Windows 11", "11"}, - {0, 0} + { } }; static void ga_get_win_version(RTL_OSVERSIONINFOEXW *info, Error **errp) @@ -2191,7 +2188,8 @@ static char *ga_get_win_name(const OSVERSIONINFOEXW *= os_version, bool id) DWORD minor =3D os_version->dwMinorVersion; DWORD build =3D os_version->dwBuildNumber; int tbl_idx =3D (os_version->wProductType !=3D VER_NT_WORKSTATION); - const ga_matrix_lookup_t *table =3D WIN_VERSION_MATRIX[tbl_idx]; + const ga_matrix_lookup_t *table =3D tbl_idx ? + WIN_SERVER_VERSION_MATRIX : WIN_CLIENT_VERSION_MATRIX; const ga_win_10_0_t *win_10_0_table =3D tbl_idx ? WIN_10_0_SERVER_VERSION_MATRIX : WIN_10_0_CLIENT_VERSION_MATRIX; const ga_win_10_0_t *win_10_0_version =3D NULL; -- 2.44.0