From patchwork Mon Feb 3 18:55:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jai Luthra X-Patchwork-Id: 17677 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 79C7244399B for ; Mon, 3 Feb 2020 20:56:06 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 391ED6898D0; Mon, 3 Feb 2020 20:56:06 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from wnew4-smtp.messagingengine.com (wnew4-smtp.messagingengine.com [64.147.123.18]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C8562688184 for ; Mon, 3 Feb 2020 20:55:58 +0200 (EET) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailnew.west.internal (Postfix) with ESMTP id 0AD37863 for ; Mon, 3 Feb 2020 13:55:55 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Mon, 03 Feb 2020 13:55:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jailuthra.in; h= from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=P/swPzcR33uo2 Jn5qnfrwtYACg2WRwmpeaUZDbyTkJI=; b=Z8WmiI3K/91A3+tFMOloY5WX/MFBj M0G6rojpAxbLJUrvKyhlWfQ3t/zNuX+tEfO1QLiZ5/fZA0mYs5QqLbVKjUQmHIVO +dxiTQbsZAfEtVjtwGYQtHaOmYNyRxg6dd4NoXHEwtk5D1nslrlWxjhlgdq+N562 4t2ziT2qCkThHO+GIBKuMB8FQDvPW6i+9YREpimhOw67vp/wayboBcZSykYW7IMl 8vw2+NCWojguC11BwmU6jGXRPxGMqqYZFq9uz8iIyEokMo55RLDeZxvpkpYUk2o2 9K3H5DzTGiY02e13hi9fHhvcDVjfS4gogTao4SePrYkx0SQOaKJ9WsTtg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=P/swPzcR33uo2Jn5qnfrwtYACg2WRwmpeaUZDbyTkJI=; b=W2lXX0kG uG00Vo8Jvabz1iFndABcnE662yzoUPJSiMTnpPRbdbeqZ8sJoWwWdaj1Cz8e6QDq KrdtXBLQTgNqZ5hJyvfwTup7CtCyWyvtCjM7Exufgs+/xP8POKCrNdYsFYEqW9iF MFnFIaHD1gX6UA4ClAlG/zfzQJx/vNA5tqxj1zHsV/8IgSC5117//b485Hv6zdKL BPwZ7uzrgJiZIbJwT+wel3aP66Vnb9wFWp0DVNywcTWEQzhX1/7bWPfj3lc/FBfE MdL9tetBIyeJ5EFKDCo6X4v/MfRiTJ+KkxF8N6OAlZMQJ8cJDPk6iMqBaWH+VYk7 Aja/aK48CbYhlw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrgeejgdduudeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomheplfgrihcunfhuthhhrhgruceomhgvsehjrghilhhuthhhrhgr rdhinheqnecukfhppeegledrvddtjedrheehrddugedvnecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomhepmhgvsehjrghilhhuthhhrhgrrdhinh X-ME-Proxy: Received: from localhost.localdomain (unknown [49.207.55.142]) by mail.messagingengine.com (Postfix) with ESMTPA id 5564B30605C5 for ; Mon, 3 Feb 2020 13:55:54 -0500 (EST) From: Jai Luthra To: ffmpeg-devel@ffmpeg.org Date: Tue, 4 Feb 2020 00:25:52 +0530 Message-Id: <20200203185552.22724-1-me@jailuthra.in> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200124103334.110855-1-me@jailuthra.in> References: <20200124103334.110855-1-me@jailuthra.in> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 6/7] mlpenc: fix -fsanitize=integer errors 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Jai Luthra --- libavcodec/mlpenc.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) v2: fixes more integer issues diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c index 347a43248c..173cf71956 100644 --- a/libavcodec/mlpenc.c +++ b/libavcodec/mlpenc.c @@ -87,11 +87,11 @@ typedef struct { } DecodingParams; typedef struct BestOffset { - int16_t offset; + int32_t offset; int bitcount; int lsb_bits; - int16_t min; - int16_t max; + int32_t min; + int32_t max; } BestOffset; #define HUFF_OFFSET_MIN (-16384) @@ -568,7 +568,7 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx) } ctx->coded_sample_fmt[1] = -1 & 0xf; - ctx->dts = -avctx->frame_size; + ctx->dts = (uint16_t) (-avctx->frame_size); ctx->num_channels = avctx->channels + 2; /* +2 noise channels */ ctx->one_sample_buffer_size = avctx->frame_size @@ -1249,7 +1249,7 @@ static void input_data_internal(MLPEncodeContext *ctx, const uint8_t *samples, uint32_t abs_sample; int32_t sample; - sample = is24 ? *samples_32++ >> 8 : *samples_16++ * 256U; + sample = is24 ? *samples_32++ >> 8 : *samples_16++ * 256; /* TODO Find out if number_sbits can be used for negative values. */ abs_sample = FFABS(sample); @@ -1589,7 +1589,7 @@ static void no_codebook_bits(MLPEncodeContext *ctx, BestOffset *bo) { DecodingParams *dp = ctx->cur_decoding_params; - int16_t offset; + int32_t offset; int32_t unsign = 0; uint32_t diff; int lsb_bits; @@ -1611,7 +1611,7 @@ static void no_codebook_bits(MLPEncodeContext *ctx, /* If all samples are the same (lsb_bits == 0), offset must be * adjusted because of sign_shift. */ - offset = min + diff / 2 + !!lsb_bits; + offset = min + (int) (diff / 2) + !!lsb_bits; bo->offset = offset; bo->lsb_bits = lsb_bits; @@ -1792,7 +1792,7 @@ static void determine_bits(MLPEncodeContext *ctx) #define SAMPLE_MAX(bitdepth) ((1 << (bitdepth - 1)) - 1) #define SAMPLE_MIN(bitdepth) (~SAMPLE_MAX(bitdepth)) -#define MSB_MASK(bits) (-(1u << (bits))) +#define MSB_MASK(bits) (-(int)(1u << (bits))) /** Applies the filter to the current samples, and saves the residual back * into the samples buffer. If the filter is too bad and overflows the @@ -2280,8 +2280,8 @@ static int mlp_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, bytes_written = write_access_unit(ctx, avpkt->data, avpkt->size, restart_frame); - ctx->timestamp += ctx->frame_size[ctx->frame_index]; - ctx->dts += ctx->frame_size[ctx->frame_index]; + ctx->timestamp = (uint16_t) (ctx->timestamp + ctx->frame_size[ctx->frame_index]); + ctx->dts = (uint16_t) (ctx->dts + ctx->frame_size[ctx->frame_index]); input_and_return: