Fix json exception when processing event_configs
power-control is crashing while processing the JSON config:
terminate called after throwing an instance of 'nlohmann::json_abi_v3_11_2::detail::type_error'
what(): [json.exception.type_error.302] type must be boolean, but is object
due to casting the `events` object to a `bool` when the underlying JSON
type is not a boolean.
Tested: Added debug print to show the value of `nmiWhenPoweredOff` and
confirmed that it worked for three cases: true, false, and not specified
in config (defaults to true).
Change-Id: I0182771a4125234df01ec39374531e5c51dec55a
Signed-off-by: Jonathan Doman <jonathan.doman@intel.com>
diff --git a/src/power_control.cpp b/src/power_control.cpp
index 07fc14f..913747a 100644
--- a/src/power_control.cpp
+++ b/src/power_control.cpp
@@ -2423,10 +2423,10 @@
}
}
- // If "events_configs" key is not in json config, fallback to {}
- auto events = jsonData.value(
- "event_configs", nlohmann::json(nlohmann::json::value_t::object));
- if (events)
+ // If "events_configs" key is not in json config, fallback to null
+ auto events = jsonData.value("event_configs",
+ nlohmann::json(nlohmann::json::value_t::null));
+ if (events.is_object())
{
nmiWhenPoweredOff = events.value("NMIWhenPoweredOff", true);
}