Check the return value of memory allocation function 94/139394/1
authorJihoon Kim <jihoon48.kim@samsung.com>
Tue, 18 Jul 2017 23:20:28 +0000 (08:20 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Tue, 18 Jul 2017 23:20:28 +0000 (08:20 +0900)
Change-Id: I8da6df0ecbc416cdcfbda6d1921196365262eb7d
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
ism/extras/wayland_immodule/wayland_imcontext.c

index a55529f..65719ed 100644 (file)
@@ -1807,6 +1807,7 @@ text_input_preedit_styling(void                 *data,
 {
     WaylandIMContext *imcontext = (WaylandIMContext *)data;
     Ecore_IMF_Preedit_Attr *attr = calloc(1, sizeof(*attr));
+    if (!attr) return;
 
     switch (style)
     {
@@ -2195,7 +2196,9 @@ text_input_input_panel_data(void                 *data,
         free (imcontext->input_panel_data);
 
     imcontext->input_panel_data = calloc (1, length);
-    memcpy (imcontext->input_panel_data, input_panel_data, length);
+    if (imcontext->input_panel_data)
+        memcpy (imcontext->input_panel_data, input_panel_data, length);
+
     imcontext->input_panel_data_length = length;
 }
 
@@ -2813,18 +2816,22 @@ wayland_im_context_preedit_string_with_attributes_get(Ecore_IMF_Context  *ctx,
         if (imcontext->preedit_attrs) {
             EINA_LIST_FOREACH(imcontext->preedit_attrs, l, a) {
                 attr = malloc(sizeof(*attr));
-                attr = memcpy(attr, a, sizeof(*attr));
-                *attrs = eina_list_append(*attrs, attr);
+                if (attr) {
+                    attr = memcpy(attr, a, sizeof(*attr));
+                    *attrs = eina_list_append(*attrs, attr);
+                }
             }
         }
         else {
             if (imcontext->preedit_text) {
                 Ecore_IMF_Preedit_Attr *attr = calloc(1, sizeof(*attr));
-                // use REVERSE style as default
-                attr->preedit_type = ECORE_IMF_PREEDIT_TYPE_SUB2;
-                attr->start_index = 0;
-                attr->end_index = strlen(imcontext->preedit_text);
-                *attrs = eina_list_append(*attrs, attr);
+                if (attr) {
+                    // use REVERSE style as default
+                    attr->preedit_type = ECORE_IMF_PREEDIT_TYPE_SUB2;
+                    attr->start_index = 0;
+                    attr->end_index = strlen(imcontext->preedit_text);
+                    *attrs = eina_list_append(*attrs, attr);
+                }
             }
         }
     }
@@ -3429,7 +3436,9 @@ wayland_im_context_input_panel_imdata_set(Ecore_IMF_Context *ctx, const void *da
         free(imcontext->imdata);
 
     imcontext->imdata = calloc(1, length);
-    memcpy(imcontext->imdata, data, length);
+    if (imcontext->imdata)
+        memcpy(imcontext->imdata, data, length);
+
     imcontext->imdata_size = length;
 
     if (imcontext->input && imcontext->text_input && (imcontext->imdata_size > 0))
@@ -3526,9 +3535,10 @@ wayland_im_context_input_panel_position_set (Ecore_IMF_Context *ctx, int x, int
 WaylandIMContext *wayland_im_context_new (struct wl_text_input_manager *text_input_manager)
 {
     WaylandIMContext *context = calloc(1, sizeof(WaylandIMContext));
-
-    LOGD("new context created");
-    context->text_input_manager = text_input_manager;
+    if (context) {
+        LOGD("new context created");
+        context->text_input_manager = text_input_manager;
+    }
 
     return context;
 }