From: Sangchul Lee Date: Fri, 5 Mar 2021 02:36:45 +0000 (+0900) Subject: media_format: Add missing null checking for parameters X-Git-Tag: submit/tizen/20210315.032240~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F88%2F254588%2F3;p=platform%2Fcore%2Fapi%2Fmediatool.git media_format: Add missing null checking for parameters Some macro are also revised. [Version] 0.1.36 [Issue Type] Improvement Change-Id: Ic6ee9c41f642af7f00736a03aa92d0960e88eb5f Signed-off-by: Sangchul Lee --- diff --git a/include/media_format_private.h b/include/media_format_private.h index e6cb0bc..029c08b 100644 --- a/include/media_format_private.h +++ b/include/media_format_private.h @@ -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)) diff --git a/packaging/capi-media-tool.spec b/packaging/capi-media-tool.spec index d6620a2..1fc650f 100755 --- a/packaging/capi-media-tool.spec +++ b/packaging/capi-media-tool.spec @@ -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 diff --git a/src/media_format.c b/src/media_format.c index 346a802..0c24e59 100644 --- a/src/media_format.c +++ b/src/media_format.c @@ -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; }