Add check routine 45/172045/6
authormk5004.lee <mk5004.lee@samsung.com>
Fri, 9 Mar 2018 07:51:03 +0000 (16:51 +0900)
committermk5004.lee <mk5004.lee@samsung.com>
Tue, 13 Mar 2018 01:34:49 +0000 (10:34 +0900)
- parameter, mem alloc fail, etc

Change-Id: I954157bc8474267161f159dd1e7992732c90aac5
Signed-off-by: mk5004.lee <mk5004.lee@samsung.com>
unittest/src/test_design_element.cc
watchface-complication-provider/watchface-complication-provider.cc
watchface-complication/complication.cc
watchface-complication/design-element.cc
watchface-complication/editables-container.cc
watchface-complication/include/watchface-complication.h
watchface-complication/received-editable.cc
watchface-complication/watchface-complication.cc
watchface-complication/watchface-editable.cc
watchface-editor/editables-editor.cc
watchface-editor/watchface-editor.cc

index 32610c2..ccf6d48 100755 (executable)
@@ -93,8 +93,8 @@ TEST_F(DE, GetData)
 
 TEST_F(DE, GetCurDataIdx)
 {
-  EXPECT_EQ(DE::element->SetCurDataIdx(1), 0);
-  EXPECT_EQ(DE::element->GetCurDataIdx(), 1);
+  EXPECT_EQ(DE::element->SetCurDataIdx(0), 0);
+  EXPECT_EQ(DE::element->GetCurDataIdx(), 0);
 }
 
 TEST_F(DE, GetName)
