vppinfra: fix vec_max_len
[vpp.git] / src / vppinfra / vec_bootstrap.h
index 501db61..5cf5d3b 100644 (file)
@@ -140,6 +140,7 @@ vec_aligned_header_end (void *v, uword header_bytes, uword align)
 */
 
 #define vec_len(v)     ((v) ? _vec_len(v) : 0)
+u32 vec_len_not_inline (void *v);
 
 /** \brief Vector's NUMA id (lvalue-capable)
 
@@ -170,7 +171,8 @@ 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]))
+#define vec_max_len(v)                                                                 \
+  ((v) ? (vec_capacity (v,0) - vec_header_bytes (0)) / sizeof (v[0]) : 0)
 
 /** \brief Set vector length to a user-defined value */
 #ifndef __COVERITY__           /* Coverity gets confused by ASSERT() */