From patchwork Tue Dec 3 17:09:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 16568 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 7D1E744ACC9 for ; Tue, 3 Dec 2019 19:09:45 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 65C1168B4CC; Tue, 3 Dec 2019 19:09:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8202468B4AF for ; Tue, 3 Dec 2019 19:09:37 +0200 (EET) Received: by mail-wr1-f68.google.com with SMTP id z7so4557994wrl.13 for ; Tue, 03 Dec 2019 09:09:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tDNzbRRrive/1x2xhjhXuV2t7SHLG4Ix3kB0a8JR+oo=; b=k+RFInblAMWYuGugNnvGItp8mMo/vp2U9HyUlGNEeNJ1DFghLXaeg6fa9sGo1DYTy0 OGlGBXmiMzxXaSQpCNVAtKOwGxrfXV/WjUlBhS/jjNXh2f5DZ7yH+enMIMCzPw6HS6kZ VOP4p3yKvhWZpOssOrAnqTV5NAOul5rAxSSknkl+yGS1+hVXqERjccSgh9gm3gs+Fn9R /geI/dugyUpsv/Aaz/YzCNZbxECB01UbPZQGsHx8EdK+ouzMo81I06qtt/0iAICwZQOR 8imKkX0COwxngOWkMx2p6kFlRmKnNy4lcVsGS5wZEMMediOrYq5XopXgGcTwgKxS7G9q epqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tDNzbRRrive/1x2xhjhXuV2t7SHLG4Ix3kB0a8JR+oo=; b=RUsznFGff+rlML/CmgINpj09VKGlSeOW3gFP50U6a6T5zQuw66FBvtoe4+mQNxTFT4 cAYuaHohkm0DxlF8uFnIj2u6Swjwln9+aXCOWz5KOATT9DW0Sf9Snw16XM77tPa8fi/N t2f3jJvcjPR82b8nGqhe9vvIZnOmiHZ1tZeIAZWl2rgNDmfBlNLwzLFj9eJXeoOW3dCm wWzCuZxP9o+980bge8WiMijZk1MnX2UdLZpr22WCBYZZWPSj28pY4ToJRpjWiIJGB4O/ oATvNGRmeil6zhb6+9cMTdU3woZj5vKdtmirghV7VBMC7oFe1h2As0DlCPw9PqhpcImx iYOA== X-Gm-Message-State: APjAAAX61nLYHoTOZWxYktUp4msmuZBu3tbPyHeH2p2SFFM6d+26bFzS uhq4kUx19Cu3KbZe4nMeUF3ipdLI X-Google-Smtp-Source: APXvYqywY7XYz/rMjeNj3HqElmTyzOuv9Fux198KHxF0Km5LjV6Uxpr4S4oEdEhhFaH3wkkNqJST9g== X-Received: by 2002:adf:f108:: with SMTP id r8mr6402309wro.390.1575392974881; Tue, 03 Dec 2019 09:09:34 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc08e23.dynamic.kabel-deutschland.de. [188.192.142.35]) by smtp.gmail.com with ESMTPSA id x21sm3513630wmj.44.2019.12.03.09.09.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2019 09:09:34 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Dec 2019 18:09:07 +0100 Message-Id: <20191203170910.5310-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191203170910.5310-1-andreas.rheinhardt@gmail.com> References: <20191203170910.5310-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/8] avformat/matroskadec: Simplify control flow of parsing laces 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Up until now, when an error happened in one of the inner loops in matroska_parse_laces, a variable designated for the return value has been set to an error value and break has been used to exit the current loop/case. This was done so that the end of matroska_parse_laces is reached, because said function allocated memory which is later used and freed in the calling function and passed at the end of matroska_parse_laces. But given that there is no allocation any more, one can now return immediately. And this commit does this. Signed-off-by: Andreas Rheinhardt --- Supersedes https://ffmpeg.org/pipermail/ffmpeg-devel/2019-August/248368.html libavformat/matroskadec.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 2f289a90b3..88c43ee0c1 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -2992,7 +2992,7 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, int *buf_size, int type, uint32_t lace_size[256], int *laces) { - int res = 0, n, size = *buf_size; + int n, size = *buf_size; uint8_t *data = *buf; if (!type) { @@ -3011,13 +3011,12 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, { uint8_t temp; uint32_t total = 0; - for (n = 0; res == 0 && n < *laces - 1; n++) { + for (n = 0; n < *laces - 1; n++) { lace_size[n] = 0; while (1) { if (size <= total) { - res = AVERROR_INVALIDDATA; - break; + return AVERROR_INVALIDDATA; } temp = *data; total += temp; @@ -3029,8 +3028,7 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, } } if (size <= total) { - res = AVERROR_INVALIDDATA; - break; + return AVERROR_INVALIDDATA; } lace_size[n] = size - total; @@ -3039,8 +3037,7 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, case 0x2: /* fixed-size lacing */ if (size % (*laces)) { - res = AVERROR_INVALIDDATA; - break; + return AVERROR_INVALIDDATA; } for (n = 0; n < *laces; n++) lace_size[n] = size / *laces; @@ -3054,21 +3051,19 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, if (n < 0 || num > INT_MAX) { av_log(matroska->ctx, AV_LOG_INFO, "EBML block data error\n"); - res = n<0 ? n : AVERROR_INVALIDDATA; - break; + return n < 0 ? n : AVERROR_INVALIDDATA; } data += n; size -= n; total = lace_size[0] = num; - for (n = 1; res == 0 && n < *laces - 1; n++) { + for (n = 1; n < *laces - 1; n++) { int64_t snum; int r; r = matroska_ebmlnum_sint(matroska, data, size, &snum); if (r < 0 || lace_size[n - 1] + snum > (uint64_t)INT_MAX) { av_log(matroska->ctx, AV_LOG_INFO, "EBML block data error\n"); - res = r<0 ? r : AVERROR_INVALIDDATA; - break; + return r < 0 ? r : AVERROR_INVALIDDATA; } data += r; size -= r; @@ -3076,8 +3071,7 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, total += lace_size[n]; } if (size <= total) { - res = AVERROR_INVALIDDATA; - break; + return AVERROR_INVALIDDATA; } lace_size[*laces - 1] = size - total; break; @@ -3087,7 +3081,7 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, *buf = data; *buf_size = size; - return res; + return 0; } static int matroska_parse_rm_audio(MatroskaDemuxContext *matroska,