aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Yourtchenko <ayourtch@gmail.com>2022-12-02 21:22:37 +0000
committerOle Tr�an <otroan@employees.org>2022-12-05 09:50:18 +0000
commit9067f3332ed0ddc143105b003e614f3f90719916 (patch)
tree9877de9a294f4c39c061c4a7db76090db3268ad2
parent309f7aac170767028a2e6e7e9424ec3d13304aff (diff)
stats: return empty vector rather than NULL if stat_segment_dump_r() is run on an empty vector from ls
The return value in this function is initialized with 0, so if a vector of length 0 is passed to stat_segment_dump_r, then this return value is never populated, resulting in inability to distinguish between a successful dump of an empty vector and an error. Solution: call vec_alloc(). As a side effect might get some trivial speed-up. Type: fix Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com> Change-Id: I33fefd801df457152e9ec257742305182e91f339
-rw-r--r--src/vpp-api/client/stat_client.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/vpp-api/client/stat_client.c b/src/vpp-api/client/stat_client.c
index 5bb6e9f1e56..5bee21a2cfc 100644
--- a/src/vpp-api/client/stat_client.c
+++ b/src/vpp-api/client/stat_client.c
@@ -411,6 +411,15 @@ stat_segment_dump_r (uint32_t * stats, stat_client_main_t * sm)
if (stat_segment_access_start (&sa, sm))
return 0;
+ /* preallocate the elements.
+ * This takes care of a special case where
+ * the vec_len(stats) == 0,
+ * such that we return a vector of
+ * length 0, rather than a null pointer
+ * (since null pointer is an error)
+ */
+ vec_alloc (res, vec_len (stats));
+
for (i = 0; i < vec_len (stats); i++)
{
/* Collect counter */