NVMeCache: make the return of getCache() const Returing a const std::span now to privent the receiver from overwriting the cache value. Tested: N/A Google-Bug-Id: 348660385 Signed-off-by: Hao Jiang <jianghao@google.com> Change-Id: I28211a41e4232ec9ded98bd2c89a25e3592a4f8a
diff --git a/src/NVMeCache.hpp b/src/NVMeCache.hpp index e0dce89..ba20773 100644 --- a/src/NVMeCache.hpp +++ b/src/NVMeCache.hpp
@@ -89,7 +89,8 @@ virtual constexpr std::string_view getIdentifier() const noexcept = 0; virtual bool isCacheValid() const noexcept = 0; virtual std::tuple<std::chrono::time_point<ClockType>, - std::chrono::time_point<ClockType>, std::span<uint8_t>> + std::chrono::time_point<ClockType>, + std::span<const uint8_t>> getCache() const noexcept = 0; };
diff --git a/src/NVMeCacheImpl.hpp b/src/NVMeCacheImpl.hpp index 262c4c4..824205f 100644 --- a/src/NVMeCacheImpl.hpp +++ b/src/NVMeCacheImpl.hpp
@@ -50,7 +50,7 @@ return cacheValid; } std::tuple<std::chrono::time_point<ClockType>, - std::chrono::time_point<ClockType>, std::span<uint8_t>> + std::chrono::time_point<ClockType>, std::span<const uint8_t>> getCache() const noexcept override { return {};
diff --git a/src/NVMeMetricStore.cpp b/src/NVMeMetricStore.cpp index c99ad6b..03bb21c 100644 --- a/src/NVMeMetricStore.cpp +++ b/src/NVMeMetricStore.cpp
@@ -3,8 +3,9 @@ #include <xyz/openbmc_project/Common/File/error.hpp> #include <xyz/openbmc_project/Common/error.hpp> -sdbusplus::message::unix_fd MetricStore::writeToFd(std::span<uint8_t> header, - std::span<uint8_t> data) +sdbusplus::message::unix_fd + MetricStore::writeToFd(std::span<const uint8_t> header, + std::span<const uint8_t> data) { std::array<int, 2> pipe{}; if (::pipe(pipe.data()) < 0)
diff --git a/src/NVMeMetricStore.hpp b/src/NVMeMetricStore.hpp index 6871b01..f88b4d5 100644 --- a/src/NVMeMetricStore.hpp +++ b/src/NVMeMetricStore.hpp
@@ -82,8 +82,8 @@ * * @return sdbusplus::message::unix_fd: Returns the read end of the pipe */ - sdbusplus::message::unix_fd writeToFd(std::span<uint8_t> header, - std::span<uint8_t> data); + sdbusplus::message::unix_fd writeToFd(std::span<const uint8_t> header, + std::span<const uint8_t> data); /** * @brief Gets Metric using a unique metric name. Metric must be registered
diff --git a/tests/test_nvme_cache.cpp b/tests/test_nvme_cache.cpp index fdcc189..a56619e 100644 --- a/tests/test_nvme_cache.cpp +++ b/tests/test_nvme_cache.cpp
@@ -51,10 +51,10 @@ MOCK_METHOD(bool, isCacheValid, (), (const, noexcept, override)); - MOCK_METHOD( - (std::tuple<std::chrono::time_point<ClockType>, - std::chrono::time_point<ClockType>, std::span<uint8_t>>), - getCache, (), (const, noexcept, override)); + MOCK_METHOD((std::tuple<std::chrono::time_point<ClockType>, + std::chrono::time_point<ClockType>, + std::span<const uint8_t>>), + getCache, (), (const, noexcept, override)); }; /**