Re: [PATCH 29/40] qemufirmwaretest: Base iteration on string lists

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2/6/21 9:32 AM, Peter Krempa wrote:
Remove the need to calculate list lengths.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
  tests/qemufirmwaretest.c | 24 ++++++++++++------------
  1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/tests/qemufirmwaretest.c b/tests/qemufirmwaretest.c
index ced9d53260..b59b002c3b 100644
--- a/tests/qemufirmwaretest.c
+++ b/tests/qemufirmwaretest.c
@@ -57,16 +57,16 @@ testFWPrecedence(const void *opaque G_GNUC_UNUSED)
  {
      g_autofree char *fakehome = NULL;
      g_auto(GStrv) fwList = NULL;
-    size_t nfwList;
-    size_t i;
      const char *expected[] = {
          PREFIX "/share/qemu/firmware/40-bios.json",
          SYSCONFDIR "/qemu/firmware/40-ovmf-sb-keys.json",
          PREFIX "/share/qemu/firmware/50-ovmf-sb-keys.json",
          PREFIX "/share/qemu/firmware/61-ovmf.json",
          PREFIX "/share/qemu/firmware/70-aavmf.json",
+        NULL
      };
-    const size_t nexpected = G_N_ELEMENTS(expected);
+    GStrv e;

Can't we use simple 'const char **'?

+    GStrv f;

      fakehome = g_strdup(abs_srcdir "/qemufirmwaredata/home/user/.config");

@@ -80,18 +80,18 @@ testFWPrecedence(const void *opaque G_GNUC_UNUSED)
          return -1;
      }

-    nfwList = virStringListLength((const char **)fwList);
-
-    for (i = 0; i < MAX(nfwList, nexpected); i++) {
-        const char *e = i < nexpected ? expected[i] : NULL;
-        const char *f = i < nfwList ? fwList[i] : NULL;
-
-        if (STRNEQ_NULLABLE(e, f)) {
+    for (e = (char **) expected, f = fwList; *f || *e;) {

We can avoid this typecast then.

+        if (STRNEQ_NULLABLE(*f, *e)) {
              fprintf(stderr,
-                    "Unexpected path (i=%zu). Expected %s got %s \n",
-                    i, NULLSTR(e), NULLSTR(f));
+                    "Unexpected path. Expected %s got %s \n",
+                    NULLSTR(*e), NULLSTR(*f));
              return -1;
          }
+
+        if (*f)
+            f++;
+        if (*e)
+            e++;
      }

      return 0;


Michal




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux