maint: regularize struct initializers

* src/chmod.c (process_file):
* src/df.c (replace_invalid_chars):
* src/iopoll.c (iopoll_internal):
* src/ls.c (quote_name_buf):
* src/pathchk.c (portable_chars_only):
* src/printf.c (STRTOX):
* src/shred.c (main):
* src/stat.c (neg_to_zero, do_stat):
* src/timeout.c (settimeout):
* src/tr.c (card_of_complement):
* src/wc.c (wc):
Prefer ‘{0}’ to initialize everything to zero.
* src/stat.c (do_stat):
* src/timeout.c (settimeout):
Do not assume the usual order for struct members,
as POSIX does not guarantee this.
This commit is contained in:
Paul Eggert 2023-08-30 07:39:34 -07:00
parent 2c902cc288
commit e0326b0473
11 changed files with 16 additions and 16 deletions

View File

@ -205,7 +205,7 @@ process_file (FTS *fts, FTSENT *ent)
char const *file_full_name = ent->fts_path;
char const *file = ent->fts_accpath;
const struct stat *file_stats = ent->fts_statp;
struct change_status ch = { 0, };
struct change_status ch = {0};
ch.status = CH_NO_STAT;
switch (ent->fts_info)

View File

@ -319,7 +319,7 @@ replace_invalid_chars (char *cell)
{
char *srcend = cell + strlen (cell);
char *dst = cell;
mbstate_t mbstate = { 0, };
mbstate_t mbstate = {0};
size_t n;
for (char *src = cell; src != srcend; src += n)

View File

@ -113,7 +113,7 @@ iopoll_internal (int fdin, int fdout, bool block, bool broken_output)
if (0 <= fdout)
FD_SET (fdout, &fds);
struct timeval delay = { .tv_sec = 0, .tv_usec = 0 };
struct timeval delay = {0};
ret = select (nfds,
broken_output ? &fds : nullptr,
broken_output ? nullptr : &fds,

View File

@ -4608,7 +4608,7 @@ quote_name_buf (char **inbuf, size_t bufsize, char *name,
reach its end, replacing each non-printable multibyte
character with a single question mark. */
{
mbstate_t mbstate = { 0, };
mbstate_t mbstate = {0};
do
{
wchar_t wc;

View File

@ -188,7 +188,7 @@ portable_chars_only (char const *file, size_t filelen)
if (*invalid)
{
mbstate_t mbstate = { 0, };
mbstate_t mbstate = {0};
size_t charlen = mbrlen (invalid, filelen - validlen, &mbstate);
error (0, 0,
_("non-portable character %s in file name %s"),

View File

@ -172,7 +172,7 @@ FUNC_NAME (char const *s) \
\
if (MB_CUR_MAX > 1 && *(s + 1)) \
{ \
mbstate_t mbstate = { 0, }; \
mbstate_t mbstate = {0}; \
wchar_t wc; \
size_t slen = strlen (s); \
ssize_t bytes; \

View File

@ -1161,7 +1161,7 @@ int
main (int argc, char **argv)
{
bool ok = true;
struct Options flags = { 0, };
struct Options flags = {0};
char **file;
int n_files;
int c;

View File

@ -1039,7 +1039,7 @@ neg_to_zero (struct timespec ts)
{
if (0 <= ts.tv_nsec)
return ts;
struct timespec z = {0, 0};
struct timespec z = {0};
return z;
}
@ -1370,11 +1370,11 @@ do_stat (char const *filename, char const *format, char const *format2)
int fd = STREQ (filename, "-") ? 0 : AT_FDCWD;
int flags = 0;
struct stat st;
struct statx stx = { 0, };
struct statx stx = {0};
char const *pathname = filename;
struct print_args pa;
pa.st = &st;
pa.btime = (struct timespec) {-1, -1};
pa.btime = (struct timespec) {.tv_sec = -1, .tv_nsec = -1};
if (AT_FDCWD != fd)
{
@ -1460,7 +1460,7 @@ do_stat (char const *filename, char const *format,
struct stat statbuf;
struct print_args pa;
pa.st = &statbuf;
pa.btime = (struct timespec) {-1, -1};
pa.btime = (struct timespec) {.tv_sec = -1, .tv_nsec = -1};
if (0 <= fd)
{

View File

@ -117,7 +117,7 @@ settimeout (double duration, bool warn)
/* timer_settime() provides potentially nanosecond resolution. */
struct timespec ts = dtotimespec (duration);
struct itimerspec its = { {0, 0}, ts };
struct itimerspec its = {.it_interval = {0}, .it_value = ts};
timer_t timerid;
if (timer_create (CLOCK_REALTIME, nullptr, &timerid) == 0)
{
@ -151,7 +151,7 @@ settimeout (double duration, bool warn)
else
tv.tv_usec--;
}
struct itimerval it = { {0, 0}, tv };
struct itimerval it = {.it_interval = {0}, .it_value = tv };
if (setitimer (ITIMER_REAL, &it, nullptr) == 0)
return;
else
@ -447,7 +447,7 @@ disable_core_dumps (void)
#elif HAVE_SETRLIMIT && defined RLIMIT_CORE
/* Note this doesn't disable processing by a filter in
/proc/sys/kernel/core_pattern on Linux. */
if (setrlimit (RLIMIT_CORE, &(struct rlimit) {0,0}) == 0)
if (setrlimit (RLIMIT_CORE, &(struct rlimit) {0}) == 0)
return true;
#else

View File

@ -1138,7 +1138,7 @@ card_of_complement (struct Spec_list *s)
{
int c;
int cardinality = N_CHARS;
bool in_set[N_CHARS] = { 0, };
bool in_set[N_CHARS] = {0};
s->state = BEGIN_STATE;
while ((c = get_next (s, nullptr)) != -1)

View File

@ -452,7 +452,7 @@ wc (int fd, char const *file_x, struct fstatus *fstatus, off_t current_pos)
{
bool in_word = false;
uintmax_t linepos = 0;
mbstate_t state = { 0, };
mbstate_t state = {0};
bool in_shift = false;
# if SUPPORT_OLD_MBRTOWC
/* Back-up the state before each multibyte character conversion and