aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeale Ranns <neale@graphiant.com>2022-01-09 13:24:47 +0000
committerDamjan Marion <dmarion@me.com>2022-01-09 14:32:30 +0000
commit9d33cfc0bc1928f0b4c8aa95c170cf91ee8011a0 (patch)
treeecf02868928c67abaa349c36fbe406f93dd47a83
parent221be7c03f8daf5b9c00b2509ebbf2c6e7e6232d (diff)
vppinfra: Check for NULL vec before the backwards iteration
Type: improvement 'vec_end(v) - 1' does not yield a good starting point. Check for NULL vec before the loop, so the user does not have to. Signed-off-by: Neale Ranns <neale@graphiant.com> Change-Id: Ia174ec8095bc476853cce709a7048d7a3e3b377d
-rw-r--r--src/vppinfra/vec_bootstrap.h10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/vppinfra/vec_bootstrap.h b/src/vppinfra/vec_bootstrap.h
index 5cf5d3b76a1..e14c4be8e52 100644
--- a/src/vppinfra/vec_bootstrap.h
+++ b/src/vppinfra/vec_bootstrap.h
@@ -213,15 +213,17 @@ u32 vec_len_not_inline (void *v);
#define vec_foreach(var,vec) for (var = (vec); var < vec_end (vec); var++)
/** \brief Vector iterator (reverse) */
-#define vec_foreach_backwards(var,vec) \
-for (var = vec_end (vec) - 1; var >= (vec); var--)
+#define vec_foreach_backwards(var, vec) \
+ if (vec) \
+ for (var = vec_end (vec) - 1; var >= (vec); var--)
/** \brief Iterate over vector indices. */
#define vec_foreach_index(var,v) for ((var) = 0; (var) < vec_len (v); (var)++)
/** \brief Iterate over vector indices (reverse). */
-#define vec_foreach_index_backwards(var,v) \
- for ((var) = vec_len((v)) - 1; (var) >= 0; (var)--)
+#define vec_foreach_index_backwards(var, v) \
+ if (v) \
+ for ((var) = vec_len ((v)) - 1; (var) >= 0; (var)--)
/** \brief return the NUMA index for a vector */
always_inline uword