From patchwork Mon May 25 14:07:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19855 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 99DBD44A859 for ; Mon, 25 May 2020 17:08:40 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7CDAD68A471; Mon, 25 May 2020 17:08:40 +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 A6E89680C0D for ; Mon, 25 May 2020 17:08:33 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id g14so9312107wme.1 for ; Mon, 25 May 2020 07:08:33 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=tdIcVmghw9hSAL3Mt3Bdcpnd3/T2J6bxlrVF6k7YE2Q=; b=MGvOS6afReuF59wjE5MzEWKWCYpH5Jc8NNaC1MAEI5P4adHNueHWFeXMuq6FH+NRZV Y+k6jzKws6DN4p85mLYTB6HF5WQ48j8Nrx907iybYPLu1RjRTto7m6YCzj2TxnmdYTUV zALbOp+MOQ3Msqjh1ogNENggm+3JQH6nAS2z9CyNWijjKLoPHczLombJpaMrfWJm+vGO OYsnMniHhdF50w/vW4Sm2l3Nf7PJ1mrG2d8upj2Rp+4jn73Xmr1e3p5TQ/rGg4z5U70+ KiGn9kcvMj52ikKN3OoLoR/b9CjjKGxRbgB3OoijttezO02dM+q9q/MCWt9si1IaqvYs F7bQ== 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=tdIcVmghw9hSAL3Mt3Bdcpnd3/T2J6bxlrVF6k7YE2Q=; b=QQ67i+ukt2+ajN54ME+7V9n7+FRqjrMKCoDmUfv//OiIzTeA/UQYQunzLSrXs2sD2m Y7WW0MArw6PZMW5yOCFvaDpUFVmuliE7loJfehteiQA8yz/c9mVeD+snaiWECRX3zlRs qBys7SfBeHgfvF90aAKxToGmcaaHzb6OdbGkG0vKeKtg4BFQFUCuvUvLvpIKIn7RsX5f /nRKHgQ1wPJT6thUDVp8nR27vDIXghSDBxT51hHZ76BAb3S6Us75+p2MRbJjwQedoTrM 1uxwvk8dIcKRgHJNo9710Fk7LtcPq5mo4VUGlEsNo4PTgHNiKZZiYX5cxkVdZhzAFiiJ V31w== X-Gm-Message-State: AOAM531nnsAGegNur19UNaWF0mnPisnoEI8VYiYs++JzsqHOjQ96MMFw unKj+boDWneuqhfsXO8k7jy6tVwp X-Google-Smtp-Source: ABdhPJyEoOqwTg6KgKJjCOfqvwb8L2EUpxiyw4W4yXDH/O2vbOy0SGhoDuqD3DPaKPgK6ln6cFrCXA== X-Received: by 2002:a1c:7712:: with SMTP id t18mr24091827wmi.182.1590415712850; Mon, 25 May 2020 07:08:32 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id x186sm10355218wmg.8.2020.05.25.07.08.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 May 2020 07:08:32 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 25 May 2020 16:07:58 +0200 Message-Id: <20200525140801.18889-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200525140801.18889-1-andreas.rheinhardt@gmail.com> References: <20200525140801.18889-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/5] avformat/aviobuf: Simplify dyn_buf_write() a bit 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" Signed-off-by: Andreas Rheinhardt --- libavformat/aviobuf.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 33c2d6f037..fcde7e8510 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -1272,22 +1272,19 @@ typedef struct DynBuffer { static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size) { DynBuffer *d = opaque; - unsigned new_size, new_allocated_size; + unsigned new_size; /* reallocate buffer if needed */ new_size = (unsigned)d->pos + buf_size; - new_allocated_size = d->allocated_size; if (new_size < d->pos || new_size > INT_MAX/2) return -1; - while (new_size > new_allocated_size) { - if (!new_allocated_size) - new_allocated_size = new_size; - else + if (new_size > d->allocated_size) { + unsigned new_allocated_size = d->allocated_size ? d->allocated_size + : new_size; + int err; + while (new_size > new_allocated_size) new_allocated_size += new_allocated_size / 2 + 1; - } - if (new_allocated_size > d->allocated_size) { - int err; if ((err = av_reallocp(&d->buffer, new_allocated_size)) < 0) { d->allocated_size = 0; d->size = 0;