Fix code bug
Before fetching any of the JSON's key, need to check it's presence.
If we try to fetch the keyword and it is not present in the json
then code crashes in runtime.
Also, added a check before executing driver binding command, as with
blank i2c address this execution will do nothing.
Signed-off-by: Alpana Kumari <alpankum@in.ibm.com>
Change-Id: I9dc991bd795cf3fad31cbd5da92cf8cd56b8aa6b
diff --git a/ibm_vpd_app.cpp b/ibm_vpd_app.cpp
index 789f1c0..b006a30 100644
--- a/ibm_vpd_app.cpp
+++ b/ibm_vpd_app.cpp
@@ -523,12 +523,16 @@
}
// Now bind the device
- string bind = json["frus"][file].at(0).value("devAddress", "");
- cout << "Binding device " << bind << endl;
- string bindCmd = string("echo \"") + bind +
- string("\" > /sys/bus/i2c/drivers/at24/bind");
- cout << bindCmd << endl;
- executeCmd(bindCmd);
+ if (json["frus"][file].at(0).find("devAddress") !=
+ json["frus"][file].at(0).end())
+ {
+ string bind = json["frus"][file].at(0).value("devAddress", "");
+ cout << "Binding device " << bind << endl;
+ string bindCmd = string("echo \"") + bind +
+ string("\" > /sys/bus/i2c/drivers/at24/bind");
+ cout << bindCmd << endl;
+ executeCmd(bindCmd);
+ }
// Check if device showed up (test for file)
if (!fs::exists(file))