]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
avoid warnings about initialization of automatic aggregates
authorJim Meyering <meyering@redhat.com>
Sun, 30 Nov 2008 21:37:42 +0000 (22:37 +0100)
committerJim Meyering <meyering@redhat.com>
Mon, 1 Dec 2008 20:18:52 +0000 (21:18 +0100)
* src/system.h (DZA_CONCAT0, DZA_CONCAT): New macros.
(DECLARE_ZEROED_AGGREGATE): New macro.
* src/ls.c (quote_name): Use it.
* src/pathchk.c (portable_chars_only): Use it.
* src/shred.c (main): Use it.
* src/stty.c (main): Use it.
* src/wc.c (SUPPORT_OLD_MBRTOWC): Use it.

src/ls.c
src/pathchk.c
src/shred.c
src/stty.c
src/system.h
src/wc.c

index 7619cebc1aff7a85926529331dae96703075dcc9..0081865955e0cb1cdcba2ba10e001400f9dae827 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -3721,7 +3721,7 @@ 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, };
+                   DECLARE_ZEROED_AGGREGATE (mbstate_t, mbstate);
                    do
                      {
                        wchar_t wc;
index 48001fc03d73f9a03e3ba1d43f42456759fd5eaf..3b2bd467b61a5a083511d7cd044808f032fdd688 100644 (file)
@@ -198,7 +198,7 @@ portable_chars_only (char const *file, size_t filelen)
 
   if (*invalid)
     {
-      mbstate_t mbstate = { 0, };
+      DECLARE_ZEROED_AGGREGATE (mbstate_t, mbstate);
       size_t charlen = mbrlen (invalid, filelen - validlen, &mbstate);
       error (0, 0,
             _("nonportable character %s in file name %s"),
index 6b7d9016750ec62e306a195b8f6fd592383b3712..1e7bffb9065efa00347bb33eabeb419e8b8469b1 100644 (file)
@@ -1099,7 +1099,7 @@ int
 main (int argc, char **argv)
 {
   bool ok = true;
-  struct Options flags = { 0, };
+  DECLARE_ZEROED_AGGREGATE (struct Options, flags);
   char **file;
   int n_files;
   int c;
index 8eeaa2fed47f72f8f198a105745eddb53515eab1..eb4f30f073d9d1562152d6ad4a0554b4c8f6f8c3 100644 (file)
@@ -726,7 +726,7 @@ 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, };
+  DECLARE_ZEROED_AGGREGATE (struct termios, mode);
 
   enum output_type output_type;
   int optc;
@@ -999,7 +999,7 @@ 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, };
+      DECLARE_ZEROED_AGGREGATE (struct termios, new_mode);
 
       if (tcsetattr (STDIN_FILENO, TCSADRAIN, &mode))
        error (EXIT_FAILURE, errno, "%s", device_name);
index d51caedf118ee411a7e41f61f044e4235c860448..21182a47f0c7ad919c532307ceb7a43cbc787a17 100644 (file)
@@ -513,6 +513,19 @@ enum
 # define IF_LINT(Code) /* empty */
 #endif
 
+/* With -Dlint, avoid warnings from gcc about code like mbstate_t m = {0,};
+   by wasting space on a static variable of the same type, that is thus
+   guaranteed to be initialized to 0, and use that on the RHS.  */
+#define DZA_CONCAT0(x,y) x ## y
+#define DZA_CONCAT(x,y) DZA_CONCAT0 (x, y)
+#ifdef lint
+# define DECLARE_ZEROED_AGGREGATE(Type, Var) \
+   static Type DZA_CONCAT (s0_, __LINE__); Type Var = DZA_CONCAT (s0_, __LINE__)
+#else
+# define DECLARE_ZEROED_AGGREGATE(Type, Var) \
+  Type Var = { 0, }
+#endif
+
 #ifndef __attribute__
 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
 #  define __attribute__(x) /* empty */
index 8cfd974cacfe0a04a9b0caa4f730715087b3e843..ad25ed8d0570e2ad663a34fbe745b5b0ff2b1c43 100644 (file)
--- a/src/wc.c
+++ b/src/wc.c
@@ -275,7 +275,7 @@ wc (int fd, char const *file_x, struct fstatus *fstatus)
     {
       bool in_word = false;
       uintmax_t linepos = 0;
-      mbstate_t state = { 0, };
+      DECLARE_ZEROED_AGGREGATE (mbstate_t, state);
       bool in_shift = false;
 # if SUPPORT_OLD_MBRTOWC
       /* Back-up the state before each multibyte character conversion and