From 0764a0a97bb929593031f74db3cc8f7ea2b6df3b Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 12 Jan 2012 08:44:08 -0700 Subject: [PATCH] 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 --- ChangeLog | 5 +++++ lib/inet_ntop.c | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index dabbd8df9..6b987ad4b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2012-01-12 Eric Blake + 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. diff --git a/lib/inet_ntop.c b/lib/inet_ntop.c index d7e6b232f..527b8a80e 100644 --- a/lib/inet_ntop.c +++ b/lib/inet_ntop.c @@ -38,6 +38,16 @@ /* Specification. */ #include +/* 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) -- 2.11.0