[Iotcon] Fix bug when options is null in RemoteResourceFromJson 63/88263/3
authorMichal Kolodziej <m.kolodziej@samsung.com>
Thu, 15 Sep 2016 13:36:23 +0000 (15:36 +0200)
committerMichal Kolodziej <m.kolodziej@samsung.com>
Fri, 16 Sep 2016 07:26:15 +0000 (09:26 +0200)
[Details] Fixed bug which caused fail on assert in picojson::get method for array.
Function needed an array and value provided was null.

Change-Id: I3942fb65e1f29dbe90b18f5b8a5227afeffe9478
Signed-off-by: Michal Kolodziej <m.kolodziej@samsung.com>
src/iotcon/iotcon_utils.cc

index 1436236..fce0426 100644 (file)
@@ -543,14 +543,17 @@ common::TizenResult IotconUtils::RemoteResourceFromJson(const picojson::object&
     LogAndReturnTizenError(res, ("creating handle failed"));
   }
 
-  // options is optional nullable. if it's not present, just ignore it
+  // options is optional nullable. if it's not present or is null, just ignore it
   auto options_it = source.find(kOptions);
   if (source.end() != options_it) {
-    const auto& options_array = options_it->second.get<picojson::array>();
     iotcon_options_h options = nullptr;
-    res = IotconUtils::OptionsFromJson(options_array, &options);
-    if (!res) {
-      return res;
+    // if array supplied, set it. Other cases just clear options with nullptr
+    if (options_it->second.is<picojson::array>()) {
+      const auto& options_array = options_it->second.get<picojson::array>();
+      res = IotconUtils::OptionsFromJson(options_array, &options);
+      if (!res) {
+        return res;
+      }
     }
     res = IotconUtils::ConvertIotconError(iotcon_remote_resource_set_options((*ptr)->handle, options));
     if (!res) {