From patchwork Tue Sep 24 22:03:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 15270 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 1A35A449BE7 for ; Wed, 25 Sep 2019 01:03:50 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F272968A423; Wed, 25 Sep 2019 01:03:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 05A5868A2CA for ; Wed, 25 Sep 2019 01:03:40 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id o18so3789641wrv.13 for ; Tue, 24 Sep 2019 15:03:40 -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=tF1LifpltT99crcya9nxreIMHqM9XWXinjHtG/xNRCk=; b=tTg+U0pFpCwdHaNaUH404mf3j7y5MCG2AO+jR79h68NTIpxxe65w1YrL9V8EtQx4mw dd4IjcOA6am7tWtUnomMNnxX/ts7YrferSvYj1HTMQ24YHrS1yvrg4J1dCW/YYn6siHk UaC6QZQ9rRS/QLDD6qI9ti3CoC5FaQ2hzbTCIaI3SLrR6pGPhGca4fLePrGSMFGsEiRl u7UEY8nn2+4LkHS2PLM4dyKZdemYOO3XJ5d1A2J8JKWmY8xGXmoV+0/nHZQI2uoOx7k4 J3RmeBdqHkhTlKA7J+Wulc6bPag2x/ewAuf3Y116xwYjf4EXnAKwuiC3g+zj4fHw7075 BpYA== 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=tF1LifpltT99crcya9nxreIMHqM9XWXinjHtG/xNRCk=; b=eaFA8eiw9sGbKUE4dSv/TwwPAnqpf5u8tOZt3XDbvFp/6LaqFZYD+WKDlzDxApbIPC 50+0dhIJyyuObASvBh3D+mweE+VNWsOPhBj7hyuWhkm+5Y4b4Spj7hCA9/rehKVitRKw +LzrtNYRHy4vgSHQmhnM9iQyD9drMXlXjhOyukUzkm8KoKJp0LMwgHtO53wUMMZrklSu CvrhPSmiLpBgZkj91bgYctEmmlLsU77z6vCdDIXsy1az/eQ+c5wVavTf8SR+1nbXevVp 1+UX8fQWnGKXUeMXrhZsSW49PBcWSpvdY5AccsPR1jZLjSK+JOdmORIesfUqFxVAGXqy Rn7A== X-Gm-Message-State: APjAAAV203Y4PUy4+cSj3xAHZrofO9kQYe+f7/ZtXCma7HWYuRslCiW4 BN95HfDEl6VbXf3NsPKafGQbLKgN X-Google-Smtp-Source: APXvYqwM/jG3Ymt5eqbr1ghoekNoJn4zYxJ8+zNKT4HxR305lW7c4FBRaaku4Vxzb/OJEZxaarJxHQ== X-Received: by 2002:adf:ce83:: with SMTP id r3mr5393254wrn.219.1569362619290; Tue, 24 Sep 2019 15:03:39 -0700 (PDT) Received: from sblaptop.fritz.box ([188.192.248.87]) by smtp.gmail.com with ESMTPSA id l1sm3023808wrb.1.2019.09.24.15.03.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Sep 2019 15:03:38 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 25 Sep 2019 00:03:01 +0200 Message-Id: <20190924220310.31157-7-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190924220310.31157-1-andreas.rheinhardt@gmail.com> References: <20190924220310.31157-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/15] avcodec/adpcm: Fix undefined left shifts of negative numbers 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" Affected the adpcm-afc, adpcm-dtk, adpcm-ea-1, adpcm-ea-2, adpcm-ima-oki, adpcm-ea-maxis-xa, adpcm-ea-r1, adpcm-ea-r2, adpcm-ea-r3 and adpcm-thp FATE-tests. Signed-off-by: Andreas Rheinhardt --- libavcodec/adpcm.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index 7f2ebfc99d..08178d9d41 100644 --- a/libavcodec/adpcm.c +++ b/libavcodec/adpcm.c @@ -342,7 +342,7 @@ static inline int16_t adpcm_ima_oki_expand_nibble(ADPCMChannelStatus *c, int nib c->predictor = av_clip_intp2(predictor, 11); c->step_index = step_index; - return c->predictor << 4; + return FFLSHIFT(c->predictor, 4); } static inline int16_t adpcm_ct_expand_nibble(ADPCMChannelStatus *c, int8_t nibble) @@ -1279,8 +1279,8 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, for (count2 = 0; count2 < 28; count2++) { byte = bytestream2_get_byteu(&gb); - next_left_sample = sign_extend(byte >> 4, 4) << shift_left; - next_right_sample = sign_extend(byte, 4) << shift_right; + next_left_sample = FFLSHIFT(sign_extend(byte >> 4, 4), shift_left); + next_right_sample = FFLSHIFT(sign_extend(byte, 4), shift_right); next_left_sample = (next_left_sample + (current_left_sample * coeff1l) + @@ -1319,7 +1319,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, if (st) byte[1] = bytestream2_get_byteu(&gb); for(i = 4; i >= 0; i-=4) { /* Pairwise samples LL RR (st) or LL LL (mono) */ for(channel = 0; channel < avctx->channels; channel++) { - int sample = sign_extend(byte[channel] >> i, 4) << shift[channel]; + int sample = FFLSHIFT(sign_extend(byte[channel] >> i, 4), shift[channel]); sample = (sample + c->status[channel].sample1 * coeff[channel][0] + c->status[channel].sample2 * coeff[channel][1] + 0x80) >> 8; @@ -1380,10 +1380,10 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, for (count2=0; count2<28; count2++) { if (count2 & 1) - next_sample = sign_extend(byte, 4) << shift; + next_sample = FFLSHIFT(sign_extend(byte, 4), shift); else { byte = bytestream2_get_byte(&gb); - next_sample = sign_extend(byte >> 4, 4) << shift; + next_sample = FFLSHIFT(sign_extend(byte >> 4, 4), shift); } next_sample += (current_sample * coeff1) + @@ -1595,8 +1595,8 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, sampledat = sign_extend(byte >> 4, 4); } - sampledat = ((prev1 * factor1 + prev2 * factor2) + - ((sampledat * scale) << 11)) >> 11; + sampledat = ((prev1 * factor1 + prev2 * factor2) >> 11) + + sampledat * scale; *samples = av_clip_int16(sampledat); prev2 = prev1; prev1 = *samples++; @@ -1673,7 +1673,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, } sampledat = ((c->status[ch].sample1 * factor1 - + c->status[ch].sample2 * factor2) >> 11) + (sampledat << exp); + + c->status[ch].sample2 * factor2) >> 11) + FFLSHIFT(sampledat, exp); *samples = av_clip_int16(sampledat); c->status[ch].sample2 = c->status[ch].sample1; c->status[ch].sample1 = *samples++; @@ -1720,7 +1720,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, else sampledat = sign_extend(byte >> 4, 4); - sampledat = (((sampledat << 12) >> (header & 0xf)) << 6) + prev; + sampledat = FFLSHIFT(FFLSHIFT(sampledat, 12) >> (header & 0xf), 6) + prev; *samples++ = av_clip_int16(sampledat >> 6); c->status[channel].sample2 = c->status[channel].sample1; c->status[channel].sample1 = sampledat;