From patchwork Sat Oct 24 13:03:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 23197 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 A75F344B5BB for ; Sat, 24 Oct 2020 16:04:04 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 87F3F68AE41; Sat, 24 Oct 2020 16:04:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B0FD0688368 for ; Sat, 24 Oct 2020 16:03:57 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id v5so5182339wmh.1 for ; Sat, 24 Oct 2020 06:03:57 -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=J5ZFKGpPwhsvKwRpgDzBj2cybAzaVEKvBWJ8Tuw1QQo=; b=USGRjoLjsZblhbkPsYfAYJMWhzH/FJJOjutW7+J20a5mn7MqAkLd48PBGfmCDuMPcC kYhNQZbdMt9doXlFY0lP/r7xVQMGs69cZfU6xwmDDCnZ5qzOtuy4Lf2nJATT0mcnasij Ldk6OK8K6fSKt0dP6fyc4zg+WLzzi8iGmC8CxWEhStXG1CXPP78ikV9iu/kQ6c+DDRgF T8OcMq6Q3Fk+IpVueXtCcOfFPQMmCPtxuyOdIjdiYKTpUG0qbin1Ys/6Ji090TOACEn2 99iRv+ksd4H+G3CSvuqliBxEYEQggUoyfPOgokuK+X4EhbCCYqzlsQ4TpG/Dq2RgIi45 0Sdw== 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=J5ZFKGpPwhsvKwRpgDzBj2cybAzaVEKvBWJ8Tuw1QQo=; b=Inj8kMtr4Kl41XKffu9gG7IfLM8hf8K5IzK0YaPxLn+r9EHA6p4vCmqfXI4Qskjlj1 kgLTIWfH9v4xLG4qsu0hpFQs5ytsOPfC1LKEr61ppmJMYKX7vgEL6QHD8h4g0QLQ51It 0WIg1pTGkGOsXbTYLq+kNrKbAT8lGeLn5mXjKHKkgKIoh2IrPPX90Yh/xwqCttsqzTkz /MBGeUxt+puY8zux0oagChDo/Pw2gR3CAN7jRgGD085akPZng2WAHD7jWyMwgOFxn0Q4 AR6HZpNfDpbfJr4lXCsE4S9jfjn3aGU3+AO6qxsmPz+XRRK/bxkIsNfJcwRwGiNPGbyy an9w== X-Gm-Message-State: AOAM5319JP1N6Qq0AKFNkKfjjvCb4XElv+OXE9Z50XEj8RvLC6ybPIn6 HQ97RwSK7slJKImpDt8B8StlR8CnsCo= X-Google-Smtp-Source: ABdhPJyc2SGC8c8QSXGecXKcA2cp1RaZWIFXj5P8SdgvDgszLZssh2UekSB88guE3LXSqy0o16/UOQ== X-Received: by 2002:a1c:7d49:: with SMTP id y70mr6965568wmc.103.1603544631314; Sat, 24 Oct 2020 06:03:51 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id d129sm10978479wmd.5.2020.10.24.06.03.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Oct 2020 06:03:49 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 24 Oct 2020 15:03:00 +0200 Message-Id: <20201024130300.45644-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201024130300.45644-1-andreas.rheinhardt@gmail.com> References: <20201024130300.45644-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/bitstream: Stop allocating one VLCcode more than needed 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" Allocating one temporary entry more than needed was made necessary by the COPY loop below writing an element before having checked that it should be written at all. But given that this behaviour changed, the need for overallocating is gone. Signed-off-by: Andreas Rheinhardt --- libavcodec/bitstream.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c index ffa352b28b..39749c6092 100644 --- a/libavcodec/bitstream.c +++ b/libavcodec/bitstream.c @@ -281,7 +281,7 @@ int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, vlc = vlc_arg; vlc->bits = nb_bits; if (flags & INIT_VLC_USE_NEW_STATIC) { - av_assert0(nb_codes + 1 <= FF_ARRAY_ELEMS(localbuf)); + av_assert0(nb_codes <= FF_ARRAY_ELEMS(localbuf)); localvlc = *vlc_arg; vlc = &localvlc; vlc->table_size = 0; @@ -290,8 +290,8 @@ int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, vlc->table_allocated = 0; vlc->table_size = 0; } - if (nb_codes + 1 > FF_ARRAY_ELEMS(localbuf)) { - buf = av_malloc_array((nb_codes + 1), sizeof(VLCcode)); + if (nb_codes > FF_ARRAY_ELEMS(localbuf)) { + buf = av_malloc_array(nb_codes, sizeof(VLCcode)); if (!buf) return AVERROR(ENOMEM); } else