From e7285749ed5aec53d77b276ccd966e6ac9e3db49 Mon Sep 17 00:00:00 2001 From: Pawel Wodkowski Date: Thu, 15 Feb 2018 18:58:21 +0100 Subject: [PATCH] lib/util: return const pointer from spdk_cpuset_fmt Change-Id: Iab5f9703ae9235fd3820228127d72e85af9826bc Signed-off-by: Pawel Wodkowski Reviewed-on: https://review.gerrithub.io/400601 Tested-by: SPDK Automated Test System Reviewed-by: Jim Harris Reviewed-by: Daniel Verkamp --- include/spdk/cpuset.h | 4 +++- lib/util/cpuset.c | 2 +- test/unit/lib/util/cpuset.c/cpuset_ut.c | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/spdk/cpuset.h b/include/spdk/cpuset.h index 59f98d421..1e0f73aae 100644 --- a/include/spdk/cpuset.h +++ b/include/spdk/cpuset.h @@ -136,8 +136,10 @@ uint32_t spdk_cpuset_count(const struct spdk_cpuset *set); * \param CPU set. * \return Pointer to hexadecimal representation of CPU set. Buffer to store a * string is dynamically allocated internally and freed with CPU set object. + * Memory returned by this function might be changed after subsequent calls to + * this function so string should be copied by user. */ -char *spdk_cpuset_fmt(struct spdk_cpuset *set); +const char *spdk_cpuset_fmt(struct spdk_cpuset *set); /** * Convert a string containing a CPU core mask into a CPU set. diff --git a/lib/util/cpuset.c b/lib/util/cpuset.c index 6d74ea77e..1a02e59fe 100644 --- a/lib/util/cpuset.c +++ b/lib/util/cpuset.c @@ -132,7 +132,7 @@ spdk_cpuset_count(const struct spdk_cpuset *set) return count; } -char * +const char * spdk_cpuset_fmt(struct spdk_cpuset *set) { uint32_t lcore, lcore_max = 0; diff --git a/test/unit/lib/util/cpuset.c/cpuset_ut.c b/test/unit/lib/util/cpuset.c/cpuset_ut.c index 058b6c049..6fea0ad3e 100644 --- a/test/unit/lib/util/cpuset.c/cpuset_ut.c +++ b/test/unit/lib/util/cpuset.c/cpuset_ut.c @@ -189,7 +189,7 @@ test_cpuset_fmt(void) int i; uint32_t lcore; struct spdk_cpuset *core_mask = spdk_cpuset_alloc(); - char *hex_mask; + const char *hex_mask; char hex_mask_ref[SPDK_CPUSET_SIZE / 4 + 1]; /* Clear coremask. hex_mask should be "0" */