diff mbox series

[ovs-dev,5/6] test-psample: Fix missing field initializer warnings on older GCC.

Message ID 20251009092228.382349-6-i.maximets@ovn.org
State Accepted
Commit efb2c55810d66195d80bc7b6cb090990fb439c3f
Headers show
Series Build fixes for OVS on old distributions. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed

Commit Message

Ilya Maximets Oct. 9, 2025, 9:21 a.m. UTC
GCC 4.8 complains for some reason:

  tests/test-psample.c: In function 'run':
  tests/test-psample.c:217:12:
    error: missing initializer for field 'packet' of 'struct sample'
    [-Werror=missing-field-initializers]
     struct sample sample = {};
            ^

While it is a little strange to complain, the {} initializer is a C++
thing and a GNU extension, so we should not be using it.  It's only
available in C23 standard.

Also, the initialization is not even necessary here, all the fields
will be initialized later with sample_clear(), as long as it covers
all the fields (rate was missing).

Fixes: 742de01a4a2e ("tests: Add test-psample testing utility.")
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
---
 tests/test-psample.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Kevin Traynor Oct. 10, 2025, 11:24 a.m. UTC | #1
On 09/10/2025 10:21, Ilya Maximets wrote:
> GCC 4.8 complains for some reason:
> 
>   tests/test-psample.c: In function 'run':
>   tests/test-psample.c:217:12:
>     error: missing initializer for field 'packet' of 'struct sample'
>     [-Werror=missing-field-initializers]
>      struct sample sample = {};
>             ^
> 
> While it is a little strange to complain, the {} initializer is a C++
> thing and a GNU extension, so we should not be using it.  It's only
> available in C23 standard.
> 
> Also, the initialization is not even necessary here, all the fields
> will be initialized later with sample_clear(), as long as it covers
> all the fields (rate was missing).
> 
> Fixes: 742de01a4a2e ("tests: Add test-psample testing utility.")
> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
> ---
>  tests/test-psample.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Acked-by: Kevin Traynor <ktraynor@redhat.com>
Eelco Chaudron Oct. 10, 2025, 11:49 a.m. UTC | #2
On 9 Oct 2025, at 11:21, Ilya Maximets wrote:

> GCC 4.8 complains for some reason:
>
>   tests/test-psample.c: In function 'run':
>   tests/test-psample.c:217:12:
>     error: missing initializer for field 'packet' of 'struct sample'
>     [-Werror=missing-field-initializers]
>      struct sample sample = {};
>             ^
>
> While it is a little strange to complain, the {} initializer is a C++
> thing and a GNU extension, so we should not be using it.  It's only
> available in C23 standard.
>
> Also, the initialization is not even necessary here, all the fields
> will be initialized later with sample_clear(), as long as it covers
> all the fields (rate was missing).
>
> Fixes: 742de01a4a2e ("tests: Add test-psample testing utility.")
> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>

Acked-by: Eelco Chaudron <echaudro@redhat.com>
diff mbox series

Patch

diff --git a/tests/test-psample.c b/tests/test-psample.c
index 1494dcc8d..9eaa11b00 100644
--- a/tests/test-psample.c
+++ b/tests/test-psample.c
@@ -160,6 +160,7 @@  static inline void
 sample_clear(struct sample *sample)
 {
     sample->group_id = 0;
+    sample->rate = 0;
     sample->obs_domain_id = 0;
     sample->obs_point_id = 0;
     sample->has_cookie = false;
@@ -214,7 +215,7 @@  parse_psample(struct ofpbuf *buf, struct sample *sample)
 static void run(struct nl_sock *sock)
 {
     static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(10, 10);
-    struct sample sample = {};
+    struct sample sample;
     int error;
 
     dp_packet_init(&sample.packet, 1500);