changeset 16275:053f5a861da8

inet_ntop: guard extra work by IF_LINT 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>
author Eric Blake <eblake@redhat.com>
date Thu, 12 Jan 2012 08:44:08 -0700
parents 2c5c6ce1dba4
children d43b527a2e6c
files ChangeLog lib/inet_ntop.c
diffstat 2 files changed, 17 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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.
--- a/lib/inet_ntop.c
+++ b/lib/inet_ntop.c
@@ -38,6 +38,16 @@
 /* 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 @@
   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)