From patchwork Mon Mar 4 13:45:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Kostiuk X-Patchwork-Id: 777755 Delivered-To: patch@linaro.org Received: by 2002:a5d:4b84:0:b0:33d:f458:43ce with SMTP id b4csp521618wrt; Mon, 4 Mar 2024 05:46:48 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWOTYtM9phRtONNyk6iM/Ml1+7OdSA+UhZEhcjYaBQJ9itH6BaBS27e3IOKt9uX2n8EhpHYz/DSkfradp1f2i+u X-Google-Smtp-Source: AGHT+IHe5INz3XbAN8w+BaCegCEYL258og91Rb4w820VYha/U+xyKIE5GAwEueg6QyeGzshO2lXS X-Received: by 2002:a05:622a:1a9f:b0:42e:fa69:ba81 with SMTP id s31-20020a05622a1a9f00b0042efa69ba81mr689486qtc.18.1709560008321; Mon, 04 Mar 2024 05:46:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709560008; cv=none; d=google.com; s=arc-20160816; b=ejg1MtFEsA56vugZBf475ZEq1W+kTxKzviZBZkHGU4PUxubrKTp15BNfQca9NsHwBa GpOCP7g7RAITOgJMyqX/BdyYiuWG1413SjrCClJ6DEksUY87BcL6j9SSc9yYk4UyLkSW UB25yUpKW3QlvXVTm397hvmITwUVP57FDsGmeszwlYGIpEhsxvgbIqVxxlkpCmBPIBQW gftEPzVf5aefw3NvVoVJYcEbVsK9W9c6f74JY6GLVRiPoTKe7/4l1CSwmmBWHKAYTpT+ 8ek/dhZHRfwuk8N1feDIivmF6y6SwEpmHN7wRgIEdIlMzTs2eXv8cVtpqj2ldjUCiNW2 gosQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6J5oh8U2LJyvNNXLz/CYBSqH4JLeLvNtvRZckNxhbIQ=; fh=HMmCulo2CQAUhcaUPQyxE7Qn8ZYkXN50aXqcPkPUXdo=; b=Owk0K/dnZlrpuIfPGleH9+2rbTc9SAevMbPJ3Lom0F6qdVLnnfF5hi3m+ZM5T6UrXV rJ29Wq78emoe+uz2l2YLf88EXRZPyAAQd6+1jL8/GxjXsKQCw2iotX6BHymKwES0keN4 60oHcNw+B94G73/aUPtyQzySYybexh4grRLClIrxgK+mk0Le6+Om+TCjzyMf5KbNm2qn jSa6gg+O7w8q8Y42QS+c/FwWFnU3ID3Tj6/MoymNWqoGVWljvlnRYZ5PQCxJAnFGWji2 JbMyES00f8i7ncM3axje5VbAmPeMv3UTshllBnzSLML6/zvhPmlASGN9o/b5uEtAtt4X 4BxA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c6CgDlHE; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id kk11-20020a056214508b00b0068fb7e2785bsi9948983qvb.319.2024.03.04.05.46.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Mar 2024 05:46:48 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c6CgDlHE; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 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= 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 X-MC-Unique: NvctdcphMQ6OuGfgzJmTFQ-1 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) From: Konstantin Kostiuk To: qemu-devel@nongnu.org Cc: Dehan Meng , =?utf-8?q?Philippe_Mathieu-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 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé 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 = WIN_VERSION_MATRIX[tbl_idx]; const ga_win_10_0_t *win_10_0_table = ... ... while (table->version != NULL) { ^^^^^^^^^^^^^^^ while (win_10_0_table->version != 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é 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(-) -- 2.44.0 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] = { - { - /* 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[] = { + { 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[] = { + { 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] = { +static const ga_win_10_0_t WIN_10_0_SERVER_VERSION_MATRIX[] = { {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] = { +static const ga_win_10_0_t WIN_10_0_CLIENT_VERSION_MATRIX[] = { {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 = os_version->dwMinorVersion; DWORD build = os_version->dwBuildNumber; int tbl_idx = (os_version->wProductType != VER_NT_WORKSTATION); - const ga_matrix_lookup_t *table = WIN_VERSION_MATRIX[tbl_idx]; + const ga_matrix_lookup_t *table = tbl_idx ? + WIN_SERVER_VERSION_MATRIX : WIN_CLIENT_VERSION_MATRIX; const ga_win_10_0_t *win_10_0_table = tbl_idx ? WIN_10_0_SERVER_VERSION_MATRIX : WIN_10_0_CLIENT_VERSION_MATRIX; const ga_win_10_0_t *win_10_0_version = NULL;