diff options
author | Damjan Marion <damarion@cisco.com> | 2022-04-04 22:40:45 +0200 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2022-04-04 23:17:13 +0000 |
commit | 8bea589cfe0fca1a6f560e16ca66a4cf199041a2 (patch) | |
tree | cf2767f8f5f31344468b65e14baa3f1a4c85fb91 /src/vppinfra/vec_bootstrap.h | |
parent | a2b358b1faf6e762e1d29a931d83c7735ac9a77d (diff) |
vppinfra: make _vec_len() read-only
Use of _vec_len() to set vector length breaks address sanitizer.
Users should use vec_set_len(), vec_inc_len(), vec_dec_len () instead.
Type: improvement
Change-Id: I441ae948771eb21c23a61f3ff9163bdad74a2cb8
Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vppinfra/vec_bootstrap.h')
-rw-r--r-- | src/vppinfra/vec_bootstrap.h | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/vppinfra/vec_bootstrap.h b/src/vppinfra/vec_bootstrap.h index d6451f3d172..0054802e8c1 100644 --- a/src/vppinfra/vec_bootstrap.h +++ b/src/vppinfra/vec_bootstrap.h @@ -116,21 +116,21 @@ vec_header_end (void *v) return v + vec_get_header_size (v); } -/** \brief Number of elements in vector (lvalue-capable) - - _vec_len (v) does not check for null, but can be used as an lvalue - (e.g. _vec_len (v) = 99). -*/ - -#define _vec_len(v) (_vec_find(v)->len) - /** \brief Number of elements in vector (rvalue-only, NULL tolerant) vec_len (v) checks for NULL, but cannot be used as an lvalue. If in doubt, use vec_len... */ +static_always_inline u32 +__vec_len (void *v) +{ + return _vec_find (v)->len; +} + +#define _vec_len(v) __vec_len ((void *) (v)) #define vec_len(v) ((v) ? _vec_len(v) : 0) + u32 vec_len_not_inline (void *v); /** \brief Number of data bytes in vector. */ @@ -180,10 +180,12 @@ _vec_set_len (void *v, uword len, uword elt_sz) else if (len > old_len) CLIB_MEM_POISON (v + len * elt_sz, (old_len - len) * elt_sz); - _vec_len (v) = len; + _vec_find (v)->len = len; } #define vec_set_len(v, l) _vec_set_len ((void *) v, l, _vec_elt_sz (v)) +#define vec_inc_len(v, l) vec_set_len (v, _vec_len (v) + (l)) +#define vec_dec_len(v, l) vec_set_len (v, _vec_len (v) - (l)) /** \brief Reset vector length to zero NULL-pointer tolerant |