summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2020-12-15 20:35:11 -0800
committerFlorin Coras <florin.coras@gmail.com>2020-12-16 16:24:18 +0000
commitd6a1acebeae5adb157397b8088042a03f0fa5ee9 (patch)
tree0f58a4b3bc0fa859a87766fa0279d80bfbca8f70
parent5bfaa6e7e3225f06403be718eb6185b5fad01c91 (diff)
vppinfra: fix vec_max_len
Return 0 if the supplied vector pointer is NULL. Type: fix Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: Icb0aab70e0b7c9c1ddcf607c9dfb7e5715f177d1
-rw-r--r--src/vppinfra/vec_bootstrap.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/vppinfra/vec_bootstrap.h b/src/vppinfra/vec_bootstrap.h
index 53968070c0e..5cf5d3b76a1 100644
--- a/src/vppinfra/vec_bootstrap.h
+++ b/src/vppinfra/vec_bootstrap.h
@@ -171,7 +171,8 @@ u32 vec_len_not_inline (void *v);
})
/** \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() */