default_backend: fix some svace issues
[platform/core/uifw/libpui.git] / backends / default_backend.c
index 8ed95cf..5d71cf2 100644 (file)
@@ -24,6 +24,7 @@
  */
 
 #include "default_backend.h"
+#include <limits.h>
 
 pui_backend_ani_func *ani_func = NULL;
 Eina_Hash *_animations_hash = NULL;
@@ -206,25 +207,30 @@ _read_json_file(const char *path, int *data_size)
 {
        FILE *fp = fopen(path, "rb");
        int size;
-       char *buffer;
+       char *buffer = NULL;
        ERROR_CHECK(fp, return NULL, "Failed to open file: %s\n", path);
 
        fseek(fp, 0, SEEK_END);
-       size = ftell(fp);
+       size = (long int)ftell(fp);
        fseek(fp, 0, SEEK_SET);
+       ERROR_CHECK(0 < size && size < INT_MAX, goto error, "Invalid file: %d size\n", size);
 
        buffer = (char *)calloc(sizeof(char), size + 1);
+       ERROR_CHECK(buffer, goto error, "Failed to allocate memory for buffer\n");
 
        if (fread(buffer, size, 1, fp) < 1) {
-               *data_size = 0;
-               free(buffer);
-               fclose(fp);
-               return NULL;
+               goto error;
        }
 
        *data_size = size;
        fclose(fp);
        return buffer;
+
+error:
+       *data_size = 0;
+       if (buffer) free(buffer);
+       fclose(fp);
+       return NULL;
 }
 
 static default_ani_info *
@@ -237,7 +243,7 @@ _read_json(const char *path)
        int data_size = 0, i, j;
 
        buffer = _read_json_file(path, &data_size);
-       ERROR_CHECK(buffer && data_size > 0, return EINA_FALSE, "File %s has no data\n", path);
+       ERROR_CHECK(buffer && data_size > 0, goto error, "File %s has no data\n", path);
        root_obj = json_tokener_parse(buffer);
        ERROR_CHECK(root_obj, goto error, "Failed to tokenize json object\n");
 
@@ -298,7 +304,7 @@ _read_json(const char *path)
        return ani_info;
 
 error:
-       free(buffer);
+       if (buffer) free(buffer);
        if (ani_info) {
                if (ani_info->frames) {
                        for (i = 0; i < ani_info->num_key_frames; i++) {
@@ -385,6 +391,20 @@ _create_ani_collection(void)
        return e;
 }
 
+pui_bool
+_geometry_get(int *width, int *height)
+{
+       if (!width || !height)
+               return 0;
+
+       if (width)
+               *width = DEFAULT_BACKEND_GEOM_WIDTH;
+       if (height)
+               *height = DEFAULT_BACKEND_GEOM_HEIGHT;
+
+       return 1;
+}
+
 pui_int_error
 _is_ani_supported(pui_id id)
 {
@@ -598,6 +618,7 @@ pui_default_backend_init(void)
        }
 
        backend_data->create_ani_collection = _create_ani_collection;
+       backend_data->geometry_get = _geometry_get;
        backend_data->ani_create = _ani_create;
        backend_data->ani_destroy = _ani_destroy;
 
@@ -652,6 +673,7 @@ pui_default_backend_deinit(pui_backend_module_data *backend_data)
        }
 
        backend_data->create_ani_collection = NULL;
+       backend_data->geometry_get = NULL;
        backend_data->ani_create = NULL;
        backend_data->ani_destroy = NULL;