ensure variable initialized and error path reported
New upstream yocto brings in an option that ensure all variables are
initialized. Without this change, we get this failure:
| ../git/libpldmresponder/bios_integer_attribute.cpp:158:12: error:
| 'value' may be used uninitialized in this function [-Werror=maybe-uninitialized]
| 158 | return value;
| | ^~~~~
| cc1plus: all warnings being treated as errors
There's no good way to report a property type is not found so add code
to raise an exception in this situation.
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: Ie218f72b6d58fa4ad1e99f1a83eb17f3f87cd941
diff --git a/libpldmresponder/bios_integer_attribute.cpp b/libpldmresponder/bios_integer_attribute.cpp
index 43a94d2..4a23ace 100644
--- a/libpldmresponder/bios_integer_attribute.cpp
+++ b/libpldmresponder/bios_integer_attribute.cpp
@@ -122,7 +122,7 @@
uint64_t BIOSIntegerAttribute::getAttrValue(const PropertyValue& propertyValue)
{
- uint64_t value;
+ uint64_t value = 0;
if (dBusMap->propertyType == "uint8_t")
{
value = std::get<uint8_t>(propertyValue);
@@ -155,6 +155,12 @@
{
value = std::get<double>(propertyValue);
}
+ else
+ {
+ std::cerr << "Unsupported property type for getAttrValue: "
+ << dBusMap->propertyType << std::endl;
+ throw std::invalid_argument("dbus type error");
+ }
return value;
}