summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/bitmap.h
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2022-04-04 22:40:45 +0200
committerDamjan Marion <dmarion@me.com>2022-04-04 23:17:13 +0000
commit8bea589cfe0fca1a6f560e16ca66a4cf199041a2 (patch)
treecf2767f8f5f31344468b65e14baa3f1a4c85fb91 /src/vppinfra/bitmap.h
parenta2b358b1faf6e762e1d29a931d83c7735ac9a77d (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/bitmap.h')
-rw-r--r--src/vppinfra/bitmap.h51
1 files changed, 27 insertions, 24 deletions
diff --git a/src/vppinfra/bitmap.h b/src/vppinfra/bitmap.h
index 096d3f1aa4a..02f9c7e55ab 100644
--- a/src/vppinfra/bitmap.h
+++ b/src/vppinfra/bitmap.h
@@ -142,7 +142,7 @@ _clib_bitmap_remove_trailing_zeros (uword * a)
for (i = _vec_len (a) - 1; i >= 0; i--)
if (a[i] != 0)
break;
- _vec_len (a) = i + 1;
+ vec_set_len (a, i + 1);
}
return a;
}
@@ -518,29 +518,32 @@ always_inline uword *clib_bitmap_or (uword * ai, uword * bi);
always_inline uword *clib_bitmap_xor (uword * ai, uword * bi);
/* ALU function definition macro for functions taking two bitmaps. */
-#define _(name, body, check_zero) \
-always_inline uword * \
-clib_bitmap_##name (uword * ai, uword * bi) \
-{ \
- uword i, a, b, bi_len, n_trailing_zeros; \
- \
- n_trailing_zeros = 0; \
- bi_len = vec_len (bi); \
- if (bi_len > 0) \
- clib_bitmap_vec_validate (ai, bi_len - 1); \
- for (i = 0; i < vec_len (ai); i++) \
- { \
- a = ai[i]; \
- b = i < bi_len ? bi[i] : 0; \
- do { body; } while (0); \
- ai[i] = a; \
- if (check_zero) \
- n_trailing_zeros = a ? 0 : (n_trailing_zeros + 1); \
- } \
- if (check_zero) \
- _vec_len (ai) -= n_trailing_zeros; \
- return ai; \
-}
+#define _(name, body, check_zero) \
+ always_inline uword *clib_bitmap_##name (uword *ai, uword *bi) \
+ { \
+ uword i, a, b, bi_len, n_trailing_zeros; \
+ \
+ n_trailing_zeros = 0; \
+ bi_len = vec_len (bi); \
+ if (bi_len > 0) \
+ clib_bitmap_vec_validate (ai, bi_len - 1); \
+ for (i = 0; i < vec_len (ai); i++) \
+ { \
+ a = ai[i]; \
+ b = i < bi_len ? bi[i] : 0; \
+ do \
+ { \
+ body; \
+ } \
+ while (0); \
+ ai[i] = a; \
+ if (check_zero) \
+ n_trailing_zeros = a ? 0 : (n_trailing_zeros + 1); \
+ } \
+ if (check_zero) \
+ vec_dec_len (ai, n_trailing_zeros); \
+ return ai; \
+ }
/* ALU functions: */
/* *INDENT-OFF* */