media_format: Add missing null checking for parameters 88/254588/3
authorSangchul Lee <sc11.lee@samsung.com>
Fri, 5 Mar 2021 02:36:45 +0000 (11:36 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 10 Mar 2021 01:29:23 +0000 (10:29 +0900)
Some macro are also revised.

[Version] 0.1.36
[Issue Type] Improvement

Change-Id: Ic6ee9c41f642af7f00736a03aa92d0960e88eb5f
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
include/media_format_private.h
packaging/capi-media-tool.spec
src/media_format.c

index e6cb0bc2b780a16e54f0b5eeff66580326dbbd7a..029c08b15ad86b292970f4758176f6736a3876cd 100644 (file)
@@ -47,13 +47,13 @@ do { \
 
 
 #define MEDIA_FORMAT_INSTANCE_CHECK(media_format)   \
-       MEDIA_FORMAT_CHECK_CONDITION(media_format != NULL, MEDIA_FORMAT_ERROR_INVALID_PARAMETER, "MEDIA_FORMAT_ERROR_INVALID_PARAMETER")
+       MEDIA_FORMAT_CHECK_CONDITION(media_format, MEDIA_FORMAT_ERROR_INVALID_PARAMETER, "MEDIA_FORMAT_ERROR_INVALID_PARAMETER")
 
 #define MEDIA_FORMAT_INSTANCE_CHEC_VOID(media_format)   \
-       MEDIA_FORMAT_CHECK_CONDITION_VOID(media_format != NULL, "MEDIA_FORMAT_ERROR_INVALID_PARAMETER")
+       MEDIA_FORMAT_CHECK_CONDITION_VOID(media_format, "MEDIA_FORMAT_ERROR_INVALID_PARAMETER")
 
 #define MEDIA_FORMAT_NULL_ARG_CHECK(arg)      \
-       MEDIA_FORMAT_CHECK_CONDITION(arg != NULL, MEDIA_FORMAT_ERROR_INVALID_PARAMETER, "MEDIA_FORMAT_ERROR_INVALID_PARAMETER")
+       MEDIA_FORMAT_CHECK_CONDITION(arg, MEDIA_FORMAT_ERROR_INVALID_PARAMETER, "MEDIA_FORMAT_ERROR_INVALID_PARAMETER")
 
 #define MEDIA_FORMAT_CAST(obj) ((media_format_s*)(obj))
 
index d6620a203f15c0e74f824c8c0559681674a0550a..1fc650fe5b7dc6bb9aa9f50b6f64556c74b56540 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       capi-media-tool
 Summary:    A Core API media tool library in Tizen Native API
-Version:    0.1.35
+Version:    0.1.36
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 346a802d13c33a64ef5ea60d6e0efc613a3265aa..0c24e5901339074e188ccea06c40f4bdd2ed9ce1 100644 (file)
@@ -121,13 +121,11 @@ static void __media_format_destroy(media_format_s *fmt)
 int media_format_get_type(media_format_h fmt, media_format_type_e *formattype)
 {
        MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+       MEDIA_FORMAT_NULL_ARG_CHECK(formattype);
 
        media_format_s *fmt_handle;
        fmt_handle = (media_format_s *)fmt;
 
-       if (!formattype)
-               return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
-
        if (CHECK_IS_AUDIO(fmt_handle->mimetype))
                *formattype = MEDIA_FORMAT_AUDIO;
        else if (CHECK_IS_VIDEO(fmt_handle->mimetype))
@@ -147,6 +145,7 @@ int media_format_get_type(media_format_h fmt, media_format_type_e *formattype)
 int media_format_get_container_mime(media_format_h fmt, media_format_mimetype_e *mimetype)
 {
        MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+       MEDIA_FORMAT_NULL_ARG_CHECK(mimetype);
 
        media_format_s *fmt_handle;
        fmt_handle = (media_format_s *)fmt;
@@ -156,8 +155,7 @@ int media_format_get_container_mime(media_format_h fmt, media_format_mimetype_e
                return MEDIA_FORMAT_ERROR_INVALID_PARAMETER;
        }
 
-       if (mimetype)
-               *mimetype = fmt_handle->mimetype;
+       *mimetype = fmt_handle->mimetype;
 
        return MEDIA_FORMAT_ERROR_NONE;
 }
@@ -165,6 +163,7 @@ int media_format_get_container_mime(media_format_h fmt, media_format_mimetype_e
 int media_format_get_text_info(media_format_h fmt, media_format_mimetype_e *mimetype, media_format_text_type_e *type)
 {
        MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+       MEDIA_FORMAT_NULL_ARG_CHECK(mimetype || type);
 
        media_format_s *fmt_handle;
        fmt_handle = (media_format_s *)fmt;
@@ -185,6 +184,7 @@ int media_format_get_text_info(media_format_h fmt, media_format_mimetype_e *mime
 int media_format_get_video_info(media_format_h fmt, media_format_mimetype_e *mimetype, int *width, int *height, int *avg_bps, int *max_bps)
 {
        MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+       MEDIA_FORMAT_NULL_ARG_CHECK(mimetype || width || height || avg_bps || max_bps);
 
        media_format_s *fmt_handle;
        fmt_handle = (media_format_s *)fmt;
@@ -211,6 +211,7 @@ int media_format_get_video_info(media_format_h fmt, media_format_mimetype_e *mim
 int media_format_get_audio_info(media_format_h fmt, media_format_mimetype_e *mimetype, int *channel, int *samplerate, int *bit, int *avg_bps)
 {
        MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+       MEDIA_FORMAT_NULL_ARG_CHECK(mimetype || channel || samplerate || bit || avg_bps);
 
        media_format_s *fmt_handle;
        fmt_handle = (media_format_s *)fmt;
@@ -236,6 +237,7 @@ int media_format_get_audio_info(media_format_h fmt, media_format_mimetype_e *mim
 int media_format_get_audio_aac_type(media_format_h fmt, bool *is_adts)
 {
        MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+       MEDIA_FORMAT_NULL_ARG_CHECK(is_adts);
 
        media_format_s *fmt_handle;
        fmt_handle = (media_format_s *)fmt;
@@ -245,8 +247,7 @@ int media_format_get_audio_aac_type(media_format_h fmt, bool *is_adts)
                return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
        }
 
-       if (is_adts)
-               *is_adts = fmt_handle->detail.audio.is_adts;
+       *is_adts = fmt_handle->detail.audio.is_adts;
 
        return MEDIA_FORMAT_ERROR_NONE;
 }
@@ -254,6 +255,7 @@ int media_format_get_audio_aac_type(media_format_h fmt, bool *is_adts)
 int media_format_get_audio_aac_header_type(media_format_h fmt, media_format_aac_header_type_e *aac_header_type)
 {
        MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+       MEDIA_FORMAT_NULL_ARG_CHECK(aac_header_type);
 
        media_format_s *fmt_handle;
        fmt_handle = (media_format_s *)fmt;
@@ -263,8 +265,7 @@ int media_format_get_audio_aac_header_type(media_format_h fmt, media_format_aac_
                return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
        }
 
-       if (aac_header_type)
-               *aac_header_type = fmt_handle->detail.audio.aac_header_type;
+       *aac_header_type = fmt_handle->detail.audio.aac_header_type;
 
        return MEDIA_FORMAT_ERROR_NONE;
 }
@@ -272,6 +273,7 @@ int media_format_get_audio_aac_header_type(media_format_h fmt, media_format_aac_
 int media_format_get_video_frame_rate(media_format_h fmt, int *frame_rate)
 {
        MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+       MEDIA_FORMAT_NULL_ARG_CHECK(frame_rate);
 
        media_format_s *fmt_handle;
        fmt_handle = (media_format_s *)fmt;
@@ -281,8 +283,7 @@ int media_format_get_video_frame_rate(media_format_h fmt, int *frame_rate)
                return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
        }
 
-       if (frame_rate)
-               *frame_rate = fmt_handle->detail.video.frame_rate;
+       *frame_rate = fmt_handle->detail.video.frame_rate;
 
        return MEDIA_FORMAT_ERROR_NONE;
 }
@@ -672,6 +673,8 @@ int media_format_unref(media_format_h fmt)
 int media_format_is_writable(media_format_h fmt, bool *is_writable)
 {
        MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+       MEDIA_FORMAT_NULL_ARG_CHECK(is_writable);
+
        if (MEDIA_FORMAT_GET_REFCOUNT(fmt) <= 0) {
                LOGE("The format ref_count is less than 0..\n.");       //LCOV_EXCL_LINE
                return MEDIA_FORMAT_ERROR_INVALID_OPERATION;
@@ -693,6 +696,7 @@ int media_format_is_writable(media_format_h fmt, bool *is_writable)
 int media_format_make_writable(media_format_h fmt, media_format_h *out_fmt)
 {
        MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+       MEDIA_FORMAT_NULL_ARG_CHECK(out_fmt);
 
        media_format_s *fmt_handle;
        fmt_handle = (media_format_s *)fmt;
@@ -726,7 +730,7 @@ int media_format_make_writable(media_format_h fmt, media_format_h *out_fmt)
        return MEDIA_FORMAT_ERROR_NONE;
 }
 
-int media_format_set_extra(media_format_h fmt, void *extra)
+int media_format_set_extra(media_format_h fmt, void *extra) /* is it nullable? */
 {
        MEDIA_FORMAT_INSTANCE_CHECK(fmt);
 
@@ -741,12 +745,12 @@ int media_format_set_extra(media_format_h fmt, void *extra)
 int media_format_get_extra(media_format_h fmt, void **extra)
 {
        MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+       MEDIA_FORMAT_NULL_ARG_CHECK(extra);
 
        media_format_s *fmt_handle;
        fmt_handle = (media_format_s *)fmt;
 
-       if (extra)
-               *extra = fmt_handle->extradata;
+       *extra = fmt_handle->extradata;
 
        return MEDIA_FORMAT_ERROR_NONE;
 }
@@ -776,6 +780,7 @@ int media_format_set_audio_channel_mask(media_format_h fmt, uint64_t channel_mas
 int media_format_get_audio_channel_mask(media_format_h fmt, uint64_t *channel_mask)
 {
        MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+       MEDIA_FORMAT_NULL_ARG_CHECK(channel_mask);
 
        media_format_s *fmt_handle;
        fmt_handle = (media_format_s *)fmt;
@@ -806,6 +811,7 @@ int media_format_get_audio_channel_mask(media_format_h fmt, uint64_t *channel_ma
 int media_format_is_little_endian(media_format_h fmt, bool *is_little_endian)
 {
        MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+       MEDIA_FORMAT_NULL_ARG_CHECK(is_little_endian);
 
        media_format_s *fmt_handle;
        fmt_handle = (media_format_s *)fmt;
@@ -850,6 +856,7 @@ int media_format_is_little_endian(media_format_h fmt, bool *is_little_endian)
 int media_format_get_audio_bit_depth(media_format_h fmt, int *bit_depth)
 {
        MEDIA_FORMAT_INSTANCE_CHECK(fmt);
+       MEDIA_FORMAT_NULL_ARG_CHECK(bit_depth);
 
        media_format_s *fmt_handle;
        fmt_handle = (media_format_s *)fmt;
@@ -896,7 +903,7 @@ int media_format_get_audio_bit_depth(media_format_h fmt, int *bit_depth)
 int media_format_channel_positions_from_mask(media_format_h fmt, uint64_t channel_mask, media_format_channel_position_e **position)
 {
        MEDIA_FORMAT_INSTANCE_CHECK(fmt);
-       MEDIA_FORMAT_INSTANCE_CHECK(*position);
+       MEDIA_FORMAT_NULL_ARG_CHECK(position);
 
        media_format_s *fmt_handle;
        fmt_handle = (media_format_s *)fmt;
@@ -943,7 +950,8 @@ no_channel_mask:
 int media_format_channel_positions_to_mask(media_format_h fmt, const media_format_channel_position_e *position, uint64_t *channel_mask_out)
 {
        MEDIA_FORMAT_INSTANCE_CHECK(fmt);
-       MEDIA_FORMAT_INSTANCE_CHECK(position);
+       MEDIA_FORMAT_NULL_ARG_CHECK(position);
+       MEDIA_FORMAT_NULL_ARG_CHECK(channel_mask_out);
 
        int i, j;
        uint64_t channel_mask = 0;
@@ -956,14 +964,12 @@ int media_format_channel_positions_to_mask(media_format_h fmt, const media_forma
        }
 
        if (fmt_handle->detail.audio.channel == 1 && position[0] == MEDIA_FORMAT_CHANNEL_POSITION_MONO) {
-               if (channel_mask_out)
-                       *channel_mask_out = 0;
+               *channel_mask_out = 0;
                return MEDIA_FORMAT_ERROR_NONE;
        }
 
        if (fmt_handle->detail.audio.channel > 0 && position[0] == MEDIA_FORMAT_CHANNEL_POSITION_NONE) {
-               if (channel_mask_out)
-                       *channel_mask_out = 0;
+               *channel_mask_out = 0;
                return MEDIA_FORMAT_ERROR_NONE;
        }
 
@@ -995,8 +1001,7 @@ int media_format_channel_positions_to_mask(media_format_h fmt, const media_forma
                channel_mask |= (G_GUINT64_CONSTANT(1) << position[i]);
        }
 
-       if (channel_mask_out)
-               *channel_mask_out = channel_mask;
+       *channel_mask_out = channel_mask;
 
        return MEDIA_FORMAT_ERROR_NONE;
 }