summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2006-10-10 22:57:07 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2006-10-10 22:57:07 +0000
commite245a66054cac00f2916fbc9436d926ea2cf4d1c (patch)
treeb36a56e3bede31be2c78a76e0bfe7db73670587a
parent489ff7f0cdaa63403aefcce778ea7214dc4e6808 (diff)
downloadcoreutils-e245a66054cac00f2916fbc9436d926ea2cf4d1c.tar.xz
* src/ls.c (quote_name): Use initializer rather than memset to
initialize an object to zero. This is easier to read and is less likely to introduce an runtime error due to a mixup. It causes gcc -W to issue a warning, but you can work around this by appending -Wno-missing-field-initializers. * src/pathchk.c (portable_chars_only): Likewise. * src/shred.c (main): Likewise. * src/stty.c (main): Likewise. * src/tr.c (card_of_complement): Likewise. * src/wc.c (wc): Likewise.
-rw-r--r--ChangeLog13
-rw-r--r--src/ls.c3
-rw-r--r--src/pathchk.c7
-rw-r--r--src/shred.c4
-rw-r--r--src/stty.c15
-rw-r--r--src/tr.c3
-rw-r--r--src/wc.c3
7 files changed, 26 insertions, 22 deletions
diff --git a/ChangeLog b/ChangeLog
index 1f68ad226..625bc8d55 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2006-10-10 Paul Eggert <eggert@cs.ucla.edu>
+
+ * src/ls.c (quote_name): Use initializer rather than memset to
+ initialize an object to zero. This is easier to read and is less
+ likely to introduce an runtime error due to a mixup. It causes
+ gcc -W to issue a warning, but you can work around this by
+ appending -Wno-missing-field-initializers.
+ * src/pathchk.c (portable_chars_only): Likewise.
+ * src/shred.c (main): Likewise.
+ * src/stty.c (main): Likewise.
+ * src/tr.c (card_of_complement): Likewise.
+ * src/wc.c (wc): Likewise.
+
2006-10-09 Paul Eggert <eggert@cs.ucla.edu>
* src/sort.c (usage): Mention again that sort fields are origin 1.
diff --git a/src/ls.c b/src/ls.c
index 573f5f581..c63330ece 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -3604,8 +3604,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;
- memset (&mbstate, 0, sizeof mbstate);
+ mbstate_t mbstate = { 0, };
do
{
wchar_t wc;
diff --git a/src/pathchk.c b/src/pathchk.c
index 04b46d8a8..2fc55d346 100644
--- a/src/pathchk.c
+++ b/src/pathchk.c
@@ -200,11 +200,8 @@ portable_chars_only (char const *file, size_t filelen)
if (*invalid)
{
- mbstate_t mbstate;
- size_t charlen;
-
- memset (&mbstate, 0, sizeof mbstate);
- charlen = mbrlen (invalid, filelen - validlen, &mbstate);
+ mbstate_t mbstate = { 0, };
+ size_t charlen = mbrlen (invalid, filelen - validlen, &mbstate);
error (0, 0,
_("nonportable character %s in file name %s"),
quotearg_n_style_mem (1, locale_quoting_style, invalid,
diff --git a/src/shred.c b/src/shred.c
index d3b1c4a9c..4c1819ccb 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;
+ struct Options flags = { 0, };
char **file;
int n_files;
int c;
@@ -1106,8 +1106,6 @@ 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 9e1ba0a7c..33a821d25 100644
--- a/src/stty.c
+++ b/src/stty.c
@@ -729,7 +729,10 @@ settings, CHAR is taken literally, or coded as in ^c, 0x37, 0177 or\n\
int
main (int argc, char **argv)
{
- struct termios mode;
+ /* 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, };
+
enum output_type output_type;
int optc;
int argi = 0;
@@ -840,9 +843,6 @@ main (int argc, char **argv)
else
device_name = _("standard input");
- /* Initialize to all zeroes so there is no risk memcmp will report a
- spurious difference in an uninitialized portion of the structure. */
- memset (&mode, 0, sizeof (mode));
if (tcgetattr (STDIN_FILENO, &mode))
error (EXIT_FAILURE, errno, "%s", device_name);
@@ -1002,7 +1002,9 @@ main (int argc, char **argv)
if (require_set_attr)
{
- struct termios new_mode;
+ /* 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, };
if (tcsetattr (STDIN_FILENO, TCSADRAIN, &mode))
error (EXIT_FAILURE, errno, "%s", device_name);
@@ -1014,9 +1016,6 @@ main (int argc, char **argv)
this partial failure, get the current terminal attributes and
compare them to the requested ones. */
- /* Initialize to all zeroes so there is no risk memcmp will report a
- spurious difference in an uninitialized portion of the structure. */
- memset (&new_mode, 0, sizeof (new_mode));
if (tcgetattr (STDIN_FILENO, &new_mode))
error (EXIT_FAILURE, errno, "%s", device_name);
diff --git a/src/tr.c b/src/tr.c
index faa38be37..e18e5588e 100644
--- a/src/tr.c
+++ b/src/tr.c
@@ -1177,9 +1177,8 @@ card_of_complement (struct Spec_list *s)
{
int c;
int cardinality = N_CHARS;
- bool in_set[N_CHARS];
+ bool in_set[N_CHARS] = { 0, };
- memset (in_set, 0, sizeof in_set);
s->state = BEGIN_STATE;
while ((c = get_next (s, NULL)) != -1)
{
diff --git a/src/wc.c b/src/wc.c
index e21fb7f05..332f32dc4 100644
--- a/src/wc.c
+++ b/src/wc.c
@@ -273,7 +273,7 @@ wc (int fd, char const *file_x, struct fstatus *fstatus)
{
bool in_word = false;
uintmax_t linepos = 0;
- mbstate_t state;
+ mbstate_t state = { 0, };
uintmax_t last_error_line = 0;
int last_error_errno = 0;
# if SUPPORT_OLD_MBRTOWC
@@ -289,7 +289,6 @@ wc (int fd, char const *file_x, struct fstatus *fstatus)
const size_t prev = 0;
# endif
- memset (&state, 0, sizeof (mbstate_t));
while ((bytes_read = safe_read (fd, buf + prev, BUFFER_SIZE - prev)) > 0)
{
const char *p;