[PATCH 06/10] Add braces in initializers for GCC 4.9 or older
H.J. Lu
hjl.tools@gmail.com
Sun Dec 15 10:49:03 GMT 2024
On Sat, Dec 14, 2024 at 5:37 PM Sam James <sam@gentoo.org> wrote:
>
> "H.J. Lu" <hjl.tools@gmail.com> writes:
>
> > Add braces to silence GCC 4.9 or older:
> >
> > getaddrinfo.c: In function ‘gaih_inet’:
> > getaddrinfo.c:1135:24: error: missing braces around initializer [-Werror=missing-braces]
> > / sizeof (struct gaih_typeproto)] = {0};
> > ^
> >
> > Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
>
> Reviewed-by: Sam James <sam@gentoo.org>
>
> > ---
> > misc/tst-preadvwritev2-common.c | 2 +-
> > nss/getaddrinfo.c | 2 +-
> > posix/tst-spawn7.c | 4 ++--
> > rt/tst-timer-sigmask.c | 4 ++--
> > stdlib/tst-system.c | 2 +-
> > sysdeps/pthread/tst-cancel28.c | 4 ++--
> > sysdeps/unix/sysv/linux/tst-getcwd-smallbuff.c | 4 ++--
> > .../unix/sysv/linux/tst-socket-timestamp-compat.c | 4 ++--
> > time/tst-itimer.c | 13 ++++++++-----
> > 9 files changed, 21 insertions(+), 18 deletions(-)
> >
> > diff --git a/misc/tst-preadvwritev2-common.c b/misc/tst-preadvwritev2-common.c
> > index 4556421a43..5d1f498da9 100644
> > --- a/misc/tst-preadvwritev2-common.c
> > +++ b/misc/tst-preadvwritev2-common.c
> > @@ -97,7 +97,7 @@ do_test_with_invalid_iov (void)
> > {
> > /* An invalid iovec buffer should trigger an invalid memory access
> > or an error (Linux for instance returns EFAULT). */
> > - struct iovec iov[IOV_MAX+1] = { 0 };
> > + struct iovec iov[IOV_MAX+1] = { { 0 } };
> >
> > TEST_VERIFY (preadv2 (temp_fd, iov, IOV_MAX + 1, 0, RWF_HIPRI) == -1);
> > TEST_VERIFY (errno == EINVAL || errno == ENOTSUP);
> > diff --git a/nss/getaddrinfo.c b/nss/getaddrinfo.c
> > index 78f50954df..2df9542e6f 100644
> > --- a/nss/getaddrinfo.c
> > +++ b/nss/getaddrinfo.c
> > @@ -1132,7 +1132,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
> > unsigned int *naddrs, struct scratch_buffer *tmpbuf)
> > {
> > struct gaih_servtuple st[sizeof (gaih_inet_typeproto)
> > - / sizeof (struct gaih_typeproto)] = {0};
> > + / sizeof (struct gaih_typeproto)] = {{0}};
> >
> > const char *orig_name = name;
> >
> > diff --git a/posix/tst-spawn7.c b/posix/tst-spawn7.c
> > index e4adc6cbf0..0b67b35d77 100644
> > --- a/posix/tst-spawn7.c
> > +++ b/posix/tst-spawn7.c
> > @@ -114,7 +114,7 @@ do_test_signals (void)
> > {
> > /* Same as before, but set SIGUSR1 and SIGUSR2 to a handler different than
> > SIG_IGN or SIG_DFL. */
> > - struct sigaction sa = { 0 };
> > + struct sigaction sa = { { 0 } };
> > sa.sa_handler = dummy_sa_handler;
> > xsigaction (SIGUSR1, &sa, NULL);
> > xsigaction (SIGUSR2, &sa, NULL);
> > @@ -123,7 +123,7 @@ do_test_signals (void)
> >
> > {
> > /* Check if SIG_IGN is keep as is. */
> > - struct sigaction sa = { 0 };
> > + struct sigaction sa = { { 0 } };
> > sa.sa_handler = SIG_IGN;
> > xsigaction (SIGUSR1, &sa, NULL);
> > xsigaction (SIGUSR2, &sa, NULL);
> > diff --git a/rt/tst-timer-sigmask.c b/rt/tst-timer-sigmask.c
> > index e27b2e5189..9ed64cc647 100644
> > --- a/rt/tst-timer-sigmask.c
> > +++ b/rt/tst-timer-sigmask.c
> > @@ -57,7 +57,7 @@ thread_handler (union sigval sv)
> > static int
> > do_test (void)
> > {
> > - struct sigevent sev = { 0 };
> > + struct sigevent sev = { { 0 } };
> > sev.sigev_notify = SIGEV_THREAD;
> > sev.sigev_notify_function = &thread_handler;
> >
> > @@ -66,7 +66,7 @@ do_test (void)
> >
> > xpthread_barrier_init (&barrier, NULL, 2);
> >
> > - struct itimerspec trigger = { 0 };
> > + struct itimerspec trigger = { { 0 } };
> > trigger.it_value.tv_nsec = 1000000;
> > TEST_COMPARE (timer_settime (timerid, 0, &trigger, NULL), 0);
> >
> > diff --git a/stdlib/tst-system.c b/stdlib/tst-system.c
> > index b5b630a41b..1878ee7ac2 100644
> > --- a/stdlib/tst-system.c
> > +++ b/stdlib/tst-system.c
> > @@ -80,7 +80,7 @@ sleep_and_check_sigchld (void *closure)
> > sprintf (cmd, "sleep %lf" , *seconds);
> > TEST_COMPARE (system (cmd), 0);
> >
> > - sigset_t blocked = {0};
> > + sigset_t blocked = {{0}};
> > TEST_COMPARE (sigprocmask (SIG_BLOCK, NULL, &blocked), 0);
> > TEST_COMPARE (sigismember (&blocked, SIGCHLD), 0);
> > return NULL;
> > diff --git a/sysdeps/pthread/tst-cancel28.c b/sysdeps/pthread/tst-cancel28.c
> > index 2280d57722..ded025504e 100644
> > --- a/sysdeps/pthread/tst-cancel28.c
> > +++ b/sysdeps/pthread/tst-cancel28.c
> > @@ -52,7 +52,7 @@ thread_handler (union sigval sv)
> > static int
> > do_test (void)
> > {
> > - struct sigevent sev = { 0 };
> > + struct sigevent sev = { { 0 } };
> > sev.sigev_notify = SIGEV_THREAD;
> > sev.sigev_notify_function = &thread_handler;
> >
> > @@ -61,7 +61,7 @@ do_test (void)
> >
> > xpthread_barrier_init (&barrier, NULL, 2);
> >
> > - struct itimerspec trigger = { 0 };
> > + struct itimerspec trigger = { { 0 } };
> > trigger.it_value.tv_nsec = 1000000;
> > TEST_COMPARE (timer_settime (timerid, 0, &trigger, NULL), 0);
> >
> > diff --git a/sysdeps/unix/sysv/linux/tst-getcwd-smallbuff.c b/sysdeps/unix/sysv/linux/tst-getcwd-smallbuff.c
> > index 55362f6060..a024783885 100644
> > --- a/sysdeps/unix/sysv/linux/tst-getcwd-smallbuff.c
> > +++ b/sysdeps/unix/sysv/linux/tst-getcwd-smallbuff.c
> > @@ -59,7 +59,7 @@ send_fd (const int sock, const int fd)
> > {
> > struct cmsghdr hdr;
> > char buf[CMSG_SPACE (sizeof (int))];
> > - } cmsgbuf = {0};
> > + } cmsgbuf = {{0}};
> > struct cmsghdr *cmsg;
> > struct iovec vec;
> > char ch = 'A';
> > @@ -92,7 +92,7 @@ recv_fd (const int sock)
> > {
> > struct cmsghdr hdr;
> > char buf[CMSG_SPACE(sizeof(int))];
> > - } cmsgbuf = {0};
> > + } cmsgbuf = {{0}};
> > struct cmsghdr *cmsg;
> > struct iovec vec;
> > ssize_t n;
> > diff --git a/sysdeps/unix/sysv/linux/tst-socket-timestamp-compat.c b/sysdeps/unix/sysv/linux/tst-socket-timestamp-compat.c
> > index e0fb28d0b9..2d8739b00d 100644
> > --- a/sysdeps/unix/sysv/linux/tst-socket-timestamp-compat.c
> > +++ b/sysdeps/unix/sysv/linux/tst-socket-timestamp-compat.c
> > @@ -76,7 +76,7 @@ do_recvmsg_ancillary (bool use_multi_call, struct mmsghdr *mmhdr,
> > static void
> > do_test_large_buffer (bool mc)
> > {
> > - struct mmsghdr mmhdr = { 0 };
> > + struct mmsghdr mmhdr = { { 0 } };
> > /* It should be large enough for either timeval/timespec and the
> > 64 time type as well. */
> >
> > @@ -147,7 +147,7 @@ do_test_large_buffer (bool mc)
> > static void
> > do_test_small_buffer (bool mc)
> > {
> > - struct mmsghdr mmhdr = { 0 };
> > + struct mmsghdr mmhdr = { { 0 } };
> >
> > /* Enable 32 bit timeval precision and check if no 64 bit timeval stamp
> > is created. */
> > diff --git a/time/tst-itimer.c b/time/tst-itimer.c
> > index e7186e6200..3937deecc8 100644
> > --- a/time/tst-itimer.c
> > +++ b/time/tst-itimer.c
> > @@ -62,7 +62,8 @@ do_test (void)
> > it.it_interval.tv_usec = 20;
> > TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
> >
> > - TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 }, &it_old),
> > + TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { { 0 } },
> > + &it_old),
> > 0);
> > /* ITIMER_REAL returns { 0, 0 } for single-shot timers, while
> > other timers returns setitimer value. */
> > @@ -87,7 +88,8 @@ do_test (void)
> > it.it_value.tv_usec = 40;
> > TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
> >
> > - TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 }, &it_old),
> > + TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { { 0 } },
> > + &it_old),
> > 0);
> > TEST_COMPARE (it.it_interval.tv_sec, it_old.it_interval.tv_sec);
> > if (timers[i] == ITIMER_REAL)
> > @@ -107,7 +109,7 @@ do_test (void)
> > if (support_itimer_support_time64())
> > {
> > TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
> > - TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 },
> > + TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { { 0 } },
> > &it_old),
> > 0);
> > /* ITIMER_REAL returns { 0, 0 } for single-sort timers, while other
> > @@ -134,7 +136,7 @@ do_test (void)
> > {
> > TEST_COMPARE (setitimer (timers[i], &it, NULL), 0);
> >
> > - TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 },
> > + TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { { 0 } },
> > &it_old),
> > 0);
> > if (timers[i] == ITIMER_REAL)
> > @@ -169,7 +171,8 @@ do_test (void)
> > TEST_COMPARE (setitimer (ITIMER_REAL, &it, NULL), 0);
> > intr_sleep (1);
> > TEST_COMPARE (cnt, 3);
> > - TEST_COMPARE (setitimer (ITIMER_REAL, &(struct itimerval) { 0 }, NULL), 0);
> > + TEST_COMPARE (setitimer (ITIMER_REAL, &(struct itimerval) { { 0 } },
> > + NULL), 0);
> >
> > return 0;
> > }
I am reverting this since not all targets need braces:
https://inbox.sourceware.org/libc-testresults/173423226290.2245540.4481814393874404938@torsion.usersys.redhat.com/
--
H.J.
More information about the Libc-alpha
mailing list