diff mbox series

[ovs-dev,1/3] ofproto-dpif-xlate: Initialize observe_offset for sample actions.

Message ID 20240717120101.591940-2-i.maximets@ovn.org
State Accepted
Commit f9078407a9d8dffffc391ccfe144de823436cae6
Headers show
Series Fix some GCC 14 false-positive build warnings. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/intel-ovs-compilation fail test: fail

Commit Message

Ilya Maximets July 17, 2024, noon UTC
For some reason gcc 14.1.1 from Fedora 41 thinks that the variable
may end up not initialized:

 ofproto/ofproto-dpif-xlate.c: In function 'compose_sample_action':
 ofproto/ofproto-dpif-xlate.c:3465:40:
          error: 'observe_offset' may be used uninitialized
  3465 |         ctx->xout->last_observe_offset = observe_offset;
       |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
 ofproto/ofproto-dpif-xlate.c:3418:12:
          note: 'observe_offset' was declared here
  3418 |     size_t observe_offset;
       |            ^~~~~~~~~~~~~~

We have an assertion in the code to ensure that at least one of
the actions is present (userspace or psample), so the variable
should actually be always initialized.

Initialize explicitly just to silence the warning.

Fixes: 516569d31fbf ("ofproto: xlate: Make sampled drops explicit.")
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
---
 ofproto/ofproto-dpif-xlate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Mike Pattrick July 17, 2024, 1:38 p.m. UTC | #1
On Wed, Jul 17, 2024 at 8:01 AM Ilya Maximets <i.maximets@ovn.org> wrote:
>
> For some reason gcc 14.1.1 from Fedora 41 thinks that the variable
> may end up not initialized:
>
>  ofproto/ofproto-dpif-xlate.c: In function 'compose_sample_action':
>  ofproto/ofproto-dpif-xlate.c:3465:40:
>           error: 'observe_offset' may be used uninitialized
>   3465 |         ctx->xout->last_observe_offset = observe_offset;
>        |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
>  ofproto/ofproto-dpif-xlate.c:3418:12:
>           note: 'observe_offset' was declared here
>   3418 |     size_t observe_offset;
>        |            ^~~~~~~~~~~~~~
>
> We have an assertion in the code to ensure that at least one of
> the actions is present (userspace or psample), so the variable
> should actually be always initialized.
>
> Initialize explicitly just to silence the warning.
>
> Fixes: 516569d31fbf ("ofproto: xlate: Make sampled drops explicit.")
> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
> ---

Acked-by: Mike Pattrick <mkp@redhat.com>
Ilya Maximets July 17, 2024, 9:50 p.m. UTC | #2
On 7/17/24 15:38, Mike Pattrick wrote:
> On Wed, Jul 17, 2024 at 8:01 AM Ilya Maximets <i.maximets@ovn.org> wrote:
>>
>> For some reason gcc 14.1.1 from Fedora 41 thinks that the variable
>> may end up not initialized:
>>
>>  ofproto/ofproto-dpif-xlate.c: In function 'compose_sample_action':
>>  ofproto/ofproto-dpif-xlate.c:3465:40:
>>           error: 'observe_offset' may be used uninitialized
>>   3465 |         ctx->xout->last_observe_offset = observe_offset;
>>        |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
>>  ofproto/ofproto-dpif-xlate.c:3418:12:
>>           note: 'observe_offset' was declared here
>>   3418 |     size_t observe_offset;
>>        |            ^~~~~~~~~~~~~~
>>
>> We have an assertion in the code to ensure that at least one of
>> the actions is present (userspace or psample), so the variable
>> should actually be always initialized.
>>
>> Initialize explicitly just to silence the warning.
>>
>> Fixes: 516569d31fbf ("ofproto: xlate: Make sampled drops explicit.")
>> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
>> ---
> 
> Acked-by: Mike Pattrick <mkp@redhat.com>
> 

Thanks, Mike!  Applied to main and 3.4.

Best regards, Ilya Maximets.
diff mbox series

Patch

diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c
index 02567a961..850597b3a 100644
--- a/ofproto/ofproto-dpif-xlate.c
+++ b/ofproto/ofproto-dpif-xlate.c
@@ -3423,8 +3423,8 @@  compose_sample_action(struct xlate_ctx *ctx,
      * insert a meter action before the user space action.  */
     struct ofproto *ofproto = &ctx->xin->ofproto->up;
     uint32_t meter_id = ofproto->slowpath_meter_id;
+    size_t observe_offset = UINT32_MAX;
     size_t cookie_offset = 0;
-    size_t observe_offset;
 
     /* The meter action is only used to throttle userspace actions.
      * If they are not needed and the sampling rate is 100%, avoid generating