bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] af_alg: Pacify --enable-gcc-warnings on GCC 8


From: Paul Eggert
Subject: [PATCH] af_alg: Pacify --enable-gcc-warnings on GCC 8
Date: Wed, 9 May 2018 10:40:27 -0700

* lib/af_alg.c (afalg_buffer, afalg_stream): Reorder local decls
and checking to pacify gcc -Wjump-misses-init on GCC 8.
---
 ChangeLog    |  6 ++++++
 lib/af_alg.c | 40 +++++++++++++++++-----------------------
 2 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 428897fa3..41bc0fbac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2018-05-09  Paul Eggert  <address@hidden>
+
+       af_alg: Pacify --enable-gcc-warnings on GCC 8
+       * lib/af_alg.c (afalg_buffer, afalg_stream): Reorder local decls
+       and checking to pacify gcc -Wjump-misses-init on GCC 8.
+
 2018-05-07  Paul Eggert  <address@hidden>
 
        af_alg: Pacify --enable-gcc-warnings
diff --git a/lib/af_alg.c b/lib/af_alg.c
index c9809c70e..81f506e7a 100644
--- a/lib/af_alg.c
+++ b/lib/af_alg.c
@@ -40,15 +40,13 @@ int
 afalg_buffer (const char *buffer, size_t len, const char *alg,
               void *resblock, ssize_t hashlen)
 {
+  int ofd;
+
   /* On Linux < 4.9, the value for an empty stream is wrong (all zeroes).
      See <https://patchwork.kernel.org/patch/9308641/>.  */
   if (len == 0)
     return -EAFNOSUPPORT;
 
-  int cfd = socket (AF_ALG, SOCK_SEQPACKET, 0);
-  if (cfd < 0)
-    return -EAFNOSUPPORT;
-
   int result;
   struct sockaddr_alg salg = {
     .salg_family = AF_ALG,
@@ -57,19 +55,19 @@ afalg_buffer (const char *buffer, size_t len, const char 
*alg,
   /* Avoid calling both strcpy and strlen.  */
   for (int i = 0; (salg.salg_name[i] = alg[i]); i++)
     if (i == sizeof salg.salg_name - 1)
-      {
-        result = -EINVAL;
-        goto out_cfd;
-      }
+      return -EINVAL;
+
+  int cfd = socket (AF_ALG, SOCK_SEQPACKET, 0);
+  if (cfd < 0)
+    return -EAFNOSUPPORT;
 
-  int ret = bind (cfd, (struct sockaddr *) &salg, sizeof salg);
-  if (ret != 0)
+  if (bind (cfd, (struct sockaddr *) &salg, sizeof salg) != 0)
     {
       result = -EAFNOSUPPORT;
       goto out_cfd;
     }
 
-  int ofd = accept (cfd, NULL, 0);
+  ofd = accept (cfd, NULL, 0);
   if (ofd < 0)
     {
       result = -EAFNOSUPPORT;
@@ -105,11 +103,7 @@ int
 afalg_stream (FILE *stream, const char *alg,
               void *resblock, ssize_t hashlen)
 {
-  int cfd = socket (AF_ALG, SOCK_SEQPACKET, 0);
-  if (cfd < 0)
-    return -EAFNOSUPPORT;
-
-  int fd;
+  int fd, ofd;
   struct stat st;
 
   int result;
@@ -120,19 +114,19 @@ afalg_stream (FILE *stream, const char *alg,
   /* Avoid calling both strcpy and strlen.  */
   for (int i = 0; (salg.salg_name[i] = alg[i]); i++)
     if (i == sizeof salg.salg_name - 1)
-      {
-        result = -EINVAL;
-        goto out_cfd;
-      }
+      return -EINVAL;
+
+  int cfd = socket (AF_ALG, SOCK_SEQPACKET, 0);
+  if (cfd < 0)
+    return -EAFNOSUPPORT;
 
-  int ret = bind (cfd, (struct sockaddr *) &salg, sizeof salg);
-  if (ret != 0)
+  if (bind (cfd, (struct sockaddr *) &salg, sizeof salg) != 0)
     {
       result = -EAFNOSUPPORT;
       goto out_cfd;
     }
 
-  int ofd = accept (cfd, NULL, 0);
+  ofd = accept (cfd, NULL, 0);
   if (ofd < 0)
     {
       result = -EAFNOSUPPORT;
-- 
2.17.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]