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.
@@ -214,6 +214,7 @@ u32 vec_len_not_inline (void *v);
/** \brief Vector iterator (reverse) */
#define vec_foreach_backwards(var, vec) \
+ if (vec) \
for (var = vec_end (vec) - 1; var >= (vec); var--)
/** \brief Iterate over vector indices. */
@@ -221,6 +222,7 @@ for (var = vec_end (vec) - 1; var >= (vec); var--)
/** \brief Iterate over vector indices (reverse). */
#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 */
