[libvirt] [PATCH 03/17] use ARRAY_CARDINALITY more

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

 



From: Jim Meyering <meyering@xxxxxxxxxx>

* tests/nodeinfotest.c: Include "util.h".
* src/xen_internal.c: Likewise.
* src/qemu_conf.c (qemudCapsInit): Use ARRAY_CARDINALITY.
* src/storage_backend.c (virStorageBackendForType): Likewise.
* src/storage_backend_fs.c (virStorageBackendProbeFile): Likewise.
* src/xen_internal.c (xenHypervisorMakeCapabilitiesInternal): Likewise.
* src/xend_internal.c (xenDaemonParseSxpr): Likewise.
* tests/nodeinfotest.c (mymain): Likewise.
* tests/qparamtest.c (DO_TEST): Likewise.
---
 src/qemu_conf.c          |    4 ++--
 src/storage_backend.c    |    2 +-
 src/storage_backend_fs.c |    4 ++--
 src/xen_internal.c       |    3 ++-
 src/xend_internal.c      |    2 +-
 tests/nodeinfotest.c     |    3 ++-
 tests/qparamtest.c       |    2 +-
 7 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index 7702090..03b14f8 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -371,7 +371,7 @@ virCapsPtr qemudCapsInit(void) {
     if (qemudCapsInitNUMA(caps) < 0)
         goto no_memory;

-    for (i = 0 ; i < (sizeof(arch_info_hvm)/sizeof(arch_info_hvm[0])) ; i++)
+    for (i = 0 ; i < ARRAY_CARDINALITY(arch_info_hvm) ; i++)
         if (qemudCapsInitGuest(caps,
                                utsname.machine,
                                &arch_info_hvm[i], 1) < 0)
@@ -379,7 +379,7 @@ virCapsPtr qemudCapsInit(void) {

     if (access("/usr/bin/xenner", X_OK) == 0 &&
         access("/dev/kvm", F_OK) == 0) {
-        for (i = 0 ; i < (sizeof(arch_info_xen)/sizeof(arch_info_xen[0])) ; i++)
+        for (i = 0 ; i < ARRAY_CARDINALITY(arch_info_xen) ; i++)
             /* Allow Xen 32-on-32, 32-on-64 and 64-on-64 */
             if (STREQ(arch_info_xen[i].arch, utsname.machine) ||
                 (STREQ(utsname.machine, "x86_64") &&
diff --git a/src/storage_backend.c b/src/storage_backend.c
index de4efa7..e33f98c 100644
--- a/src/storage_backend.c
+++ b/src/storage_backend.c
@@ -88,7 +88,7 @@ static virStorageBackendPtr backends[] = {
 virStorageBackendPtr
 virStorageBackendForType(int type) {
     unsigned int i;
-    for (i = 0 ; i < (sizeof(backends)/sizeof(backends[0])) ; i++)
+    for (i = 0 ; i < ARRAY_CARDINALITY(backends); i++)
         if (backends[i]->type == type)
             return backends[i];

diff --git a/src/storage_backend_fs.c b/src/storage_backend_fs.c
index c3bda71..2ea9f93 100644
--- a/src/storage_backend_fs.c
+++ b/src/storage_backend_fs.c
@@ -210,7 +210,7 @@ static int virStorageBackendProbeFile(virConnectPtr conn,
     close(fd);

     /* First check file magic */
-    for (i = 0 ; i < sizeof(fileTypeInfo)/sizeof(fileTypeInfo[0]) ; i++) {
+    for (i = 0 ; i < ARRAY_CARDINALITY(fileTypeInfo) ; i++) {
         int mlen;
         if (fileTypeInfo[i].magic == NULL)
             continue;
@@ -276,7 +276,7 @@ static int virStorageBackendProbeFile(virConnectPtr conn,
     }

     /* No magic, so check file extension */
-    for (i = 0 ; i < sizeof(fileTypeInfo)/sizeof(fileTypeInfo[0]) ; i++) {
+    for (i = 0 ; i < ARRAY_CARDINALITY(fileTypeInfo) ; i++) {
         if (fileTypeInfo[i].extension == NULL)
             continue;

diff --git a/src/xen_internal.c b/src/xen_internal.c
index 5e34c25..72c61eb 100644
--- a/src/xen_internal.c
+++ b/src/xen_internal.c
@@ -29,6 +29,7 @@
 #include "xs_internal.h"
 #include "stats_linux.h"
 #include "xend_internal.h"
+#include "util.h"

 /* required for dom0_getdomaininfo_t */
 #include <xen/dom0_ops.h>
@@ -2345,7 +2346,7 @@ xenHypervisorMakeCapabilitiesInternal(virConnectPtr conn,
                 }

                 /* Too many arch flavours - highly unlikely ! */
-                if (i >= sizeof(guest_archs)/sizeof(guest_archs[0]))
+                if (i >= ARRAY_CARDINALITY(guest_archs))
                     continue;
                 /* Didn't find a match, so create a new one */
                 if (i == nr_guest_archs)
diff --git a/src/xend_internal.c b/src/xend_internal.c
index 21f1f1a..bad9de3 100644
--- a/src/xend_internal.c
+++ b/src/xend_internal.c
@@ -2312,7 +2312,7 @@ xenDaemonParseSxpr(virConnectPtr conn,
     if (hvm) {
         const char *const fds[] = { "fda", "fdb" };
         int i;
-        for (i = 0 ; i < sizeof(fds)/sizeof(fds[0]) ; i++) {
+        for (i = 0 ; i < ARRAY_CARDINALITY(fds) ; i++) {
             tmp = sexpr_fmt_node(root, "domain/image/hvm/%s", fds[i]);
             if ((tmp != NULL) && (tmp[0] != 0)) {
                 virDomainDiskDefPtr disk;
diff --git a/tests/nodeinfotest.c b/tests/nodeinfotest.c
index 2e0274a..66f60d9 100644
--- a/tests/nodeinfotest.c
+++ b/tests/nodeinfotest.c
@@ -8,6 +8,7 @@
 #include "testutils.h"
 #include "internal.h"
 #include "nodeinfo.h"
+#include "util.h"

 static char *progname;
 static char *abs_srcdir;
@@ -95,7 +96,7 @@ mymain(int argc, char **argv)

     virInitialize();

-    for (i = 0 ; i < (sizeof(nodeData)/sizeof(nodeData[0])) ; i++)
+    for (i = 0 ; i < ARRAY_CARDINALITY(nodeData); i++)
       if (virtTestRun(nodeData[i], 1, linuxTestNodeInfo, nodeData[i]) != 0)
         ret = -1;
 #endif
diff --git a/tests/qparamtest.c b/tests/qparamtest.c
index b85a29f..f8f2d29 100644
--- a/tests/qparamtest.c
+++ b/tests/qparamtest.c
@@ -193,7 +193,7 @@ mymain(int argc ATTRIBUTE_UNUSED,
         struct qparamParseData info = {                                 \
             queryIn,                                                    \
             queryOut ? queryOut : queryIn,                              \
-            sizeof(params)/sizeof(params[0]),                           \
+            ARRAY_CARDINALITY(params),                                  \
             params };                                                   \
         if (virtTestRun("Parse " queryIn,                               \
                         1, qparamParseTest, &info) < 0)                 \
-- 
1.6.0.3.756.gb776d

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[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]