Silence some false positive warnings for gcc 4.7

Message ID 1453327970-4275-1-git-send-email-cmetcalf@ezchip.com
State Committed
Headers

Commit Message

Chris Metcalf Jan. 20, 2016, 10:12 p.m. UTC
  Good to push to master?

2016-01-20  Chris Metcalf  <cmetcalf@ezchip.com>

	* nis/nis_table.c (__follow_path): Disable diagnostic for
	uninitialized variable that is a false positive for gcc 4.7.
	* stdio-common/vfscanf.c (_IO_vfwscanf): Likewise.
  

Comments

Stefan Liebler Jan. 21, 2016, 8:11 a.m. UTC | #1
Hi,

I got the same werrors when building with a gcc 4.7.4 on s390x.
After applying the patch, glibc builds without an werror.

Bye
Stefan

On 01/20/2016 11:12 PM, Chris Metcalf wrote:
> Good to push to master?
>
> 2016-01-20  Chris Metcalf  <cmetcalf@ezchip.com>
>
> 	* nis/nis_table.c (__follow_path): Disable diagnostic for
> 	uninitialized variable that is a false positive for gcc 4.7.
> 	* stdio-common/vfscanf.c (_IO_vfwscanf): Likewise.
>
> diff --git a/nis/nis_table.c b/nis/nis_table.c
> index 2831164a191b..1d607a49c4e9 100644
> --- a/nis/nis_table.c
> +++ b/nis/nis_table.c
> @@ -19,6 +19,7 @@
>   #include <assert.h>
>   #include <string.h>
>   #include <rpcsvc/nis.h>
> +#include <libc-internal.h>
>
>   #include "nis_xdr.h"
>   #include "nis_intern.h"
> @@ -175,6 +176,12 @@ __follow_path (char **tablepath, char **tableptr, struct ib_request *ibreq,
>
>         *tableptr = *tablepath;
>       }
> +
> +  /* Since tableptr is only set here, and it's set when tablepath is NULL,
> +     which it is initially defined as, we know it will always be set here.  */
> +  DIAG_PUSH_NEEDS_COMMENT;
> +  DIAG_IGNORE_NEEDS_COMMENT (4.7, "-Wmaybe-uninitialized");
> +
>     if (*tableptr == NULL)
>       return NIS_NOTFOUND;
>
> @@ -182,6 +189,8 @@ __follow_path (char **tablepath, char **tableptr, struct ib_request *ibreq,
>     if (newname[0] == '\0')
>       return NIS_NOTFOUND;
>
> +  DIAG_POP_NEEDS_COMMENT;
> +
>     newname = strdup (newname);
>     if (newname == NULL)
>       return NIS_NOMEMORY;
> diff --git a/stdio-common/vfscanf.c b/stdio-common/vfscanf.c
> index f8f97cd1d2cd..8cd59557a698 100644
> --- a/stdio-common/vfscanf.c
> +++ b/stdio-common/vfscanf.c
> @@ -27,6 +27,7 @@
>   #include <string.h>
>   #include <wchar.h>
>   #include <wctype.h>
> +#include <libc-internal.h>
>   #include <libc-lock.h>
>   #include <locale/localeinfo.h>
>   #include <scratch_buffer.h>
> @@ -1535,6 +1536,13 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
>   		    {
>   		      /* Get the string for the digits with value N.  */
>   #ifdef COMPILE_WSCANF
> +
> +		      /* wcdigits_extended[] is fully set in the loop
> +			 above, but the test for "map != NULL" is done
> +			 inside the loop here and outside the loop there.  */
> +		      DIAG_PUSH_NEEDS_COMMENT;
> +		      DIAG_IGNORE_NEEDS_COMMENT (4.7, "-Wmaybe-uninitialized");
> +
>   		      if (__glibc_unlikely (map != NULL))
>   			wcdigits[n] = wcdigits_extended[n];
>   		      else
> @@ -1542,6 +1550,8 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
>   			  _NL_CURRENT (LC_CTYPE, _NL_CTYPE_INDIGITS0_WC + n);
>   		      wcdigits[n] += from_level;
>
> +		      DIAG_POP_NEEDS_COMMENT;
> +
>   		      if (c == (wint_t) *wcdigits[n])
>   			{
>   			  to_level = from_level;
>
  
Adhemerval Zanella Netto Jan. 21, 2016, 1:48 p.m. UTC | #2
LGTM, thanks.

On 20-01-2016 20:12, Chris Metcalf wrote:
> Good to push to master?
> 
> 2016-01-20  Chris Metcalf  <cmetcalf@ezchip.com>
> 
> 	* nis/nis_table.c (__follow_path): Disable diagnostic for
> 	uninitialized variable that is a false positive for gcc 4.7.
> 	* stdio-common/vfscanf.c (_IO_vfwscanf): Likewise.
> 
> diff --git a/nis/nis_table.c b/nis/nis_table.c
> index 2831164a191b..1d607a49c4e9 100644
> --- a/nis/nis_table.c
> +++ b/nis/nis_table.c
> @@ -19,6 +19,7 @@
>  #include <assert.h>
>  #include <string.h>
>  #include <rpcsvc/nis.h>
> +#include <libc-internal.h>
>  
>  #include "nis_xdr.h"
>  #include "nis_intern.h"
> @@ -175,6 +176,12 @@ __follow_path (char **tablepath, char **tableptr, struct ib_request *ibreq,
>  
>        *tableptr = *tablepath;
>      }
> +
> +  /* Since tableptr is only set here, and it's set when tablepath is NULL,
> +     which it is initially defined as, we know it will always be set here.  */
> +  DIAG_PUSH_NEEDS_COMMENT;
> +  DIAG_IGNORE_NEEDS_COMMENT (4.7, "-Wmaybe-uninitialized");
> +
>    if (*tableptr == NULL)
>      return NIS_NOTFOUND;
>  
> @@ -182,6 +189,8 @@ __follow_path (char **tablepath, char **tableptr, struct ib_request *ibreq,
>    if (newname[0] == '\0')
>      return NIS_NOTFOUND;
>  
> +  DIAG_POP_NEEDS_COMMENT;
> +
>    newname = strdup (newname);
>    if (newname == NULL)
>      return NIS_NOMEMORY;
> diff --git a/stdio-common/vfscanf.c b/stdio-common/vfscanf.c
> index f8f97cd1d2cd..8cd59557a698 100644
> --- a/stdio-common/vfscanf.c
> +++ b/stdio-common/vfscanf.c
> @@ -27,6 +27,7 @@
>  #include <string.h>
>  #include <wchar.h>
>  #include <wctype.h>
> +#include <libc-internal.h>
>  #include <libc-lock.h>
>  #include <locale/localeinfo.h>
>  #include <scratch_buffer.h>
> @@ -1535,6 +1536,13 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
>  		    {
>  		      /* Get the string for the digits with value N.  */
>  #ifdef COMPILE_WSCANF
> +
> +		      /* wcdigits_extended[] is fully set in the loop
> +			 above, but the test for "map != NULL" is done
> +			 inside the loop here and outside the loop there.  */
> +		      DIAG_PUSH_NEEDS_COMMENT;
> +		      DIAG_IGNORE_NEEDS_COMMENT (4.7, "-Wmaybe-uninitialized");
> +
>  		      if (__glibc_unlikely (map != NULL))
>  			wcdigits[n] = wcdigits_extended[n];
>  		      else
> @@ -1542,6 +1550,8 @@ _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
>  			  _NL_CURRENT (LC_CTYPE, _NL_CTYPE_INDIGITS0_WC + n);
>  		      wcdigits[n] += from_level;
>  
> +		      DIAG_POP_NEEDS_COMMENT;
> +
>  		      if (c == (wint_t) *wcdigits[n])
>  			{
>  			  to_level = from_level;
>
  

Patch

diff --git a/nis/nis_table.c b/nis/nis_table.c
index 2831164a191b..1d607a49c4e9 100644
--- a/nis/nis_table.c
+++ b/nis/nis_table.c
@@ -19,6 +19,7 @@ 
 #include <assert.h>
 #include <string.h>
 #include <rpcsvc/nis.h>
+#include <libc-internal.h>
 
 #include "nis_xdr.h"
 #include "nis_intern.h"
@@ -175,6 +176,12 @@  __follow_path (char **tablepath, char **tableptr, struct ib_request *ibreq,
 
       *tableptr = *tablepath;
     }
+
+  /* Since tableptr is only set here, and it's set when tablepath is NULL,
+     which it is initially defined as, we know it will always be set here.  */
+  DIAG_PUSH_NEEDS_COMMENT;
+  DIAG_IGNORE_NEEDS_COMMENT (4.7, "-Wmaybe-uninitialized");
+
   if (*tableptr == NULL)
     return NIS_NOTFOUND;
 
@@ -182,6 +189,8 @@  __follow_path (char **tablepath, char **tableptr, struct ib_request *ibreq,
   if (newname[0] == '\0')
     return NIS_NOTFOUND;
 
+  DIAG_POP_NEEDS_COMMENT;
+
   newname = strdup (newname);
   if (newname == NULL)
     return NIS_NOMEMORY;
diff --git a/stdio-common/vfscanf.c b/stdio-common/vfscanf.c
index f8f97cd1d2cd..8cd59557a698 100644
--- a/stdio-common/vfscanf.c
+++ b/stdio-common/vfscanf.c
@@ -27,6 +27,7 @@ 
 #include <string.h>
 #include <wchar.h>
 #include <wctype.h>
+#include <libc-internal.h>
 #include <libc-lock.h>
 #include <locale/localeinfo.h>
 #include <scratch_buffer.h>
@@ -1535,6 +1536,13 @@  _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
 		    {
 		      /* Get the string for the digits with value N.  */
 #ifdef COMPILE_WSCANF
+
+		      /* wcdigits_extended[] is fully set in the loop
+			 above, but the test for "map != NULL" is done
+			 inside the loop here and outside the loop there.  */
+		      DIAG_PUSH_NEEDS_COMMENT;
+		      DIAG_IGNORE_NEEDS_COMMENT (4.7, "-Wmaybe-uninitialized");
+
 		      if (__glibc_unlikely (map != NULL))
 			wcdigits[n] = wcdigits_extended[n];
 		      else
@@ -1542,6 +1550,8 @@  _IO_vfscanf_internal (_IO_FILE *s, const char *format, _IO_va_list argptr,
 			  _NL_CURRENT (LC_CTYPE, _NL_CTYPE_INDIGITS0_WC + n);
 		      wcdigits[n] += from_level;
 
+		      DIAG_POP_NEEDS_COMMENT;
+
 		      if (c == (wint_t) *wcdigits[n])
 			{
 			  to_level = from_level;