From f67ec886a3c264d5bc5d39337380e22ee09aafb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Sat, 21 Sep 2019 13:39:42 +0200 Subject: [PATCH] libs: decoder: h264, h266: fix g_return_val_if_fail() missuse g_return_val_fail() documentations says: If expr evaluates to FALSE, the current function should be considered to have undefined behaviour (a programmer error). The only correct solution to such an error is to change the module that is calling the current function, so that it avoids this incorrect call. So it was missused in a couple parts of the H264 and H265 internal decoders. This patch changes that to plain conditionals. Also, it was included a couple code-style fixes. --- gst-libs/gst/vaapi/gstvaapidecoder_h264.c | 16 +++++++++++----- gst-libs/gst/vaapi/gstvaapidecoder_h265.c | 17 +++++++++-------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_h264.c b/gst-libs/gst/vaapi/gstvaapidecoder_h264.c index b724184423..b20e727272 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder_h264.c +++ b/gst-libs/gst/vaapi/gstvaapidecoder_h264.c @@ -369,10 +369,15 @@ gst_vaapi_frame_store_add (GstVaapiFrameStore * fs, field = picture->structure == GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD ? TOP_FIELD : BOTTOM_FIELD; - g_return_val_if_fail (fs->buffers[0]->field_poc[field] == G_MAXINT32, FALSE); + + if (fs->buffers[0]->field_poc[field] != G_MAXINT32) + return FALSE; fs->buffers[0]->field_poc[field] = picture->field_poc[field]; - g_return_val_if_fail (picture->field_poc[!field] == G_MAXINT32, FALSE); + + if (picture->field_poc[!field] != G_MAXINT32) + return FALSE; picture->field_poc[!field] = fs->buffers[0]->field_poc[!field]; + return TRUE; } @@ -744,7 +749,8 @@ dpb_output (GstVaapiDecoderH264 * decoder, GstVaapiFrameStore * fs) for (i = 0; i < fs->num_buffers; i++) { GstVaapiPictureH264 *const pic = fs->buffers[i]; - g_return_val_if_fail (pic != NULL, FALSE); + if (pic == NULL) + return FALSE; pic->output_needed = FALSE; if (!GST_VAAPI_PICTURE_FLAG_IS_SET (pic, GST_VAAPI_PICTURE_FLAG_GHOST)) picture = pic; @@ -3994,8 +4000,8 @@ decode_picture (GstVaapiDecoderH264 * decoder, GstVaapiDecoderUnit * unit) GstVaapiPictureH264 *picture, *first_field; GstVaapiDecoderStatus status; - g_return_val_if_fail (pps != NULL, GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN); - g_return_val_if_fail (sps != NULL, GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN); + if (!(pps && sps)) + return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN; status = ensure_context (decoder, sps); if (status != GST_VAAPI_DECODER_STATUS_SUCCESS) diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_h265.c b/gst-libs/gst/vaapi/gstvaapidecoder_h265.c index 7a5a2e6165..a04c74b8ee 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder_h265.c +++ b/gst-libs/gst/vaapi/gstvaapidecoder_h265.c @@ -676,7 +676,8 @@ dpb_output (GstVaapiDecoderH265 * decoder, GstVaapiFrameStore * fs) g_return_val_if_fail (fs != NULL, FALSE); picture = fs->buffer; - g_return_val_if_fail (picture != NULL, FALSE); + if (!picture) + return FALSE; picture->output_needed = FALSE; return gst_vaapi_picture_output (GST_VAAPI_PICTURE_CAST (picture)); @@ -1630,8 +1631,8 @@ init_picture_refs (GstVaapiDecoderH265 * decoder, { GstVaapiDecoderH265Private *const priv = &decoder->priv; guint32 NumRpsCurrTempList0 = 0, NumRpsCurrTempList1 = 0; - GstVaapiPictureH265 *RefPicListTemp0[16] = { NULL, }, *RefPicListTemp1[16] = { - NULL,}; + GstVaapiPictureH265 *RefPicListTemp0[16] = { NULL, }; + GstVaapiPictureH265 *RefPicListTemp1[16] = { NULL, }; guint i, rIdx = 0; guint num_ref_idx_l0_active_minus1 = 0; guint num_ref_idx_l1_active_minus1 = 0; @@ -2208,9 +2209,9 @@ decode_ref_pic_set (GstVaapiDecoderH265 * decoder, priv->NumPocLtCurr = priv->NumPocLtFoll = 0; } else { GstH265ShortTermRefPicSet *stRefPic = NULL; - gint32 num_lt_pics, pocLt, PocLsbLt[16] = { 0, } - , UsedByCurrPicLt[16] = { - 0,}; + gint32 num_lt_pics, pocLt; + gint32 PocLsbLt[16] = { 0, }; + gint32 UsedByCurrPicLt[16] = { 0, }; gint32 DeltaPocMsbCycleLt[16] = { 0, }; gint numtotalcurr = 0; @@ -2306,8 +2307,8 @@ decode_picture (GstVaapiDecoderH265 * decoder, GstVaapiDecoderUnit * unit) GstVaapiPictureH265 *picture; GstVaapiDecoderStatus status; - g_return_val_if_fail (pps != NULL, GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN); - g_return_val_if_fail (sps != NULL, GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN); + if (!(pps && sps)) + return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN; status = ensure_context (decoder, sps); if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)