From patchwork Fri Jun 7 21:45:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Eoff, Ullysses A" X-Patchwork-Id: 13454 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 874D54472A3 for ; Sat, 8 Jun 2019 00:45:45 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 72C5B68A9D8; Sat, 8 Jun 2019 00:45:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AAD9768A9D8 for ; Sat, 8 Jun 2019 00:45:38 +0300 (EEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Jun 2019 14:45:36 -0700 X-ExtLoop1: 1 Received: from uaeoff-desk.amr.corp.intel.com ([10.251.8.58]) by orsmga004.jf.intel.com with ESMTP; 07 Jun 2019 14:45:36 -0700 From: "U. Artie Eoff" To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Jun 2019 14:45:33 -0700 Message-Id: <20190607214533.20540-1-ullysses.a.eoff@intel.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4] vaapi_encode_mjpeg: fix bad component id bug X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: "U. Artie Eoff" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The compound literals assigned to "components" only exist within the scope of the if/else block (thanks Mark Thompson for the better explanation). Thus, after this if/else block, "components" ends up pointing to an arbitrary/undefined array. With some compilers and depending on optimization settings, these arbitrary values may end up being the same value (i.e. 0 with GNU GCC 9.x). Unfortunately, the GNU GCC compiler, at least, never prints any warnings about this. This patch fixes this issue by assigning the constant arrays to local variables at function scope and then pointing "components" to those as necessary. Fixes #7915 Signed-off-by: U. Artie Eoff --- libavcodec/vaapi_encode_mjpeg.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavcodec/vaapi_encode_mjpeg.c b/libavcodec/vaapi_encode_mjpeg.c index 4dcdc3d16bb0..bd029cc90315 100644 --- a/libavcodec/vaapi_encode_mjpeg.c +++ b/libavcodec/vaapi_encode_mjpeg.c @@ -227,6 +227,8 @@ static int vaapi_encode_mjpeg_init_picture_params(AVCodecContext *avctx, JPEGRawScanHeader *sh = &priv->scan.header; VAEncPictureParameterBufferJPEG *vpic = pic->codec_picture_params; const AVPixFmtDescriptor *desc; + const uint8_t components_rgb[3] = { 'R', 'G', 'B' }; + const uint8_t components_yuv[3] = { 1, 2, 3 }; const uint8_t *components; int t, i, quant_scale, len; @@ -235,9 +237,9 @@ static int vaapi_encode_mjpeg_init_picture_params(AVCodecContext *avctx, desc = av_pix_fmt_desc_get(priv->common.input_frames->sw_format); av_assert0(desc); if (desc->flags & AV_PIX_FMT_FLAG_RGB) - components = (uint8_t[3]) { 'R', 'G', 'B' }; + components = components_rgb; else - components = (uint8_t[3]) { 1, 2, 3 }; + components = components_yuv; // Frame header.