coreutils
[Top][All Lists]
Advanced

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

ls, pathchk, shred, stty, wc: warning: missing initializer [-Wmissing-fi


From: Bernhard Voelker
Subject: ls, pathchk, shred, stty, wc: warning: missing initializer [-Wmissing-field-initializers]
Date: Fri, 23 Mar 2012 19:31:24 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.2) Gecko/20120215 Thunderbird/10.0.2

According to the comment of commit v8.12-20-g73fd918:

    maint: remove -Wmissing-field-initializers workarounds

    * configure.ac: Rather than disabling -Wmissing-field-initializers,
    use the fact that gnulib now disables it automatically when required
    (on versions of GCC older than 4.7).
    * src/system.h: Remove the no longer needed DECLARE_ZEROED_AGGREGATE.
    * src/ls.c: Likewise.
    * src/pathchk.c: Likewise.
    * src/shred.c: Likewise.
    * src/stty.c: Likewise.
    * src/wc.c: Likewise.

these warnings should not happen:

  stty.c: In function 'main':
  stty.c:732:10: warning: missing initializer [-Wmissing-field-initializers]
  stty.c:732:10: warning: (near initialization for 'mode.c_oflag') 
[-Wmissing-field-initializers]
  stty.c:1005:14: warning: missing initializer [-Wmissing-field-initializers]
  stty.c:1005:14: warning: (near initialization for 'new_mode.c_oflag') 
[-Wmissing-field-initializers]
  ls.c: In function 'quote_name':
  ls.c:4046:21: warning: missing initializer [-Wmissing-field-initializers]
  ls.c:4046:21: warning: (near initialization for 'mbstate.__value') 
[-Wmissing-field-initializers]
  pathchk.c: In function 'portable_chars_only':
  pathchk.c:193:7: warning: missing initializer [-Wmissing-field-initializers]
  pathchk.c:193:7: warning: (near initialization for 'mbstate.__value') 
[-Wmissing-field-initializers]
  shred.c: In function 'main':
  shred.c:1094:10: warning: missing initializer [-Wmissing-field-initializers]
  shred.c:1094:10: warning: (near initialization for 'flags.n_iterations') 
[-Wmissing-field-initializers]
  wc.c: In function 'wc':
  wc.c:289:7: warning: missing initializer [-Wmissing-field-initializers]
  wc.c:289:7: warning: (near initialization for 'state.__value') 
[-Wmissing-field-initializers]

But they do: the compiler used on that system (OpenSuSE-12.1) is
"gcc (SUSE Linux) 4.6.2". As these are the only warnings here when
using --enable-gcc-warnings, shouldn't we go with a more conservative
memset? See patch proposal below.

Have a nice day,
Berny


>From f9fe9b71b5e87ec63eb37d5fcef5691a466f1920 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <address@hidden>
Date: Fri, 23 Mar 2012 19:21:18 +0100
Subject: [PATCH] maint: explicitly init structs to avoid
 -Wmissing-field-initializers

According to commit v8.12-20-g73fd918, the "missing initializer"
warnings should not occur anymore for gcc versions older than 4.7;
but these warnings have been seen at least on gcc 4.6.2 on
OpenSuSE 12.1. The following changes avoid these warnings by
explicitly initializing all struct members to zero using memset.

* src/ls.c (quote_name): Initialize mbstate_t structure.
* src/pathchk.c (portable_chars_only): Likewise.
* src/wc.c (wc): Likewise.
* src/shred.c (main): Likewise for the flags structure.
* src/stty.c (main): Likewise for mode and new_mode structure.
---
 src/ls.c      |    3 ++-
 src/pathchk.c |    3 ++-
 src/shred.c   |    3 ++-
 src/stty.c    |    6 ++++--
 src/wc.c      |    3 ++-
 5 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/ls.c b/src/ls.c
index f1dfb1e..fa0f54a 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -4043,7 +4043,8 @@ quote_name (FILE *out, const char *name, struct 
quoting_options const *options,
                      reach its end, replacing each non-printable multibyte
                      character with a single question mark.  */
                   {
-                    mbstate_t mbstate = { 0, };
+                    mbstate_t mbstate;
+                    memset (&mbstate, 0, sizeof (mbstate));
                     do
                       {
                         wchar_t wc;
diff --git a/src/pathchk.c b/src/pathchk.c
index 194de22..b119dc0 100644
--- a/src/pathchk.c
+++ b/src/pathchk.c
@@ -190,7 +190,8 @@ portable_chars_only (char const *file, size_t filelen)

   if (*invalid)
     {
-      mbstate_t mbstate = { 0, };
+      mbstate_t mbstate;
+      memset (&mbstate, 0, sizeof (mbstate));
       size_t charlen = mbrlen (invalid, filelen - validlen, &mbstate);
       error (0, 0,
              _("nonportable character %s in file name %s"),
diff --git a/src/shred.c b/src/shred.c
index 7a28260..882498e 100644
--- a/src/shred.c
+++ b/src/shred.c
@@ -1091,7 +1091,7 @@ int
 main (int argc, char **argv)
 {
   bool ok = true;
-  struct Options flags = { 0, };
+  struct Options flags;
   char **file;
   int n_files;
   int c;
@@ -1106,6 +1106,7 @@ main (int argc, char **argv)

   atexit (close_stdout);

+  memset (&flags, 0, sizeof (flags));
   flags.n_iterations = DEFAULT_PASSES;
   flags.size = -1;

diff --git a/src/stty.c b/src/stty.c
index 8e36593..c5ae11f 100644
--- a/src/stty.c
+++ b/src/stty.c
@@ -729,7 +729,8 @@ main (int argc, char **argv)
 {
   /* Initialize to all zeroes so there is no risk memcmp will report a
      spurious difference in an uninitialized portion of the structure.  */
-  struct termios mode = { 0, };
+  struct termios mode;
+  memset (&mode, 0, sizeof (mode));

   enum output_type output_type;
   int optc;
@@ -1002,7 +1003,8 @@ main (int argc, char **argv)
     {
       /* Initialize to all zeroes so there is no risk memcmp will report a
          spurious difference in an uninitialized portion of the structure.  */
-      struct termios new_mode = { 0, };
+      struct termios new_mode;
+      memset (&new_mode, 0, sizeof (new_mode));

       if (tcsetattr (STDIN_FILENO, TCSADRAIN, &mode))
         error (EXIT_FAILURE, errno, "%s", device_name);
diff --git a/src/wc.c b/src/wc.c
index 1b8a7a4..f2f2505 100644
--- a/src/wc.c
+++ b/src/wc.c
@@ -286,7 +286,8 @@ wc (int fd, char const *file_x, struct fstatus *fstatus)
     {
       bool in_word = false;
       uintmax_t linepos = 0;
-      mbstate_t state = { 0, };
+      mbstate_t state;
+      memset (&state, 0, sizeof (state));
       bool in_shift = false;
 # if SUPPORT_OLD_MBRTOWC
       /* Back-up the state before each multibyte character conversion and
-- 
1.7.7




reply via email to

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