[PATCH] Replacing for (; ; ) with while (1) for better code.

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

 



As mentioned in https://libvirt.org/hacking.html,
using while (1) is better than for (;;).
---
 src/libvirt-stream.c            | 4 ++--
 src/phyp/phyp_driver.c          | 2 +-
 src/qemu/qemu_migration.c       | 2 +-
 src/remote/remote_driver.c      | 2 +-
 src/rpc/virnetclient.c          | 6 +++---
 src/security/security_selinux.c | 2 +-
 src/util/vircgroup.c            | 2 +-
 src/util/vircommand.c           | 2 +-
 src/util/virdbus.c              | 4 ++--
 src/util/virfile.c              | 2 +-
 tests/commandhelper.c           | 2 +-
 11 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/libvirt-stream.c b/src/libvirt-stream.c
index 8384b37..41daaa1 100644
--- a/src/libvirt-stream.c
+++ b/src/libvirt-stream.c
@@ -349,7 +349,7 @@ virStreamSendAll(virStreamPtr stream,
     if (VIR_ALLOC_N(bytes, want) < 0)
         goto cleanup;
 
-    for (;;) {
+    while (1) {
         int got, offset = 0;
         got = (handler)(stream, bytes, want, opaque);
         if (got < 0) {
@@ -443,7 +443,7 @@ virStreamRecvAll(virStreamPtr stream,
     if (VIR_ALLOC_N(bytes, want) < 0)
         goto cleanup;
 
-    for (;;) {
+    while (1) {
         int got, offset = 0;
         got = virStreamRecv(stream, bytes, want);
         if (got < 0)
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index 3dd8927..50cf1ae 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -187,7 +187,7 @@ phypExec(LIBSSH2_SESSION *session, const char *cmd, int *exit_status,
     if (rc != 0)
         goto err;
 
-    for (;;) {
+    while (1) {
         /* loop until we block */
         do {
             rc = libssh2_channel_read(channel, buffer, buffer_size);
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 8a220d9..bc7d268 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -4398,7 +4398,7 @@ static void qemuMigrationIOFunc(void *arg)
     fds[0].fd = data->sock;
     fds[1].fd = data->wakeupRecvFD;
 
-    for (;;) {
+    while (1) {
         int ret;
 
         fds[0].events = fds[1].events = POLLIN;
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 3b8b796..b0c4440 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -4055,7 +4055,7 @@ remoteAuthSASL(virConnectPtr conn, struct private_data *priv,
     /* Loop-the-loop...
      * Even if the server has completed, the client must *always* do at least one step
      * in this loop to verify the server isn't lying about something. Mutual auth */
-    for (;;) {
+    while (1) {
         if ((err = virNetSASLSessionClientStep(sasl,
                                                serverin,
                                                serverinlen,
diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 361dc1a..f3457be 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -777,7 +777,7 @@ int virNetClientSetTLSSession(virNetClientPtr client,
 
     virNetSocketSetTLSSession(client->sock, client->tls);
 
-    for (;;) {
+    while (1) {
         ret = virNetTLSSessionHandshake(client->tls);
 
         if (ret < 0)
@@ -1258,7 +1258,7 @@ virNetClientIOHandleInput(virNetClientPtr client)
     /* Read as much data as is available, until we get
      * EAGAIN
      */
-    for (;;) {
+    while (1) {
         ssize_t ret;
 
         if (client->msg.nfds == 0) {
@@ -1463,7 +1463,7 @@ static int virNetClientIOEventLoop(virNetClientPtr client,
     fds[0].fd = virNetSocketGetFD(client->sock);
     fds[1].fd = client->wakeupReadFD;
 
-    for (;;) {
+    while (1) {
         char ignore;
         sigset_t oldmask, blockedsigs;
         int timeout = -1;
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index 4be946d..153e6e9 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -137,7 +137,7 @@ virSecuritySELinuxMCSFind(virSecurityManagerPtr mgr,
     VIR_DEBUG("Using sensitivity level '%s' cat min %d max %d range %d",
               sens, catMin, catMax, catRange);
 
-    for (;;) {
+    while (1) {
         int c1 = virRandomInt(catRange);
         int c2 = virRandomInt(catRange);
 
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 8b52816..cc83cf7 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -1587,7 +1587,7 @@ virCgroupNewMachineSystemd(const char *name,
         goto cleanup;
 
 
-    for (;;) {
+    while (1) {
         virCgroupPtr tmp;
         char *t = strchr(offset + 1, '/');
         if (t)
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 2a59bd1..bfc130d 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -2033,7 +2033,7 @@ virCommandProcessIO(virCommandPtr cmd)
         goto cleanup;
     ret = -1;
 
-    for (;;) {
+    while (1) {
         size_t i;
         struct pollfd fds[3];
         int nfds = 0;
diff --git a/src/util/virdbus.c b/src/util/virdbus.c
index 3f4dbe3..413229c 100644
--- a/src/util/virdbus.c
+++ b/src/util/virdbus.c
@@ -627,7 +627,7 @@ virDBusMessageIterEncode(DBusMessageIter *rootiter,
     narray = (size_t)-1;
     nstruct = strlen(types);
 
-    for (;;) {
+    while (1) {
         const char *t;
 
         VIR_DEBUG("Loop nstack=%zu narray=%zd nstruct=%zu types='%s'",
@@ -904,7 +904,7 @@ virDBusMessageIterDecode(DBusMessageIter *rootiter,
     narray = (size_t)-1;
     nstruct = strlen(types);
 
-    for (;;) {
+    while (1) {
         const char *t;
         bool advanceiter = true;
 
diff --git a/src/util/virfile.c b/src/util/virfile.c
index a45279a..f246b29 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -1269,7 +1269,7 @@ saferead_lim(int fd, size_t max_len, size_t *length)
     size_t size = 0;
     int save_errno;
 
-    for (;;) {
+    while (1) {
         int count;
         int requested;
 
diff --git a/tests/commandhelper.c b/tests/commandhelper.c
index 015efda..5a77108 100644
--- a/tests/commandhelper.c
+++ b/tests/commandhelper.c
@@ -138,7 +138,7 @@ int main(int argc, char **argv) {
     fprintf(stderr, "BEGIN STDERR\n");
     fflush(stderr);
 
-    for (;;) {
+    while (1) {
         got = read(STDIN_FILENO, buf, sizeof(buf));
         if (got < 0)
             goto cleanup;
-- 
2.1.0

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