Add code to check return value 33/185133/1
authorjusung son <jusung07.son@samsung.com>
Thu, 26 Jul 2018 07:17:46 +0000 (16:17 +0900)
committerjusung son <jusung07.son@samsung.com>
Thu, 26 Jul 2018 07:17:46 +0000 (16:17 +0900)
Change-Id: Ia1f574e6cde732499eef33b3092306d12a7cf0f4
Signed-off-by: jusung son <jusung07.son@samsung.com>
watchface-complication/complication.cc
watchface-complication/design-element.cc
watchface-editor/editables-editor.cc
watchface-editor/watchface-editor.cc

index 93b91f7..0afde7c 100644 (file)
@@ -305,8 +305,7 @@ void Complication::SetGeo(IEditable::Geometry geo) {
 
 int Complication::SetCandidates(
     std::list<std::unique_ptr<Bundle>> candidates_list) {
-  UpdateCandidatesInfo();
-  return WATCHFACE_COMPLICATION_ERROR_NONE;
+  return UpdateCandidatesInfo();
 }
 
 std::list<std::unique_ptr<Bundle>> const& Complication::GetCandidates() const {
@@ -349,12 +348,16 @@ int Complication::GetLastDataIdx() {
 }
 
 int Complication::Impl::UpdateLastDataFields() {
+  int ret;
+
   last_provider_id_ = cur_provider_id_;
   last_type_ = cur_type_;
   last_data_idx_ = cur_data_idx_;
-  LoadPeriod();
-  LoadLabel();
-  return WATCHFACE_COMPLICATION_ERROR_NONE;
+  ret = LoadPeriod();
+  if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
+    return ret;
+  ret = LoadLabel();
+  return ret;;
 }
 
 int Complication::Impl::LoadLabel() {
@@ -398,7 +401,10 @@ int Complication::UpdateLastData() {
   if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
     return ret;
 
-  impl_->UpdateLastDataFields();
+  ret = impl_->UpdateLastDataFields();
+  if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
+    return ret;
+
   LOGI("update last data idx : %d", impl_->last_data_idx_);
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
@@ -803,10 +809,10 @@ int Complication::UpdateCandidatesInfo() {
       impl_->cur_provider_id_, impl_->cur_type_);
   if (idx != -1) {
     impl_->cur_data_idx_ = idx;
-    impl_->UpdateLastDataFields();
+    ret = impl_->UpdateLastDataFields();
   }
 
-  return WATCHFACE_COMPLICATION_ERROR_NONE;
+  return ret;
 }
 
 int Complication::ApplyAllowedList(
index b92d72d..5f284db 100644 (file)
@@ -117,10 +117,18 @@ int DesignElement::UpdateLastData() {
     return WATCHFACE_COMPLICATION_ERROR_NO_DATA;
 
   bundle_raw* raw_data = NULL;
-  int raw_len;
-  bundle_encode(const_cast<Bundle*>(cur_data)->GetRaw(), &raw_data, &raw_len);
+  int raw_len, ret;
+  ret = bundle_encode(const_cast<Bundle*>(cur_data)->GetRaw(), &raw_data, &raw_len);
+  if (ret != BUNDLE_ERROR_NONE) {
+    if (ret == BUNDLE_ERROR_OUT_OF_MEMORY) {
+      return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
+    } else {
+      LOGE("bundle encode fail");
+      return WATCHFACE_COMPLICATION_ERROR_NO_DATA;
+    }
+  }
   try {
-    int ret = EditablesManager::GetInst().StoreSetting(impl_->id_, raw_data);
+    ret = EditablesManager::GetInst().StoreSetting(impl_->id_, raw_data);
     free(raw_data);
 
     if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
@@ -197,7 +205,13 @@ int DesignElement::UpdateLastContext() {
     LOGI("Empty context");
     return WATCHFACE_COMPLICATION_ERROR_NONE;
   }
-  impl_->last_context_data_.reset(new Bundle((impl_->context_data_.get())->GetRaw()));
+
+  try {
+    impl_->last_context_data_.reset(new Bundle((impl_->context_data_.get())->GetRaw()));
+  } catch (Exception &ex) {
+    LOGE("%s %d", ex.what(), ex.GetErrorCode());
+    return ex.GetErrorCode();
+  }
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
 
index 9c2c46d..99f397e 100644 (file)
@@ -174,7 +174,9 @@ int EditablesEditor::EditPreview(IEditable& ed, int cur_data_idx) {
     return ret;
 
   ReceivedEditable& re = static_cast<ReceivedEditable&>(ed);
-  re.SetCurDataIdx(cur_data_idx);
+  ret = re.SetCurDataIdx(cur_data_idx);
+  if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
+    return ret;
 
   Bundle *context = re.GetContext().get();
   try {
index dcc181d..5e39280 100644 (file)
@@ -207,13 +207,18 @@ extern "C" EXPORT_API int watchface_editor_remove_request_edit_cb(
 extern "C" EXPORT_API int watchface_editor_edit_preview(
     watchface_editable_h handle,
     int cur_data_idx) {
+  int ret;
+
   if (handle == NULL) {
     LOGE("Invalid parameter");
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
   }
 
   IEditable* ed = static_cast<IEditable*>(handle);
-  ed->SetCurDataIdx(cur_data_idx);
+  ret = ed->SetCurDataIdx(cur_data_idx);
+  if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
+    return ret;
+
   return __stub->EditPreview(*ed, cur_data_idx);
 }
 
@@ -351,13 +356,17 @@ extern "C" EXPORT_API int watchface_editor_editable_candidate_list_get_nth(
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
   }
 
+  bundle* tmp;
   IEditable* ed = static_cast<IEditable*>(handle);
   const std::list<std::unique_ptr<Bundle>>& list = ed->GetCandidates();
   const std::list<std::unique_ptr<Bundle>>::const_iterator it
                                   = list.begin();
   auto nx = std::next(it, nth);
-  *data = bundle_dup(((*nx).get())->GetRaw());
+  tmp = bundle_dup(((*nx).get())->GetRaw());
+  if (tmp == NULL)
+    return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
 
+  *data = tmp;
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
 
@@ -366,12 +375,17 @@ extern "C" EXPORT_API int watchface_editor_get_setup_appid(
   if (handle == NULL || setup_appid == NULL)
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
 
+  char* tmp;
   IEditable* ed = static_cast<IEditable*>(handle);
   std::string appid = ed->GetSetupAppId();
   if (appid.empty())
     return WATCHFACE_COMPLICATION_ERROR_NO_DATA;
-  *setup_appid = strdup(appid.c_str());
 
+  tmp = strdup(appid.c_str());
+  if (tmp == NULL)
+    return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
+
+  *setup_appid = tmp;
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
 
@@ -499,14 +513,19 @@ extern "C" EXPORT_API int watchface_editor_get_complication_provider_id(
   if (complication == NULL || provider_id == NULL)
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
 
-  char *val = NULL;
+  char* val = NULL;
+  char* tmp;
 
   bundle_get_str(const_cast<bundle*>(complication),
       Complication::GetProviderIdKey(), &val);
-  if (val != NULL)
-    *provider_id = strdup(val);
-  else
+  if (val != NULL) {
+    tmp = strdup(val);
+    if (tmp == NULL)
+      return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
+    *provider_id = tmp;
+  } else {
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
 
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }