clang-tidy: Add bugprone-unchecked-optional-access
Enabled the clang-tidy check `bugprone-unchecked-optional-access` to
improve code safety when working with std::optional.
Fixed the following instances where optional values were accessed
without prior validation.
'''
../libipmid/utils.cpp:173:12: error: unchecked access to optional value [bugprone-unchecked-optional-access,-warnings-as-errors]
173 | return cachedService.value();
./chassishandler.cpp:1124:21: error: unchecked access to optional value [bugprone-unchecked-optional-access,-warnings-as-errors]
1124 | sdbusplus::message::convert_from_string<Intrusion::Status>(
'''
Change-Id: I910a6007453be4b01adc9bda36d2d37358de1ace
Signed-off-by: Jayanth Othayoth <ojayanth@gmail.com>
diff --git a/libipmid/utils.cpp b/libipmid/utils.cpp
index f8e8083..7468cf8 100644
--- a/libipmid/utils.cpp
+++ b/libipmid/utils.cpp
@@ -170,6 +170,11 @@
cachedBusName = bus.get_unique_name();
cachedService = ::ipmi::getService(bus, intf, path);
}
+
+ if (!cachedService)
+ {
+ throw std::runtime_error("Service not cached");
+ }
return cachedService.value();
}