[Spice-devel] [PATCH x11spice] Fix compliation on gcc 4.X.

Frediano Ziglio fziglio at redhat.com
Thu Mar 12 12:02:50 UTC 2020


If I can suggest, for sigaction, just use memset!

It's  weird structure defined in different way in different systems, and also
on the same system could be different depending on some flags.
It's a weird combination of unions and structures, in reality some field name
you use are preprocessor macros to access nested fields.

Frediano

> 
> Hi,
> 
> I'm afraid that does not help on the gcc 4.8.5 on RHEL 7.X, particularly
> with structures that contain other structures.
> 
> gcc -Wall -DTHREE -o /dev/null -c test.c
> test.c: In function ‘handle_sigterm’:
> test.c:12:12: warning: missing braces around initializer [-Wmissing-braces]
>       struct sigaction act = { 0 };
>              ^
> test.c:12:12: warning: (near initialization for
> ‘act.__sigaction_handler’) [-Wmissing-braces]
> 
> Attached is the test program.
> 
> Cheers,
> 
> Jeremy
> 
> On 3/11/20 1:27 PM, Uri Lublin wrote:
> > Hi,
> > 
> > Thanks for the ping on IRC.
> > 
> > On 9/17/19 7:23 PM, Jeremy White wrote:
> >> gcc 4.x warns if you use a { 0 } initialization construct
> >> for a structure with an initial member that is also a struct.
> >>
> >> The { } construct is simpler and appears to work on a wider
> >> range of gcc versions.
> > 
> > On my Fedora 31, gcc (version 9.2.1) does complain about {} but not
> > about {0}
> > when built with -Wpedantic (see simple program below).
> > 
> > 
> > Does {0, } works better for you ?
> > 
> > 
> > ================
> > 
> > #include <stdio.h>
> > 
> > struct S {int a, b; };
> > 
> > void print_s(struct S* ps)
> > {
> >      if (!ps) { printf("null\n"); return; }
> >      printf("(%d, %d)\n", ps->a, ps->b);
> > }
> > 
> > int main ()
> > {
> >          struct S s = { };
> > 
> >          print_s(&s);
> >      return 0;
> > }
> > 
> > 
> > ================
> > 
> > Uri.
> > 
> >>
> >> This is a correction to fdfdf1107be100b983de1bff4beee8e6360f670b
> >>
> >> Signed-off-by: Jeremy White <jwhite at codeweavers.com>
> >> ---
> >>   src/gui.c    | 2 +-
> >>   src/listen.c | 2 +-
> >>   src/main.c   | 2 +-
> >>   src/spice.c  | 2 +-
> >>   4 files changed, 4 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/src/gui.c b/src/gui.c
> >> index 88acf5c9..3c26b864 100644
> >> --- a/src/gui.c
> >> +++ b/src/gui.c
> >> @@ -147,7 +147,7 @@ void session_disconnect_client(session_t *session)
> >>   int main(int argc, char *argv[])
> >>   {
> >>       gui_t gui;
> >> -    session_t session = { 0 };
> >> +    session_t session = { };
> >>       setlocale(LC_ALL, "");
> >>       gui_create(&gui, &session, argc, argv);
> >> diff --git a/src/listen.c b/src/listen.c
> >> index 452fd81f..76c0798a 100644
> >> --- a/src/listen.c
> >> +++ b/src/listen.c
> >> @@ -117,7 +117,7 @@ int listen_parse(const char *listen_spec, char
> >> **addr, int *port_start, int *por
> >>   static int try_port(const char *addr, int port)
> >>   {
> >>       static const int on = 1, off = 0;
> >> -    struct addrinfo ai = { 0 }, *res, *e;
> >> +    struct addrinfo ai = { }, *res, *e;
> >>       char portbuf[33];
> >>       int sock, rc;
> >> diff --git a/src/main.c b/src/main.c
> >> index 71cbb465..890ff133 100644
> >> --- a/src/main.c
> >> +++ b/src/main.c
> >> @@ -55,7 +55,7 @@ int main(int argc, char *argv[])
> >>   {
> >>       int rc;
> >> -    session_t session = { 0 };
> >> +    session_t session = { };
> >>       int display_opened = 0;
> >>       int spice_started = 0;
> >> diff --git a/src/spice.c b/src/spice.c
> >> index 08a5d09a..561c85ff 100644
> >> --- a/src/spice.c
> >> +++ b/src/spice.c
> >> @@ -474,7 +474,7 @@ static int send_monitors_config(spice_t *s, int w,
> >> int h)
> >>   int spice_create_primary(spice_t *s, int w, int h, int
> >> bytes_per_line, void *shmaddr)
> >>   {
> >> -    QXLDevSurfaceCreate surface = { 0 };
> >> +    QXLDevSurfaceCreate surface = { };
> >>       surface.height = h;
> >>       surface.width = w;
> >>
> > 
> 
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
> 



More information about the Spice-devel mailing list