Fix segfault caused by accessing nullptr
There is a corner cases where "sensors" map contains nullptr when
CPU is not installed or base configuration is invalid. Now presence
of shared_ptr is validated on every loop.
Tested:
- Successfully boot OpenBMC without any crash in adcsensor.
Signed-off-by: Wludzik, Jozef <jozef.wludzik@intel.com>
Change-Id: I267388c004fcbfcd5e3c14b77f95d31aa89f0cc8
diff --git a/src/ADCSensorMain.cpp b/src/ADCSensorMain.cpp
index cc8e7cd..1125c5f 100644
--- a/src/ADCSensorMain.cpp
+++ b/src/ADCSensorMain.cpp
@@ -182,7 +182,8 @@
for (auto it = sensorsChanged->begin();
it != sensorsChanged->end(); it++)
{
- if (boost::ends_with(*it, findSensor->second->name))
+ if (findSensor->second &&
+ boost::ends_with(*it, findSensor->second->name))
{
sensorsChanged->erase(it);
findSensor->second = nullptr;