index 941bca1..abc4c60 100644 (file)
@@ -96,6 +96,9 @@ class WatchComplicationProviderStub : public ComplicationProvider {
 static std::map<string, WatchComplicationProviderStub*> __providers;
 extern "C" EXPORT_API int complication_provider_update_request_cb_add(
   const char *provider_id, on_update_request cb, void *user_data) {
+  if (provider_id == NULL || cb == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   // TODO(?): Provider ID validation
   // TODO(?): Get provider's support type from storage
   int support_types = ShortText | Image;
@@ -113,11 +116,17 @@ extern "C" EXPORT_API int complication_provider_update_request_cb_add(
 
 extern "C" EXPORT_API int complication_provider_update_request_cb_del(
   const char *provider_id, on_update_request cb, void *user_data) {
+  if (provider_id == NULL || cb == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   return 0;
 }
 
 extern "C" EXPORT_API int complication_provider_get_support_types(
   const char *provider_id, int *types) {
+  if (provider_id == NULL || types == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   return 0;
 }
 
index a88876f..8b28559 100755 (executable)
@@ -18,6 +18,7 @@
 #include <unistd.h>
 #include <aul.h>
 #include <appsvc.h>
+#include <stdexcept>
 
 #include "watchface-complication/complication.h"
 #include "watchface-complication/complication-implementation.h"
@@ -62,6 +63,9 @@ Complication::Impl::Impl(Complication* parent, int id,
         parent_->GetProviderList(static_cast<ComplicationType>(type));
     for (auto& provider_id : provider_list) {
       bundle* data = bundle_create();
+      if (data == NULL)
+        std::runtime_error("bundle create failed");
+
       bundle_add_str(data, provider_id_key_.c_str(), provider_id.c_str());
       bundle_add_str(data, provider_type_key_.c_str(), std::to_string(type).c_str());
       candidates_list_.emplace_back(new Bundle(data));
@@ -384,6 +388,10 @@ const char* Complication::GetCurProviderId() {
 
 const char* Complication::GetProviderId(Bundle& data) {
   char* provider_id = NULL;
+
+  if (data.GetRaw() == nullptr)
+    return NULL;
+
   bundle_get_str(data.GetRaw(), impl_->provider_id_key_.c_str(), &provider_id);
 
   return provider_id;
@@ -404,6 +412,10 @@ int Complication::GetCurType() {
 int Complication::GetType(Bundle& data) {
   char* type;
   int ret = -1;
+
+  if (data.GetRaw() == nullptr)
+    return ret;
+
   bundle_get_str(data.GetRaw(), impl_->provider_type_key_.c_str(), &type);
 
   if (type)
@@ -417,6 +429,9 @@ const std::string& Complication::GetName() {
 }
 
 void Complication::SetName(const std::string& name) {
+  if (name.empty())
+    return;
+
   impl_->name_ = name;
 }
 
@@ -475,6 +490,8 @@ void Complication::SendDataUpdateRequest() {
   std::string provider_appid = impl_->GetProviderAppId();
   const char* context_data_raw = "";
   bundle *arg_list = bundle_create();
+  if (arg_list == NULL)
+    std::runtime_error("bundle create failed");
 
   appsvc_set_operation(arg_list, APPSVC_OPERATION_DEFAULT);
   appsvc_set_appid(arg_list, provider_appid.c_str());
index e460c99..3582610 100644 (file)
@@ -92,6 +92,11 @@ int DesignElement::UpdateLastDataIdx() {
 }
 
 int DesignElement::SetCurDataIdx(int cur_data_idx) {
+  if (cur_data_idx < 0 || cur_data_idx >= (int)impl_->candidates_list_.size()) {
+    LOGE("Invalid index");
+    return -1;
+  }
+
   LOGI("set cur data %d", cur_data_idx);
   impl_->cur_data_idx_ = cur_data_idx;
   return 0;
@@ -102,6 +107,9 @@ const std::string& DesignElement::GetName() {
 }
 
 void DesignElement::SetName(const std::string& name) {
+  if (name.empty())
+    return;
+
   impl_->name_ = name;
 }
 
index e34b055..594b8e5 100644 (file)
@@ -120,9 +120,18 @@ int EditablesContainer::RequestEdit(const std::string& editor_id) {
   bundle_raw *str_raw = NULL;
   std::unique_ptr<const char*[]> list_arr(new const char*[impl_->ed_list_.size()]);
 
+  if (editor_id.empty())
+    return -1;
+
   for (auto& i : impl_->ed_list_) {
     i.get()->SetState(IEditable::OnGoing);
     bundle* ed = bundle_create();
+    if (ed == NULL) {
+      if (str_raw)
+        free(str_raw);
+      return -1;
+    }
+
     bundle_add(ed, "EDITABLE_ID", std::to_string(i.get()->GetId()).c_str());
 
     int cur_data_idx = i.get()->GetCurDataIdx();
@@ -152,6 +161,12 @@ int EditablesContainer::RequestEdit(const std::string& editor_id) {
   }
 
   bundle* container = bundle_create();
+  if (container == NULL) {
+    if (str_raw)
+      free(str_raw);
+    return -1;
+  }
+
   bundle_add_str_array(container, "EDITABLE_LIST", list_arr.get(), list_idx);
   bundle_encode(container, &str_raw, &str_len);
 
@@ -181,11 +196,17 @@ void EditablesContainer::OnEditReady(const std::string& editor_id) {
 }
 
 int EditablesContainer::Add(std::shared_ptr<IEditable> ed) {
+  if (ed == nullptr)
+    return -1;
+
   impl_->ed_list_.push_back(ed);
   return 0;
 }
 
 int EditablesContainer::Remove(std::shared_ptr<IEditable> ed) {
+  if (ed == nullptr)
+    return -1;
+
   for (auto& i : impl_->ed_list_) {
     if (i.get() == ed.get()) {
       impl_->ed_list_.remove(i);
index 9775906..a1032b8 100644 (file)
@@ -25,12 +25,19 @@ extern "C" {
 #endif
 
 typedef enum _complication_type {
+  COMPLICATION_TYPE_NONE = 0x00,
   COMPLICATION_SHORT_TEXT = 0x01,
   COMPLICATION_LONG_TEXT = 0x02,
   COMPLICATION_RANGED_VALUE = 0x04,
   COMPLICATION_TIME = 0x08,
   COMPLICATION_ICON = 0x10,
   COMPLICATION_IMAGE = 0x20,
+  COMPLICATION_TYPE_MAX = COMPLICATION_SHORT_TEXT |
+                          COMPLICATION_LONG_TEXT |
+                          COMPLICATION_RANGED_VALUE |
+                          COMPLICATION_TIME |
+                          COMPLICATION_ICON |
+                          COMPLICATION_IMAGE,
 } complication_type;
 
 typedef enum _complication_shape_type {
index 439bb08..240b389 100644 (file)
@@ -37,6 +37,8 @@ ReceivedEditable::ReceivedEditable(std::string raw)
 ReceivedEditable::~ReceivedEditable() = default;
 ReceivedEditable::Impl::Impl(ReceivedEditable* parent, std::string raw)
   : parent_(parent) {
+  if (raw.empty())
+    return;
 
   bundle* data = bundle_decode(
                    reinterpret_cast<const bundle_raw*>(
@@ -116,6 +118,11 @@ Bundle& ReceivedEditable::GetNthData(int nth) {
 }
 
 int ReceivedEditable::SetCurDataIdx(int cur_data_idx) {
+  if (cur_data_idx < 0 || cur_data_idx >= (int)impl_->candidates_list_.size()) {
+    LOGE("Invalid index");
+    return -1;
+  }
+
   impl_->cur_data_idx_ = cur_data_idx;
   return 0;
 }
@@ -123,7 +130,11 @@ int ReceivedEditable::SetCurDataIdx(int cur_data_idx) {
 const std::string& ReceivedEditable::GetName() {
   return impl_->name_;
 }
+
 void ReceivedEditable::SetName(const std::string& name) {
+  if (name.empty())
+    return;
+
   impl_->name_ = name;
 }
 
index 7ec3095..a427e72 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
@@ -100,6 +99,8 @@ class WatchComplicationStub : public Complication {
 
 extern "C" EXPORT_API int complication_update_cb_add(complication_h handle,
     on_complication_update cb, void *user_data) {
+  if (handle == NULL || cb == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
 
   auto sh = static_cast<SharedHandle<WatchComplicationStub>*>(handle);
   auto ptr = SharedHandle<WatchComplicationStub>::Share(sh);
@@ -110,15 +111,24 @@ extern "C" EXPORT_API int complication_update_cb_add(complication_h handle,
 
 extern "C" EXPORT_API int complication_update_cb_del(complication_h handle,
     on_complication_update cb) {
+  if (handle == NULL || cb == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   return 0;
 }
 
 extern "C" EXPORT_API int complication_set_provider(const char *provider_id) {
+  if (provider_id == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   return 0;
 }
 
 extern "C" EXPORT_API int complication_send_update_request(
     complication_h handle) {
+ if (handle == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   LOGI("update call!!");
   auto sh = static_cast<SharedHandle<WatchComplicationStub>*>(handle);
   auto ptr = SharedHandle<WatchComplicationStub>::Share(sh);
@@ -128,12 +138,9 @@ extern "C" EXPORT_API int complication_send_update_request(
 }
 
 extern "C" EXPORT_API int complication_get_id(complication_h handle) {
-  return -1;
-}
+  if (handle == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
 
-int __get_complication_data(int complication_id, char **provider_id,
-                            complication_type *comp_type) {
-  // TODO(?): return saved value
   return -1;
 }
 
@@ -141,6 +148,10 @@ extern "C" EXPORT_API int complication_create(int complication_id,
     const char *default_provider_id, complication_type default_type,
     int support_types, complication_shape_type shape_type,
     complication_h *created_handle) {
+  if (support_types <= COMPLICATION_TYPE_NONE ||
+      support_types > COMPLICATION_TYPE_MAX)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   // TODO(?) check default value and type is valid
   auto ws = new WatchComplicationStub(
               complication_id,
@@ -157,6 +168,8 @@ extern "C" EXPORT_API int complication_create(int complication_id,
 }
 
 extern "C" EXPORT_API int complication_destroy(complication_h handle) {
+  if (handle == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
 
   auto sh = static_cast<SharedHandle<WatchComplicationStub>*>(handle);
   delete sh;
@@ -166,6 +179,9 @@ extern "C" EXPORT_API int complication_destroy(complication_h handle) {
 
 extern "C" EXPORT_API int complication_get_cur_provider_id(complication_h handle,
     const char** cur_provider_id) {
+  if (handle == NULL || cur_provider_id == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   auto sh = static_cast<SharedHandle<WatchComplicationStub>*>(handle);
   auto ptr = SharedHandle<WatchComplicationStub>::Share(sh);
   *cur_provider_id = ptr.get()->GetCurProviderId();
@@ -175,6 +191,9 @@ extern "C" EXPORT_API int complication_get_cur_provider_id(complication_h handle
 
 extern "C" EXPORT_API int complication_get_cur_type(complication_h handle,
     complication_type* cur_type) {
+  if (handle == NULL || cur_type == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   auto sh = static_cast<SharedHandle<WatchComplicationStub>*>(handle);
   auto ptr = SharedHandle<WatchComplicationStub>::Share(sh);
   int ret = ptr.get()->GetCurType();
@@ -186,6 +205,9 @@ extern "C" EXPORT_API int complication_get_cur_type(complication_h handle,
 
 extern "C" EXPORT_API int complication_get_provider_id(const bundle* candidate,
     const char** provider_id) {
+  if (candidate == NULL || provider_id == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   char* val = NULL;
 
   bundle_get_str(const_cast<bundle*>(candidate),
@@ -200,6 +222,9 @@ extern "C" EXPORT_API int complication_get_provider_id(const bundle* candidate,
 
 extern "C" EXPORT_API int complication_get_type(const bundle* candidate,
     complication_type* cur_type) {
+  if (candidate == NULL || cur_type == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   char* val = NULL;
 
   bundle_get_str(const_cast<bundle*>(candidate),
@@ -210,4 +235,4 @@ extern "C" EXPORT_API int complication_get_type(const bundle* candidate,
     return -1;
 
   return 0;
-}
\ No newline at end of file
+}
index 5c0b518..303d4dc 100644 (file)
@@ -130,6 +130,9 @@ static EditablesContainerStub *__container;
 extern "C" EXPORT_API int editable_add_design_element(editable_container_h handle,
     int edit_id, int cur_data_idx, GList* candiatelist, editable_geo geo,
     const char* editable_name) {
+  if (handle == NULL || candiatelist == NULL || editable_name == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   EditablesContainerStub* ec = static_cast<EditablesContainerStub*>(handle);
   bundle* data;
   int str_len = 0;
@@ -160,6 +163,9 @@ extern "C" EXPORT_API int editable_add_design_element(editable_container_h handl
 extern "C" EXPORT_API int editable_add_complication(editable_container_h handle,
     int edit_id, complication_h comp, editable_geo geo,
     const char* editable_name) {
+  if (handle == NULL || comp == NULL || editable_name == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   EditablesContainerStub* ec = static_cast<EditablesContainerStub*>(handle);
   SharedHandle<IEditable>* sh = static_cast<SharedHandle<IEditable>*>(comp);
 
@@ -172,6 +178,9 @@ extern "C" EXPORT_API int editable_add_complication(editable_container_h handle,
 
 extern "C" EXPORT_API int editable_request_edit(editable_container_h handle,
     const char *editor_appid, on_editable_update cb, void *user_data) {
+  if (handle == NULL || editor_appid == NULL || cb == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   EditablesContainerStub* ec = static_cast<EditablesContainerStub*>(handle);
   auto ci = new UpdateCallbackInfo(cb, user_data);
   ec->ClearUpdateCallbackInfo();
@@ -185,6 +194,9 @@ extern "C" EXPORT_API int editable_request_edit(editable_container_h handle,
 
 extern "C" EXPORT_API int editable_on_edit_ready_cb_add(on_edit_ready cb,
     void *user_data) {
+  if (cb == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   if (__container == NULL)
     __container = new EditablesContainerStub();
 
@@ -195,11 +207,17 @@ extern "C" EXPORT_API int editable_on_edit_ready_cb_add(on_edit_ready cb,
 }
 
 extern "C" EXPORT_API int editable_on_edit_ready_cb_del(on_edit_ready cb) {
+  if (cb == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   return 0;
 }
 
 extern "C" EXPORT_API int editable_get_cur_data_idx(const editable_h handle,
     int *idx) {
+  if (handle == NULL || idx == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   IEditable* ie = static_cast<IEditable*>(handle);
   *idx = ie->GetCurDataIdx();
   return 0;
@@ -207,6 +225,9 @@ extern "C" EXPORT_API int editable_get_cur_data_idx(const editable_h handle,
 
 extern "C" EXPORT_API int editable_set_cur_data_idx(const editable_h handle,
     int idx) {
+  if (handle == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   IEditable* ie = static_cast<IEditable*>(handle);
   ie->SetCurDataIdx(idx);
   return 0;
@@ -214,6 +235,9 @@ extern "C" EXPORT_API int editable_set_cur_data_idx(const editable_h handle,
 
 extern "C" EXPORT_API int editable_get_cur_data(const editable_h handle,
     bundle **cur_data) {
+  if (handle == NULL || cur_data == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   IEditable* ie = static_cast<IEditable*>(handle);
   Bundle& data = ie->GetCurData();
   *cur_data = data.GetRaw();
@@ -222,6 +246,9 @@ extern "C" EXPORT_API int editable_get_cur_data(const editable_h handle,
 
 extern "C" EXPORT_API int editable_get_nth_data(const editable_h handle,
     int nth, bundle **cur_data) {
+  if (handle == NULL || cur_data == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   IEditable* ie = static_cast<IEditable*>(handle);
   Bundle& data = ie->GetNthData(nth);
   *cur_data = data.GetRaw();
@@ -230,6 +257,9 @@ extern "C" EXPORT_API int editable_get_nth_data(const editable_h handle,
 
 extern "C" EXPORT_API int editable_get_editable_id(const editable_h handle,
     int *editable_id) {
+  if (handle == NULL || editable_id == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   IEditable* ie = static_cast<IEditable*>(handle);
   *editable_id = ie->GetId();
 
@@ -237,16 +267,25 @@ extern "C" EXPORT_API int editable_get_editable_id(const editable_h handle,
 }
 extern "C" EXPORT_API int editable_get_geometry(const editable_h handle,
     editable_geo *geo) {
+  if (handle == NULL || geo == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   return 0;
 }
 
 extern "C" EXPORT_API int editable_get_candidates_list(const editable_h handle,
     GList **candiates_list) {
+  if (handle == NULL || candiates_list == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   return 0;
 }
 
 extern "C" EXPORT_API int editable_get_editable_name(const editable_h handle,
     const char **editable_name) {
+  if (handle == NULL || editable_name == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   IEditable* ie = static_cast<IEditable*>(handle);
   if (!ie->GetName().empty())
     *editable_name = ie->GetName().c_str();
@@ -255,6 +294,9 @@ extern "C" EXPORT_API int editable_get_editable_name(const editable_h handle,
 
 extern "C" EXPORT_API int editable_set_editable_name(const editable_h handle,
     const char *editable_name) {
+  if (handle == NULL || editable_name == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   IEditable* ie = static_cast<IEditable*>(handle);
   ie->SetName(std::string(editable_name));
   return 0;
index 03ce833..f4fd1c5 100644 (file)
@@ -17,6 +17,7 @@
 #include <glib.h>
 #include <unistd.h>
 #include <utility>
+#include <stdexcept>
 
 #include "watchface-editor/editables-editor.h"
 #include "watchface-editor/editables-editor-implementation.h"
@@ -73,6 +74,9 @@ void EditablesEditor::Impl::OnSignal(const std::string& sender_name,
     const char **str_arr = NULL;
     int len = 0;
 
+    if (data == NULL)
+      throw std::runtime_error("bundle decode failed");
+
     str_arr = bundle_get_str_array(data, "EDITABLE_LIST", &len);
     for (int i = 0; i < len; i++) {
       e_list.emplace_back(std::unique_ptr<IEditable>(
@@ -142,6 +146,9 @@ int EditablesEditor::EditCancel() {
 }
 
 int EditablesEditor::NotifyEditReady(std::string appid) {
+  if (appid.empty())
+    return -1;
+
   ComplicationConnector::GetInst().EmitSignal(
     ComplicationConnector::Editable,
     appid,
index 14330a4..4ae429d 100644 (file)
@@ -99,6 +99,9 @@ class EditablesEditorStub : public EditablesEditor {
 static std::unique_ptr<EditablesEditorStub> __stub = nullptr;
 extern "C" EXPORT_API int editor_on_request_edit_cb_add(on_request_edit cb,
     void *user_data) {
+  if (cb == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   if (__stub == nullptr)
     __stub = std::unique_ptr<EditablesEditorStub>(new EditablesEditorStub());
 
@@ -109,11 +112,17 @@ extern "C" EXPORT_API int editor_on_request_edit_cb_add(on_request_edit cb,
 }
 
 extern "C" EXPORT_API int editor_on_request_edit_cb_del(on_request_edit cb) {
+  if (cb == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   return 0;
 }
 
 extern "C" EXPORT_API int editor_edit_preview(const editable_h ed_h,
     int cur_data_idx) {
+ if (ed_h == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   IEditable* ed = static_cast<IEditable*>(ed_h);
   ed->SetCurDataIdx(cur_data_idx);
   return __stub->EditPreview(*ed, cur_data_idx);
@@ -128,6 +137,9 @@ extern "C" EXPORT_API int editor_edit_cancel() {
 }
 
 extern "C" EXPORT_API int editor_notify_edit_ready(const char *appid) {
+  if (appid == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   if (__stub == nullptr)
     __stub = std::unique_ptr<EditablesEditorStub>(new EditablesEditorStub());
   else
@@ -140,6 +152,9 @@ extern "C" EXPORT_API int editor_notify_edit_ready(const char *appid) {
 
 extern "C" EXPORT_API int editor_foreach_editable_list(editable_list_h list_h,
     editable_list_foreach_cb cb, void *user_data) {
+  if (list_h == NULL || cb == NULL)
+    return COMPLICATION_ERROR_INVALID_PARAMETER;
+
   GList *iter = list_h;
   while (iter) {
     cb((editable_h)iter->data, user_data);
@@ -151,6 +166,11 @@ extern "C" EXPORT_API int editor_foreach_editable_list(editable_list_h list_h,
 
 extern "C" EXPORT_API editable_list_h editor_editable_list_dup(
   editable_list_h source) {
+  if (source == NULL) {
+    LOGE("Invalid parameter");
+    return NULL;
+  }
+
   GList* dest = NULL;
   GList* iter = source;
   while (iter) {
@@ -172,6 +192,11 @@ extern "C" EXPORT_API int editor_editable_list_size(editable_list_h list) {
 
 extern "C" EXPORT_API const editable_h editor_editable_list_nth(
   editable_list_h list, int nth) {
+  if (list == NULL) {
+    LOGE("Invalid parameter");
+    return NULL;
+  }
+
   GList* iter = list;
   int idx = 0;
   while (iter) {
@@ -185,6 +210,11 @@ extern "C" EXPORT_API const editable_h editor_editable_list_nth(
 
 
 extern "C" EXPORT_API int editor_editable_candidate_list_size(const editable_h ed_h) {
+  if (ed_h == NULL) {
+    LOGE("Invalid parameter");
+    return -1;
+  }
+
   IEditable* ed = static_cast<IEditable*>(ed_h);
   std::list<std::unique_ptr<Bundle>> const& list = ed->GetCandidates();
   return list.size();
@@ -192,6 +222,11 @@ extern "C" EXPORT_API int editor_editable_candidate_list_size(const editable_h e
 
 extern "C" EXPORT_API const bundle* editor_editable_candidate_list_nth(
   const editable_h ed_h, int nth) {
+  if (ed_h == NULL) {
+    LOGE("Invalid parameter");
+    return NULL;
+  }
+
   IEditable* ed = static_cast<IEditable*>(ed_h);
   const std::list<std::unique_ptr<Bundle>>& list = ed->GetCandidates();
   const std::list<std::unique_ptr<Bundle>>::const_iterator it