Fix Coverity issue 81/213881/3 accepted/tizen/unified/20190916.111542 submit/tizen/20190916.065445
authorhj kim <backto.kim@samsung.com>
Mon, 16 Sep 2019 06:25:33 +0000 (15:25 +0900)
committerhj kim <backto.kim@samsung.com>
Mon, 16 Sep 2019 07:26:42 +0000 (16:26 +0900)
Change-Id: Ibb420a510910901f109478f625422c30aa474544

include/thumbnail_util_private.h
src/thumbnail_util.c

index 500aafe..7dcde72 100755 (executable)
@@ -59,16 +59,16 @@ typedef enum {
 typedef struct {
        int request_id;
        char *file_path;
-       int dst_width;
-       int dst_height;
+       unsigned int dst_width;
+       unsigned int dst_height;
 } thumbnail_s;
 
 typedef struct {
        char *path;
        thumbnail_util_extract_type_e extract_type;
        thumbnail_util_media_type_e media_type;
-       int width;
-       int height;
+       unsigned int width;
+       unsigned int height;
        char *thumbnail_path;
        unsigned char *buffer;
        int buffer_size;
@@ -104,6 +104,13 @@ typedef struct {
                        } \
                } while (0)
 
+#define thumbnail_util_retm_if(expr, fmt, arg...) do { \
+                       if (expr) { \
+                               LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg); \
+                               return; \
+                       } \
+               } while (0)
+
 #define thumbnail_util_warn(fmt, arg...) do { \
                LOGW(FONT_COLOR_GREEN""fmt""FONT_COLOR_RESET, ##arg);     \
        } while (0)
index f122ac7..059aad8 100644 (file)
@@ -244,7 +244,7 @@ int thumbnail_util_destroy(thumbnail_h thumb)
 
 ////////////////////////////////////////// Sync
 
-void _thumbnail_util_destroy_thumb_data(thumbnail_data_s *thumb)
+static void __thumbnail_util_destroy_thumb_data(thumbnail_data_s *thumb)
 {
        SAFE_FREE(thumb->path);
        SAFE_FREE(thumb->thumbnail_path);
@@ -252,10 +252,15 @@ void _thumbnail_util_destroy_thumb_data(thumbnail_data_s *thumb)
        SAFE_FREE(thumb);
 }
 
