From 16a17507f418c89ac0aacaf19d83dd07dee42d21 Mon Sep 17 00:00:00 2001 From: Benoît Ganne Date: Mon, 22 Jul 2019 14:21:46 +0200 Subject: vppinfra: add vec_set_len() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit l2-flood and bier nodes reset vector length without updating it to its effective size. Introduce a helper to do it (this allows ASAN to keep track of the new vector size). Type: refactor Change-Id: I2d652550c440f0553a2b49c3ee3d37b49ebc16c3 Signed-off-by: Benoît Ganne (cherry picked from commit 8a4bfdae87286ed281df855c58b669eb6b76aaf8) --- src/vppinfra/vec_bootstrap.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/vppinfra') diff --git a/src/vppinfra/vec_bootstrap.h b/src/vppinfra/vec_bootstrap.h index fec0df08143..7fb016fe8d2 100644 --- a/src/vppinfra/vec_bootstrap.h +++ b/src/vppinfra/vec_bootstrap.h @@ -142,12 +142,6 @@ vec_aligned_header_end (void *v, uword header_bytes, uword align) #define vec_len(v) ((v) ? _vec_len(v) : 0) -/** \brief Reset vector length to zero - NULL-pointer tolerant -*/ - -#define vec_reset_length(v) do { if (v) _vec_len (v) = 0; } while (0) - /** \brief Number of data bytes in vector. */ #define vec_bytes(v) (vec_len (v) * sizeof (v[0])) @@ -165,6 +159,19 @@ vec_aligned_header_end (void *v, uword header_bytes, uword align) /** \brief Total number of elements that can fit into vector. */ #define vec_max_len(v) (vec_capacity(v,0) / sizeof (v[0])) +/** \brief Set vector length to a user-defined value */ +#define vec_set_len(v, l) do { \ + ASSERT(v); \ + ASSERT((l) <= vec_max_len(v)); \ + _vec_len(v) = (l); \ +} while (0) + +/** \brief Reset vector length to zero + NULL-pointer tolerant +*/ + +#define vec_reset_length(v) do { if (v) vec_set_len (v, 0); } while (0) + /** \brief End (last data address) of vector. */ #define vec_end(v) ((v) + vec_len (v)) -- cgit 1.2.3-korg