Fix svace issues 30/316830/2 accepted/tizen/unified/20240830.163355 accepted/tizen/unified/x/20240901.123209
authorJeongmo Yang <jm80.yang@samsung.com>
Wed, 28 Aug 2024 11:33:01 +0000 (20:33 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Thu, 29 Aug 2024 05:02:12 +0000 (14:02 +0900)
- Issue list
 : SEC_DO_NOT_USE_POINTER_WITH_INT_IN_UNION
 : SEC_INVALID_ASSIGNMENT_WITH_UNSIGNED_VALUES
 : SEC_DO_NOT_ASSIGN_SIZE_OF_INT
 : SEC_MALLOC_ALIGNMENT
 : SIGNED_TO_BIGGER_UNSIGNED

[Version] 1.2.5
[Issue Type] Svace

Change-Id: I0e40bde1fd2fbb3173f6eb6b54882352313cc9cf
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
12 files changed:
packaging/libmm-camcorder.spec
src/include/mm_camcorder_attribute.h
src/include/mm_camcorder_configure.h
src/mm_camcorder_audiorec.c
src/mm_camcorder_configure.c
src/mm_camcorder_exifinfo.c
src/mm_camcorder_gstcommon.c
src/mm_camcorder_internal.c
src/mm_camcorder_platform.c
src/mm_camcorder_stillshot.c
src/mm_camcorder_util.c
src/mm_camcorder_videorec.c

index 8dc22e9..8895732 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       libmm-camcorder
 Summary:    Camera and recorder library
-Version:    1.2.4
+Version:    1.2.5
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index 7015e4d..9a1a0d2 100644 (file)
@@ -223,13 +223,13 @@ typedef struct {
        union {
                void *value_void;
                char *value_string;
-               int value_int;
+               intptr_t value_int;
                double value_double;
        } default_value;              /* default value */
        MMCamAttrsValidType validity_type;
        union {
                int *int_array;
-               int int_min;
+               intptr_t int_min;
                double *double_array;
                double double_min;
        } validity_value_1;
index 8b265cc..278b2bf 100644 (file)
@@ -183,7 +183,7 @@ struct _conf_info_table {
        int value_type;
        union {
                type_element *value_element;
-               int value_int;
+               intptr_t value_int;
                char *value_string;
        };
 };
index ca5dd30..9c14bcc 100644 (file)
@@ -765,7 +765,7 @@ static GstPadProbeReturn __mmcamcorder_audio_dataprobe_voicerecorder(GstPad *pad
                stream.data = (void *)mapinfo.data;
                stream.format = format;
                stream.channel = channel;
-               stream.length = mapinfo.size;
+               stream.length = (unsigned int)mapinfo.size;
                stream.timestamp = (unsigned int)(GST_TIME_AS_MSECONDS(GST_BUFFER_PTS(buffer)));
                stream.volume_dB = curdcb;
 
index fbe1a66..b946112 100644 (file)
@@ -58,7 +58,7 @@ char *get_new_string(char* src_string)
 int _mmcamcorder_conf_init(MMHandleType handle, int type, camera_conf *configure_info)
 {
        int category_num = 0;
-       int info_table_size = sizeof(conf_info_table);
+       size_t info_table_size = sizeof(conf_info_table);
 
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
 
index be2e209..3aaf067 100644 (file)
@@ -186,7 +186,7 @@ mm_exif_set_exif_to_info(mm_exif_info_t *info, ExifData *exif)
        MMCAM_LOG_INFO("exif(ifd :%p)", exif->ifd);
 
        if (info->data) {
-               free(info->data);
+               g_free(info->data);
                info->data = NULL;
                info->size = 0;
        }
@@ -232,7 +232,7 @@ mm_exif_set_add_entry(ExifData *exif, ExifIfd ifd, ExifTag tag, ExifFormat forma
 
        if (e->size == 0) {
                e->data = NULL;
-               e->data = malloc(exif_format_get_size(format) * e->components);
+               e->data = g_malloc(exif_format_get_size(format) * e->components);
                if (!e->data) {
                        exif_entry_unref(e);
                        return MM_ERROR_CAMCORDER_LOW_MEMORY;
@@ -242,7 +242,7 @@ mm_exif_set_add_entry(ExifData *exif, ExifIfd ifd, ExifTag tag, ExifFormat forma
                        memset(e->data, '\0', exif_format_get_size(format) * e->components);
        }
 
-       e->size = exif_format_get_size(format) * e->components;
+       e->size = (unsigned int)(exif_format_get_size(format) * e->components);
        memcpy(e->data, data, e->size);
        exif_content_add_entry(ed->ifd[ifd], e);
        exif_entry_unref(e);
@@ -274,17 +274,17 @@ mm_exif_create_exif_info(mm_exif_info_t **info)
                return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
        }
 
-       x = malloc(sizeof(mm_exif_info_t));
+       x = g_new(mm_exif_info_t, 1);
        if (!x) {
-               MMCAM_LOG_ERROR("malloc error");
+               MMCAM_LOG_ERROR("g_new error");
                return MM_ERROR_CAMCORDER_LOW_MEMORY;
        }
 #if MM_EXIFINFO_USE_BINARY_EXIFDATA
        x->data = NULL;
-       x->data = malloc(_EXIF_BIN_SIZE_);
+       x->data = g_malloc(_EXIF_BIN_SIZE_);
        if (!x->data) {
-               MMCAM_LOG_ERROR("malloc error");
-               free(x);
+               MMCAM_LOG_ERROR("g_malloc error");
+               g_free(x);
                return MM_ERROR_CAMCORDER_LOW_MEMORY;
        }
        memcpy(x->data, g_exif_bin, _EXIF_BIN_SIZE_);
@@ -293,7 +293,7 @@ mm_exif_create_exif_info(mm_exif_info_t **info)
        ed = exif_data_new();
        if (!ed) {
                MMCAM_LOG_ERROR("exif data new error");
-               free(x);
+               g_free(x);
                return MM_ERROR_CAMCORDER_LOW_MEMORY;
        }
 
@@ -306,7 +306,7 @@ mm_exif_create_exif_info(mm_exif_info_t **info)
        exif_data_save_data(ed, &eb, &ebs);
        if (eb == NULL) {
                MMCAM_LOG_ERROR("exif_data_save_data error");
-               free(x);
+               g_free(x);
                exif_data_unref(ed);
                return MM_ERROR_CAMCORDER_INTERNAL;
        }
@@ -328,8 +328,8 @@ mm_exif_destory_exif_info(mm_exif_info_t *info)
        /* MMCAM_LOG_INFO( ""); */
        if (info) {
                if (info->data)
-                       free(info->data);
-               free(info);
+                       g_free(info->data);
+               g_free(info);
        }
 }
 
@@ -340,7 +340,7 @@ mm_exif_add_thumbnail_info(mm_exif_info_t *info, void *thumbnail, int width, int
        ExifData *ed = NULL;
        static ExifLong elong[10];
 
-       unsigned char *p_compressed = NULL;
+       ExifShort *p_compressed = NULL;
        int ret = MM_ERROR_NONE;
        int cntl = 0;
 
@@ -362,9 +362,9 @@ mm_exif_add_thumbnail_info(mm_exif_info_t *info, void *thumbnail, int width, int
        ed->size = len;
 
        /* set thumbnail data */
-       p_compressed = (unsigned char *)malloc(sizeof(ExifShort));
+       p_compressed = g_new(ExifShort, 1);
        if (p_compressed != NULL) {
-               exif_set_short(p_compressed, exif_data_get_byte_order(ed), 6);
+               exif_set_short((unsigned char *)p_compressed, exif_data_get_byte_order(ed), 6);
                ret = mm_exif_set_add_entry(ed, EXIF_IFD_1, EXIF_TAG_COMPRESSION, EXIF_FORMAT_SHORT, 1, (const char *)p_compressed);
                if (ret != MM_ERROR_NONE)
                        goto exit;
@@ -393,8 +393,7 @@ mm_exif_add_thumbnail_info(mm_exif_info_t *info, void *thumbnail, int width, int
        exif_data_unref(ed);
 
 exit:
-       if (p_compressed != NULL)
-               free(p_compressed);
+       g_free(p_compressed);
 
        return ret;
 }
@@ -434,10 +433,10 @@ mm_exif_write_exif_jpeg_to_memory(void **mem, unsigned int *length, mm_exif_info
                if (test_exif_info) {
                        jpeg_offset = test_exif_info->size + JPEG_EXIF_OFFSET;
                        if (test_exif_info->data) {
-                               free(test_exif_info->data);
+                               g_free(test_exif_info->data);
                                test_exif_info->data = NULL;
                        }
-                       free(test_exif_info);
+                       g_free(test_exif_info);
                        test_exif_info = NULL;
                } else {
                        MMCAM_LOG_ERROR("test_exif_info is NULL");
@@ -450,9 +449,9 @@ mm_exif_write_exif_jpeg_to_memory(void **mem, unsigned int *length, mm_exif_info
        /*SOI + APP1 + length of APP1 + length of EXIF + IMAGE*/
        m_len = EXIF_MARKER_SOI_LENGTH + EXIF_MARKER_APP1_LENGTH + EXIF_APP1_LENGTH + ebs + (jpeg_len - jpeg_offset);
        /*alloc output image*/
-       m = malloc(m_len);
+       m = g_malloc(m_len);
        if (!m) {
-               MMCAM_LOG_ERROR("malloc() failed.");
+               MMCAM_LOG_ERROR("g_malloc() failed.");
                return MM_ERROR_CAMCORDER_LOW_MEMORY;
        }
 
@@ -463,7 +462,7 @@ mm_exif_write_exif_jpeg_to_memory(void **mem, unsigned int *length, mm_exif_info
        _exif_set_uint16(0, &head_len, (unsigned short)(ebs + 2));
        if (head[0] == 0 || head[1] == 0 || head_len == 0) {
                MMCAM_LOG_ERROR("setting error");
-               free(m);
+               g_free(m);
                return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
        }
 
@@ -509,23 +508,23 @@ int mm_exif_load_exif_info(mm_exif_info_t **info, void *jpeg_data, int jpeg_leng
                exif_loader_write(loader, jpeg_data, jpeg_length);
                exif_loader_get_buf(loader, &b, &s);
                if (s > 0) {
-                       x = malloc(sizeof(mm_exif_info_t));
+                       x = g_new(mm_exif_info_t, 1);
                        if (x) {
-                               x->data = malloc(s);
+                               x->data = g_malloc(s);
                                if (x->data) {
                                        memcpy((char*)x->data, b, s);
                                        x->size = s;
                                        *info = x;
                                        MMCAM_LOG_WARNING("load EXIF : data %p, size %d", x->data, x->size);
                                } else {
-                                       MMCAM_LOG_ERROR("mm_exif_info_t malloc failed");
-                                       free(x);
+                                       MMCAM_LOG_ERROR("mm_exif_info_t g_malloc failed");
+                                       g_free(x);
                                        exif_loader_unref(loader);
 
                                        return MM_ERROR_CAMCORDER_LOW_MEMORY;
                                }
                        } else {
-                               MMCAM_LOG_ERROR("mm_exif_info_t malloc failed");
+                               MMCAM_LOG_ERROR("mm_exif_info_t g_new failed");
                        }
                } else {
                        MMCAM_LOG_ERROR("exif_loader_get_buf failed");
index 0c396b9..ba7ce50 100644 (file)
@@ -174,7 +174,7 @@ static gboolean __mmcamcorder_set_stream_data(MMCamcorderVideoStreamDataType *st
        mmf_return_val_if_fail(stream, FALSE);
        mmf_return_val_if_fail(map_info, FALSE);
 
-       stream->length_total = map_info->size;
+       stream->length_total = (unsigned int)map_info->size;
 
        switch (stream->format) {
        case MM_PIXEL_FORMAT_NV12: /* fall through */
@@ -299,7 +299,7 @@ static gboolean __mmcamcorder_set_stream_data_zero_copy(MMCamcorderVideoStreamDa
                stream->stride[0] = stream->width;
                stream->elevation[0] = stream->height;
                stream->data.encoded.data = bo_handle.ptr;
-               stream->length_total = gst_memory_get_sizes(memory, NULL, NULL);
+               stream->length_total = (unsigned int)gst_memory_get_sizes(memory, NULL, NULL);
                stream->data.encoded.length_data = stream->length_total;
                stream->data.encoded.is_delta_frame = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_DELTA_UNIT);
                stream->data.encoded.is_header_included = GST_BUFFER_FLAG_IS_SET(buffer, GST_BUFFER_FLAG_HEADER);
@@ -1946,7 +1946,6 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi
        int do_scaling = FALSE;
        int *dp_handle = NULL;
        MMCamWindowInfo *window_info = NULL;
-       gulong xid;
        char *err_name = NULL;
        const char *videosink_name = NULL;
 
@@ -2002,26 +2001,7 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi
        MMCAM_LOG_INFO("(dp_handle=%p, size=%d)", dp_handle, size);
 
        /* Set display handle */
-       if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "ximagesink")) {
-               if (dp_handle) {
-                       xid = *dp_handle;
-                       MMCAM_LOG_INFO("xid = %lu )", xid);
-                       gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), xid);
-               } else {
-                       MMCAM_LOG_WARNING("Handle is NULL. Set xid as 0.. but, it's not recommended.");
-                       gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(vsink), 0);
-               }
-       } else if (!strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink")) {
-               MMCAM_LOG_INFO("videosink : %s, handle : %p", videosink_name, dp_handle);
-
-               if (dp_handle) {
-                       MMCAMCORDER_G_OBJECT_SET_POINTER(vsink, "evas-object", dp_handle);
-                       MMCAMCORDER_G_OBJECT_SET(vsink, "origin-size", !do_scaling);
-               } else {
-                       MMCAM_LOG_ERROR("display handle(eavs object) is NULL");
-                       return MM_ERROR_CAMCORDER_INVALID_ARGUMENT;
-               }
-       } else if (!strcmp(videosink_name, "tizenwlsink")) {
+       if (!strcmp(videosink_name, "tizenwlsink")) {
                if (dp_handle) {
                        window_info = (MMCamWindowInfo *)dp_handle;
                        MMCAM_LOG_INFO("wayland global surface id : %d", window_info->surface_id);
@@ -2060,8 +2040,7 @@ int _mmcamcorder_videosink_window_set(MMHandleType handle, type_element* Videosi
                videosink_name, display_geometry_method, origin_size, visible, rotation, flip);
 
        /* Set attribute */
-       if (!strcmp(videosink_name, "xvimagesink") || !strcmp(videosink_name, "tizenwlsink") ||
-           !strcmp(videosink_name, "evaspixmapsink") || !strcmp(videosink_name, "directvideosink")) {
+       if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "directvideosink")) {
                /* set rotation */
                MMCAMCORDER_G_OBJECT_SET(vsink, "rotate", rotation);
 
@@ -2377,7 +2356,7 @@ GstPadProbeReturn __mmcamcorder_muxed_dataprobe(GstPad *pad, GstPadProbeInfo *in
 
        if (hcamcorder->mstream_cb) {
                stream.data = (void *)mapinfo.data;
-               stream.length = mapinfo.size;
+               stream.length = (unsigned int)mapinfo.size;
                stream.offset = sc->muxed_stream_offset;
                hcamcorder->mstream_cb(&stream, hcamcorder->mstream_cb_param);
        }
@@ -2719,9 +2698,7 @@ bool _mmcamcorder_set_display_rotation(MMHandleType handle, int display_rotate,
                        return FALSE;
                }
 
-               if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "xvimagesink") ||
-                       !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
-                       !strcmp(videosink_name, "directvideosink")) {
+               if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "directvideosink")) {
                        MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "rotate", display_rotate);
                        MMCAM_LOG_INFO("Set display-rotate [%d] done.", display_rotate);
                } else {
@@ -2758,9 +2735,7 @@ bool _mmcamcorder_set_display_flip(MMHandleType handle, int display_flip, int vi
                        return FALSE;
                }
 
-               if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "xvimagesink") ||
-                       !strcmp(videosink_name, "evasimagesink") || !strcmp(videosink_name, "evaspixmapsink") ||
-                       !strcmp(videosink_name, "directvideosink")) {
+               if (!strcmp(videosink_name, "tizenwlsink") || !strcmp(videosink_name, "directvideosink")) {
                        MMCAMCORDER_G_OBJECT_SET(sc->element[videosink_index].gst, "flip", display_flip);
                        MMCAM_LOG_INFO("Set display flip [%d] done.", display_flip);
                } else {
index a887e23..fd4e76b 100644 (file)
@@ -2212,8 +2212,8 @@ static gboolean __mmcamcorder_init_gstreamer(camera_conf *conf)
        MMCAM_LOG_INFO("");
 
        /* alloc */
-       argc = malloc(sizeof(int));
-       argv = malloc(sizeof(gchar *) * max_argc);
+       argc = g_new(int, 1);
+       argv = g_new(gchar *, max_argc);
 
        if (!argc || !argv)
                goto ERROR;
@@ -2256,30 +2256,16 @@ static gboolean __mmcamcorder_init_gstreamer(camera_conf *conf)
                }
        }
 
-       if (argv) {
-               free(argv);
-               argv = NULL;
-       }
-
-       if (argc) {
-               free(argc);
-               argc = NULL;
-       }
+       g_free(argv);
+       g_free(argc);
 
        return ret;
 
 ERROR:
        MMCAM_LOG_ERROR("failed to initialize gstreamer");
 
-       if (argv) {
-               free(argv);
-               argv = NULL;
-       }
-
-       if (argc) {
-               free(argc);
-               argc = NULL;
-       }
+       g_free(argv);
+       g_free(argc);
 
        return FALSE;
 }
index 5d55c1a..c4d5058 100644 (file)
@@ -1115,10 +1115,10 @@ int _mmcamcorder_set_converted_value(MMHandleType handle, _MMCamcorderEnumConver
 int _mmcamcorder_init_convert_table(MMHandleType handle)
 {
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(handle);
-       int enum_conv_size = sizeof(_MMCamcorderEnumConvert);
-       int caminfo_conv_size = sizeof(g_caminfo_convert);
-       int caminfo_conv_length = sizeof(g_caminfo_convert) / sizeof(_MMCamcorderInfoConverting);
-       int i = 0;
+       size_t enum_conv_size = sizeof(_MMCamcorderEnumConvert);
+       size_t caminfo_conv_size = sizeof(g_caminfo_convert);
+       size_t caminfo_conv_length = sizeof(g_caminfo_convert) / sizeof(_MMCamcorderInfoConverting);
+       size_t i = 0;
 
        mmf_return_val_if_fail(hcamcorder, MM_ERROR_CAMCORDER_NOT_INITIALIZED);
 
index a9b41ea..654072d 100644 (file)
@@ -1480,7 +1480,7 @@ static void __mmcamcorder_get_capture_data_from_buffer(MMCamcorderCaptureDataTyp
                "width", G_TYPE_INT, &capture_data->width,
                "height", G_TYPE_INT, &capture_data->height,
                NULL);
-       capture_data->length = mapinfo.size;
+       capture_data->length = (unsigned int)mapinfo.size;
        gst_buffer_unmap(gst_sample_get_buffer(sample), &mapinfo);
 
        MMCAM_LOG_WARNING("buffer data[%p],size[%dx%d],length[%d],format[%d]",
index 3614ffe..423b330 100644 (file)
@@ -2699,8 +2699,9 @@ void _mmcamcorder_measure_fps(void *data)
 
        kpi->current_fps = (frame_count - kpi->last_framecount) / diff_sec;
 
-       if ((current_video_time.tv_sec - kpi->init_video_time.tv_sec) != 0)
-               kpi->average_fps = kpi->video_framecount / (current_video_time.tv_sec - kpi->init_video_time.tv_sec);
+       diff_sec = current_video_time.tv_sec - kpi->init_video_time.tv_sec;
+       if (diff_sec != 0)
+               kpi->average_fps = (int)kpi->video_framecount / diff_sec;
 
        kpi->last_framecount = frame_count;
        kpi->last_video_time.tv_sec = current_video_time.tv_sec;
index 32cb955..d582711 100644 (file)
@@ -1545,7 +1545,7 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_audio_disable(GstPad *pad
 {
        guint64 trailer_size = 0;
        guint64 rec_pipe_time = 0;
-       unsigned int remained_time = 0;
+       unsigned long long remained_time = 0;
 
        GstClockTime b_time;
 
@@ -1604,7 +1604,7 @@ static GstPadProbeReturn __mmcamcorder_video_dataprobe_audio_disable(GstPad *pad
                long double max_size = (long double)videoinfo->max_size;
                long double current_size = (long double)(videoinfo->filesize + trailer_size);
 
-               remained_time = (unsigned int)((long double)rec_pipe_time * (max_size/current_size)) - rec_pipe_time;
+               remained_time = (unsigned long long)((long double)rec_pipe_time * (max_size/current_size)) - rec_pipe_time;
        }
 
        msg.id = MM_MESSAGE_CAMCORDER_RECORDING_STATUS;
@@ -1646,7 +1646,7 @@ static GstPadProbeReturn __mmcamcorder_audioque_dataprobe(GstPad *pad, GstPadPro
        _MMCamcorderSubContext *sc = NULL;
        mmf_camcorder_t *hcamcorder = MMF_CAMCORDER(u_data);
        _MMCamcorderVideoInfo *videoinfo = NULL;
-       unsigned int remained_time = 0;
+       unsigned long long remained_time = 0;
        GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER(info);
 
        mmf_return_val_if_fail(buffer, GST_PAD_PROBE_DROP);
@@ -1768,7 +1768,7 @@ static GstPadProbeReturn __mmcamcorder_audio_dataprobe_audio_mute(GstPad *pad, G
                stream.data = (void *)mapinfo.data;
                stream.format = format;
                stream.channel = channel;
-               stream.length = mapinfo.size;
+               stream.length = (unsigned int)mapinfo.size;
                stream.timestamp = (unsigned int)(GST_TIME_AS_MSECONDS(GST_BUFFER_PTS(buffer)));
 
                _MMCAMCORDER_LOCK_ASTREAM_CALLBACK(hcamcorder);