-int __thumbnail_util_get_proper_thumb_size(int orig_w, int orig_h, int *thumb_w, int *thumb_h)
+static void __thumbnail_util_get_proper_thumb_size(unsigned int orig_w, unsigned int orig_h, unsigned int *thumb_w, unsigned int *thumb_h)
 {
        bool portrait = false;
-       double ratio;
+       double ratio = 0.0;
+
+       thumbnail_util_retm_if(orig_w == 0, "Invalid orig_w");
+       thumbnail_util_retm_if(orig_h == 0, "Invalid orig_h");
+       thumbnail_util_retm_if(!thumb_w, "Invalid thumb_w");
+       thumbnail_util_retm_if(!thumb_h, "Invalid thumb_h");
 
        if (orig_w < orig_h)
                portrait = true;
@@ -275,10 +280,9 @@ int __thumbnail_util_get_proper_thumb_size(int orig_w, int orig_h, int *thumb_w,
 
        thumbnail_util_debug("proper thumb w: %d h: %d", *thumb_w, *thumb_h);
 
-       return MS_MEDIA_ERR_NONE;
 }
 
-int _thumbnail_util_extract_video(thumbnail_data_s *thumb)
+static int __thumbnail_util_extract_video(thumbnail_data_s *thumb)
 {
        int ret = THUMBNAIL_UTIL_ERROR_NONE;
        MMHandleType content = NULL;
@@ -287,10 +291,10 @@ int _thumbnail_util_extract_video(thumbnail_data_s *thumb)
        int video_track_num = 0;
        char *err_msg = NULL;
        int size = 0;
-       int width = 0;
-       int height = 0;
-       int thumb_width = 0;
-       int thumb_height = 0;
+       unsigned int width = 0;
+       unsigned int height = 0;
+       unsigned int thumb_width = 0;
+       unsigned int thumb_height = 0;
        int cdis_value = 0;
        mm_util_image_h img = NULL;
 
@@ -407,13 +411,13 @@ ERROR:
        return THUMBNAIL_UTIL_ERROR_OUT_OF_MEMORY;
 }
 
-int _thumbnail_util_extract(thumbnail_data_s *thumb)
+static int __thumbnail_util_extract(thumbnail_data_s *thumb)
 {
-       int ret = 0;
+       int ret = THUMBNAIL_UTIL_ERROR_NONE;
        unsigned int orig_width = 0;
        unsigned int orig_height = 0;
-       int thumb_width = 0;
-       int thumb_height = 0;
+       unsigned int thumb_width = 0;
+       unsigned int thumb_height = 0;
        mm_util_img_codec_type type = IMG_CODEC_UNKNOWN_TYPE;
 
        thumbnail_util_retvm_if(thumb == NULL, THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Data is NULL");
@@ -425,8 +429,7 @@ int _thumbnail_util_extract(thumbnail_data_s *thumb)
                ret = mm_util_extract_image_info(thumb->path, &type, &orig_width, &orig_height);
                thumbnail_util_retv_if(ret != MM_UTIL_ERROR_NONE, THUMBNAIL_UTIL_ERROR_INVALID_OPERATION);
 
-               ret = __thumbnail_util_get_proper_thumb_size((int)orig_width, (int)orig_height, &thumb_width, &thumb_height);
-               thumbnail_util_retv_if(ret != MM_UTIL_ERROR_NONE, THUMBNAIL_UTIL_ERROR_INVALID_OPERATION);
+               __thumbnail_util_get_proper_thumb_size(orig_width, orig_height, &thumb_width, &thumb_height);
 
                if (thumb->extract_type == THUMBNAIL_UTIL_FILE) {
                        ret = mm_util_resize_P_P(thumb->path, thumb_width, thumb_height, thumb->thumbnail_path);
@@ -461,8 +464,8 @@ int _thumbnail_util_extract(thumbnail_data_s *thumb)
                        SAFE_FREE(buf);
                }
        } else {
-               ret = _thumbnail_util_extract_video(thumb);
-               thumbnail_util_retvm_if(ret != THUMBNAIL_UTIL_ERROR_NONE, ret, "_thumbnail_util_extract_video failed");
+               ret = __thumbnail_util_extract_video(thumb);
+               thumbnail_util_retvm_if(ret != THUMBNAIL_UTIL_ERROR_NONE, ret, "__thumbnail_util_extract_video failed");
        }
 
        return THUMBNAIL_UTIL_ERROR_NONE;
@@ -486,9 +489,9 @@ int __thumbnail_util_get_file_ext(const char *file_path, char *file_ext, int max
        return THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER;
 }
 
-int _thumbnail_util_check_media_type(const char *path, thumbnail_util_media_type_e *type)
+static int __thumbnail_util_check_media_type(const char *path, thumbnail_util_media_type_e *type)
 {
-       int ret = 0;
+       int ret = THUMBNAIL_UTIL_ERROR_NONE;
        char mimetype[255] = {0,};
        const char *unsupported_type = "image/tiff";
        const char *supported_type = "application/vnd.ms-asf";
@@ -527,15 +530,15 @@ int _thumbnail_util_check_media_type(const char *path, thumbnail_util_media_type
        return THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER;
 }
 
-bool _thumbnail_util_is_support_img(const char *path)
+static bool __thumbnail_util_is_support_img(const char *path)
 {
-       int ret = 0;
+       int ret = THUMBNAIL_UTIL_ERROR_NONE;
        mm_util_img_codec_type t = IMG_CODEC_UNKNOWN_TYPE;
        unsigned int w = 0;
        unsigned int h = 0;
 
        ret = mm_util_extract_image_info(path, &t, &w, &h);
-       if (ret != 0 || t == IMG_CODEC_UNKNOWN_TYPE)
+       if (ret != MM_UTIL_ERROR_NONE || t == IMG_CODEC_UNKNOWN_TYPE)
                return false;
        else
                return true;
@@ -552,12 +555,12 @@ int thumbnail_util_extract_to_buffer(const char *path, unsigned int width, unsig
        thumbnail_util_retvm_if(thumb_buffer == NULL || thumb_size == NULL || thumb_width == NULL || thumb_height == NULL, THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Out param is NULL");
 
        /* check media type */
-       ret = _thumbnail_util_check_media_type(path, &type);
-       thumbnail_util_retvm_if(ret != THUMBNAIL_UTIL_ERROR_NONE, ret, "_thumbnail_util_check_media_type failed");
+       ret = __thumbnail_util_check_media_type(path, &type);
+       thumbnail_util_retvm_if(ret != THUMBNAIL_UTIL_ERROR_NONE, ret, "__thumbnail_util_check_media_type failed");
 
        /* If image, check support format */
        if (type == THUMBNAIL_UTIL_IMAGE) {
-               if (_thumbnail_util_is_support_img(path) == false) {
+               if (__thumbnail_util_is_support_img(path) == false) {
                        thumbnail_util_error("This image format is not supported");
                        return THUMBNAIL_UTIL_ERROR_UNSUPPORTED_CONTENT;
                }
@@ -571,24 +574,23 @@ int thumbnail_util_extract_to_buffer(const char *path, unsigned int width, unsig
        thumb->height = height;
 
        if (thumb->path == NULL) {
-               _thumbnail_util_destroy_thumb_data(thumb);
+               __thumbnail_util_destroy_thumb_data(thumb);
                return THUMBNAIL_UTIL_ERROR_OUT_OF_MEMORY;
        }
 
-       ret = _thumbnail_util_extract(thumb);
+       ret = __thumbnail_util_extract(thumb);
        if (ret != THUMBNAIL_UTIL_ERROR_NONE) {
                thumbnail_util_error("Extract failed");
-               _thumbnail_util_destroy_thumb_data(thumb);
        } else {
                *thumb_buffer = malloc(thumb->buffer_size);
                memcpy(*thumb_buffer, thumb->buffer, thumb->buffer_size);
                *thumb_size = thumb->buffer_size;
                *thumb_width = thumb->width;
                *thumb_height = thumb->height;
-
-               _thumbnail_util_destroy_thumb_data(thumb);
        }
 
+       __thumbnail_util_destroy_thumb_data(thumb);
+
        return ret;
 }
 
@@ -604,12 +606,12 @@ int thumbnail_util_extract_to_file(const char *path, unsigned int width, unsigne
        thumbnail_util_retvm_if(!STRING_VALID(thumbnail_path), THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER, "Wrong thumbnail_path");
 
        /* check media type */
-       ret = _thumbnail_util_check_media_type(path, &type);
-       thumbnail_util_retvm_if(ret != THUMBNAIL_UTIL_ERROR_NONE, ret, "_thumbnail_util_check_media_type failed");
+       ret = __thumbnail_util_check_media_type(path, &type);
+       thumbnail_util_retvm_if(ret != THUMBNAIL_UTIL_ERROR_NONE, ret, "__thumbnail_util_check_media_type failed");
 
        /* If image, check support format */
        if (type == THUMBNAIL_UTIL_IMAGE) {
-               if (_thumbnail_util_is_support_img(path) == false) {
+               if (__thumbnail_util_is_support_img(path) == false) {
                        thumbnail_util_error("This image format is not supported");
                        return THUMBNAIL_UTIL_ERROR_UNSUPPORTED_CONTENT;
                }
@@ -647,15 +649,15 @@ int thumbnail_util_extract_to_file(const char *path, unsigned int width, unsigne
        thumb->thumbnail_path = g_strdup(thumbnail_path);
 
        if (thumb->path == NULL || thumb->thumbnail_path == NULL) {
-               _thumbnail_util_destroy_thumb_data(thumb);
+               __thumbnail_util_destroy_thumb_data(thumb);
                return THUMBNAIL_UTIL_ERROR_OUT_OF_MEMORY;
        }
 
-       ret = _thumbnail_util_extract(thumb);
+       ret = __thumbnail_util_extract(thumb);
        if (ret != THUMBNAIL_UTIL_ERROR_NONE)
                thumbnail_util_error("Extract failed");
 
-       _thumbnail_util_destroy_thumb_data(thumb);
+       __thumbnail_util_destroy_thumb_data(thumb);
 
        return ret;
 }