inet_ntop: guard extra work by IF_LINT
authorEric Blake <eblake@redhat.com>
Thu, 12 Jan 2012 15:44:08 +0000 (08:44 -0700)
committerEric Blake <eblake@redhat.com>
Thu, 12 Jan 2012 15:52:21 +0000 (08:52 -0700)
No need to penalize the code just to silence a gcc warning, so
follow the conventions used elsewhere in gnulib.  Clients that
want to use extra warnings should also be using -Dlint.

* lib/inet_ntop.c (inet_ntop6): Mark spurious initialization, for
better code generation when not checking for warnings.
Suggested by Paul Eggert and Jim Meyering.

Signed-off-by: Eric Blake <eblake@redhat.com>
ChangeLog
lib/inet_ntop.c

index dabbd8d..6b987ad 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2012-01-12  Eric Blake  <eblake@redhat.com>
 
+       inet_ntop: guard extra work by IF_LINT
+       * lib/inet_ntop.c (inet_ntop6): Mark spurious initialization, for
+       better code generation when not checking for warnings.
+       Suggested by Paul Eggert and Jim Meyering.
+
        strptime: fix regression on mingw
        * lib/strptime.c (__strptime_internal) [!_LIBC && !HAVE_TM_GMTOFF]:
        Fix regression.  Reported by Bruno Haible.
index d7e6b23..527b8a8 100644 (file)
 /* Specification.  */
 #include <arpa/inet.h>
 
+/* Use this to suppress gcc's "...may be used before initialized" warnings.
+   Beware: The Code argument must not contain commas.  */
+#ifndef IF_LINT
+# ifdef lint
+#  define IF_LINT(Code) Code
+# else
+#  define IF_LINT(Code) /* empty */
+# endif
+#endif
+
 #if HAVE_DECL_INET_NTOP
 
 # undef inet_ntop
@@ -166,8 +176,9 @@ inet_ntop6 (const unsigned char *src, char *dst, socklen_t size)
   for (i = 0; i < NS_IN6ADDRSZ; i += 2)
     words[i / 2] = (src[i] << 8) | src[i + 1];
   best.base = -1;
-  best.len = 0;
   cur.base = -1;
+  IF_LINT(best.len = 0);
+  IF_LINT(cur.len = 0);
   for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++)
     {
       if (words[i] == 0)