vppinfra: fix ASAN issue in vec_foreach_pointer and pool_foreach_pointer 33/39833/1
authorDamjan Marion <damarion@cisco.com>
Mon, 6 Nov 2023 17:37:04 +0000 (17:37 +0000)
committerDamjan Marion <damarion@cisco.com>
Mon, 6 Nov 2023 17:40:07 +0000 (17:40 +0000)
Change-Id: If9381ae7283488b352a3c22f85732cd56ac6bfd9
Type: fix
Fixes: 993735991ff0e9
Signed-off-by: Damjan Marion <damarion@cisco.com>
src/vppinfra/pool.h
src/vppinfra/vec_bootstrap.h

index 9913838..1a414ae 100644 (file)
@@ -571,9 +571,10 @@ do {                                                                       \
 /* works only for pool of pointers, e is declared inside macro */
 #define pool_foreach_pointer(e, p)                                            \
   if (p)                                                                      \
-    for (typeof ((p)[0]) *_t = (p) + pool_get_first_index (p), (e) = *_t;     \
-        _t < vec_end (p);                                                    \
-        _t = (p) + pool_get_next_index (p, _t - (p)), (e) = *_t)
+    for (typeof ((p)[0]) *_t = (p) + pool_get_first_index (p), (e) = *_t,     \
+                        *_end = vec_end (p);                                 \
+        _t < _end; _t = (p) + pool_get_next_index (p, _t - (p)),             \
+                        (e) = _t < _end ? *_t : (e))
 
 /**
  * @brief Remove all elements from a pool in a safe way
index 5ea7a80..5d386b1 100644 (file)
@@ -240,8 +240,8 @@ _vec_set_len (void *v, uword len, uword elt_sz)
 
 #define vec_foreach_pointer(e, v)                                             \
   if (v)                                                                      \
-    for (typeof (**v) **__ep = (v), *(e) = *__ep; __ep - (v) < vec_len (v);   \
-        __ep++, (e) = *__ep)
+    for (typeof (**v) **__ep = (v), **__end = vec_end (v), *(e) = *__ep;      \
+        __ep < __end; __ep++, (e) = __ep < __end ? *__ep : (e))
 
 #endif /* included_clib_vec_bootstrap_h */