qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org, Dehan Meng <demeng@redhat.com>
Cc: "Konstantin Kostiuk" <kkostiuk@redhat.com>,
	"Michael Roth" <michael.roth@amd.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PATCH v3 2/3] qga/commands-win32: Do not set matrix_lookup_t/win_10_0_t arrays size
Date: Thu, 22 Feb 2024 16:28:34 +0100	[thread overview]
Message-ID: <20240222152835.72095-3-philmd@linaro.org> (raw)
In-Reply-To: <20240222152835.72095-1-philmd@linaro.org>

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.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 qga/commands-win32.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 79b5a580c9..87ce6e2870 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -2124,7 +2124,7 @@ 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] = {
+static const ga_matrix_lookup_t WIN_VERSION_MATRIX[2][] = {
     {
         /* Desktop editions */
         { 5, 0, "Microsoft Windows 2000",   "2000"},
@@ -2133,7 +2133,7 @@ static const ga_matrix_lookup_t WIN_VERSION_MATRIX[2][7] = {
         { 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"},
@@ -2141,28 +2141,27 @@ static const ga_matrix_lookup_t WIN_VERSION_MATRIX[2][7] = {
         { 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}
+        { },
     }
 };
 
 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)
-- 
2.41.0



  parent reply	other threads:[~2024-02-22 15:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-22 15:28 [PATCH v3 0/3] qga/commands-win32: Style cleanups before adding Windows Server 2025 Philippe Mathieu-Daudé
2024-02-22 15:28 ` [PATCH v3 1/3] qga/commands-win32: Declare const qualifier before type Philippe Mathieu-Daudé
2024-02-23  8:35   ` Konstantin Kostiuk
2024-02-22 15:28 ` Philippe Mathieu-Daudé [this message]
2024-02-23  8:37   ` [PATCH v3 2/3] qga/commands-win32: Do not set matrix_lookup_t/win_10_0_t arrays size Konstantin Kostiuk
2024-02-23 12:00   ` Konstantin Kostiuk
2024-02-23 17:49   ` Philippe Mathieu-Daudé
2024-02-22 15:28 ` [PATCH v3 3/3] qga-win: Add support of Windows Server 2025 in get-osinfo command Philippe Mathieu-Daudé
2024-02-23  8:38   ` Konstantin Kostiuk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240222152835.72095-3-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=demeng@redhat.com \
    --cc=kkostiuk@redhat.com \
    --cc=michael.roth@amd.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).