From patchwork Fri Aug 16 03:05:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 14539 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 7AE21448852 for ; Fri, 16 Aug 2019 06:13:31 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 572C468AD08; Fri, 16 Aug 2019 06:13:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2AE8E680114 for ; Fri, 16 Aug 2019 06:13:25 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id p77so2240533wme.0 for ; Thu, 15 Aug 2019 20:13:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=WTTaB7vbAH9EInR8zIsv3HYxyADXG9+vxH9T5WIVzz4=; b=oEzYTk/7xqxg11CHWaeHHBcbR5kV6vqSdU9c24BTPwT886tXBWI2BnDnRdpTw2c8UD 7wjf1VBO7yzcYezyZpbX8iUVztvX/W4kcv8gi/Mjqj1q2mMexOtYe2hL384y92KFXMGb +ysXqZYidmNR+2gxExE+i2PcJqXRw6OFVErwhCO9A79m+Kquitt7d4DuViqZaCxmpS4s rTY9oOzALnbQHRyUiRG5S3/2eiij4STAuZwCpubtKCLa61FcniLJA792bivA5uk/JjCu HdseCA+sZmAhJ09mpjziLwylfnx39icAFLlMTyE2H8AvjxooYSi6xZu8dPRGA0wH141/ 1/0A== 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:mime-version :content-transfer-encoding; bh=WTTaB7vbAH9EInR8zIsv3HYxyADXG9+vxH9T5WIVzz4=; b=UT6BVfypTsy/IKL8M7PlFRjUZttV/VvBDeDc+RSxnJwUxHtZrYxmIEvgtgpMMDyXdK 52qZaMjWFHM9r8F5Zk78j8jHhMkPLrsWVxRpGgOMgkyAoO6QRAEM1wpgAg1wOyVywwRC h0NscQ78M2D/MxU1QklMUvnUe6Nfsc0eDC5ECPvECvf0c0f1qFjw9Tn1lGkXh+6uxSSi V5RQETl1+LjfKHbXdjDMii72qe18mqB6l+GnkLMm7j5vGDXmob6hH0RJQln4gHWOloJw dLiF6lzULPCijMeUznCSr6io1xedFdndFVvBluI/DD7T83kLrqYOKcRW+7mmfcJxtyoE Cl5Q== X-Gm-Message-State: APjAAAUA40GOXp/pm+5pTVbyCsd0Hg2iCVJ5p+zQDhub4YH9pYJoMuv3 BWPUlTfC7XiQeZc2I9VVbZOfSpWl X-Google-Smtp-Source: APXvYqz1dz18umAZdL50ms1Im8JWQJHzg6K2f5CFmpO1Nkxl0+qATkL+KHLmljoy0mMIBDy6OGrt/w== X-Received: by 2002:a05:600c:2056:: with SMTP id p22mr4523497wmg.159.1565924779439; Thu, 15 Aug 2019 20:06:19 -0700 (PDT) Received: from localhost.localdomain (ipbcc08b69.dynamic.kabel-deutschland.de. [188.192.139.105]) by smtp.gmail.com with ESMTPSA id x20sm8501603wrg.10.2019.08.15.20.06.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Aug 2019 20:06:18 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 16 Aug 2019 05:05:21 +0200 Message-Id: <20190816030531.4775-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/11] 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 allocates memory which is later used and freed in the calling function and passed at the end of matroska_parse_laces. But there is actually no reason to pass it at the end: This commit sets the address of the newly allocated memory as soon as it is known and exits the subfunction as soon as an error is encountered. Signed-off-by: Andreas Rheinhardt --- libavformat/matroskadec.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 4e20f15792..25f26da074 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -2999,7 +2999,7 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, int *buf_size, int type, uint32_t **lace_buf, int *laces) { - int res = 0, n, size = *buf_size; + int n, size = *buf_size; uint8_t *data = *buf; uint32_t *lace_size; @@ -3018,6 +3018,7 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, data += 1; size -= 1; lace_size = av_malloc_array(*laces, sizeof(*lace_size)); + *lace_buf = lace_size; if (!lace_size) return AVERROR(ENOMEM); @@ -3026,13 +3027,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; @@ -3044,8 +3044,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; @@ -3054,8 +3053,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; @@ -3069,21 +3067,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; @@ -3091,8 +3087,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; @@ -3100,10 +3095,9 @@ static int matroska_parse_laces(MatroskaDemuxContext *matroska, uint8_t **buf, } *buf = data; - *lace_buf = lace_size; *buf_size = size; - return res; + return 0; } static int matroska_parse_rm_audio(MatroskaDemuxContext *matroska, @@ -3537,7 +3531,7 @@ static int matroska_parse_block(MatroskaDemuxContext *matroska, AVBufferRef *buf int res = 0; AVStream *st; int16_t block_time; - uint32_t *lace_size = NULL; + uint32_t *lace_size; int n, flags, laces = 0; uint64_t num; int trust_default_duration = 1;