diff mbox series

[ovs-dev,v3,05/17] list: ensure iterator is NULL after pop loop

Message ID 20220216142800.3295236-6-amorenoz@redhat.com
State Superseded
Headers show
Series Fix undefined behavior in loop macros | 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

Adrián Moreno Feb. 16, 2022, 2:27 p.m. UTC
After the loop ends, the iterator is not guaranteed to point to a valid
object and should not be used. Make it NULL to avoid undefined behavior.

Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
---
 include/openvswitch/list.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Dumitru Ceara Feb. 25, 2022, 12:07 p.m. UTC | #1
On 2/16/22 15:27, Adrian Moreno wrote:
> After the loop ends, the iterator is not guaranteed to point to a valid
> object and should not be used. Make it NULL to avoid undefined behavior.
> 
> Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
> ---

I think this could be squashed together with patch 04/17.  For the
change itself:

Acked-by: Dumitru Ceara <dceara@redhat.com>
Adrián Moreno Feb. 28, 2022, 9:10 a.m. UTC | #2
On 2/25/22 13:07, Dumitru Ceara wrote:
> On 2/16/22 15:27, Adrian Moreno wrote:
>> After the loop ends, the iterator is not guaranteed to point to a valid
>> object and should not be used. Make it NULL to avoid undefined behavior.
>>
>> Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
>> ---
> 
> I think this could be squashed together with patch 04/17.  For the
> change itself:
> 

OK, Will squash.

> Acked-by: Dumitru Ceara <dceara@redhat.com>
> 

Thanks
diff mbox series

Patch

diff --git a/include/openvswitch/list.h b/include/openvswitch/list.h
index 8673bab93..8cd76b892 100644
--- a/include/openvswitch/list.h
+++ b/include/openvswitch/list.h
@@ -112,8 +112,9 @@  static inline bool ovs_list_is_short(const struct ovs_list *);
          UPDATE_MULTIVAR_SAFE_LONG(VAR, NEXT))
 
 #define LIST_FOR_EACH_POP(ITER, MEMBER, LIST)                                 \
-    while (!ovs_list_is_empty(LIST)                                           \
-           && (INIT_CONTAINER(ITER, ovs_list_pop_front(LIST), MEMBER), 1))
+    while (!ovs_list_is_empty(LIST) ?                                         \
+           (INIT_CONTAINER(ITER, ovs_list_pop_front(LIST), MEMBER), 1) :      \
+           (ITER = NULL, 0))
 
 /* Inline implementations. */