summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2008-11-30 22:37:42 +0100
committerJim Meyering <meyering@redhat.com>2008-12-01 21:18:52 +0100
commitc58b5daa337b16416be50adfeb3e99e3c009c891 (patch)
treeed91dec7768322eb9f09427036069239b210f562 /src
parent80325aca2dc20c9f6ac0ac51fdfb2a12aee565eb (diff)
downloadcoreutils-c58b5daa337b16416be50adfeb3e99e3c009c891.tar.xz
avoid warnings about initialization of automatic aggregates
* 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.
Diffstat (limited to 'src')
-rw-r--r--src/ls.c2
-rw-r--r--src/pathchk.c2
-rw-r--r--src/shred.c2
-rw-r--r--src/stty.c4
-rw-r--r--src/system.h13
-rw-r--r--src/wc.c2
6 files changed, 19 insertions, 6 deletions
diff --git a/src/ls.c b/src/ls.c
index 7619cebc1..008186595 100644
--- 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;
diff --git a/src/pathchk.c b/src/pathchk.c
index 48001fc03..3b2bd467b 100644
--- a/src/pathchk.c
+++ b/src/pathchk.c
@@ -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"),
diff --git a/src/shred.c b/src/shred.c
index 6b7d90167..1e7bffb90 100644
--- a/src/shred.c
+++ b/src/shred.c
@@ -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;
diff --git a/src/stty.c b/src/stty.c
index 8eeaa2fed..eb4f30f07 100644
--- a/src/stty.c
+++ b/src/stty.c
@@ -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);
diff --git a/src/system.h b/src/system.h
index d51caedf1..21182a47f 100644
--- a/src/system.h
+++ b/src/system.h
@@ -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 */
diff --git a/src/wc.c b/src/wc.c
index 8cfd974ca..ad25ed8d0 100644
--- 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