Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: webrtc/modules/audio_coding/codecs/isac/fix/source/entropy_coding.c

Issue 1989803002: Fix UBSan errors (left shift of negative value) (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 248
249 for (n = 0; n < FRAMESAMPLES/8; n++) 249 for (n = 0; n < FRAMESAMPLES/8; n++)
250 diffQ16[n] = (CS_ptrQ9[n] * (CorrQ11[1] >> shftVal) + 2) >> 2; 250 diffQ16[n] = (CS_ptrQ9[n] * (CorrQ11[1] >> shftVal) + 2) >> 2;
251 for (k = 2; k < AR_ORDER; k += 2) { 251 for (k = 2; k < AR_ORDER; k += 2) {
252 CS_ptrQ9 = WebRtcIsacfix_kCos[k]; 252 CS_ptrQ9 = WebRtcIsacfix_kCos[k];
253 for (n = 0; n < FRAMESAMPLES/8; n++) 253 for (n = 0; n < FRAMESAMPLES/8; n++)
254 diffQ16[n] += (CS_ptrQ9[n] * (CorrQ11[k + 1] >> shftVal) + 2) >> 2; 254 diffQ16[n] += (CS_ptrQ9[n] * (CorrQ11[k + 1] >> shftVal) + 2) >> 2;
255 } 255 }
256 256
257 for (k=0; k<FRAMESAMPLES/8; k++) { 257 for (k=0; k<FRAMESAMPLES/8; k++) {
258 int32_t diff_q16 = diffQ16[k] << shftVal; 258 int32_t diff_q16 = diffQ16[k] * (1 << shftVal);
259 CurveQ16[FRAMESAMPLES / 4 - 1 - k] = CurveQ16[k] - diff_q16; 259 CurveQ16[FRAMESAMPLES / 4 - 1 - k] = CurveQ16[k] - diff_q16;
260 CurveQ16[k] += diff_q16; 260 CurveQ16[k] += diff_q16;
261 } 261 }
262 } 262 }
263 263
264 static void CalcRootInvArSpec(const int16_t *ARCoefQ12, 264 static void CalcRootInvArSpec(const int16_t *ARCoefQ12,
265 const int32_t gainQ10, 265 const int32_t gainQ10,
266 uint16_t *CurveQ8) 266 uint16_t *CurveQ8)
267 { 267 {
268 int32_t CorrQ11[AR_ORDER+1]; 268 int32_t CorrQ11[AR_ORDER+1];
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 matrix1_index_factor2 = &k; 857 matrix1_index_factor2 = &k;
858 } 858 }
859 859
860 for (j = 0; j < SUBFRAMES; j++) { 860 for (j = 0; j < SUBFRAMES; j++) {
861 matrix_prod_index = mid_loop_count * j; 861 matrix_prod_index = mid_loop_count * j;
862 for (k = 0; k < mid_loop_count; k++) { 862 for (k = 0; k < mid_loop_count; k++) {
863 int32_t sum32 = 0; 863 int32_t sum32 = 0;
864 matrix0_index = matrix0_index_factor1 * (*matrix0_index_factor2); 864 matrix0_index = matrix0_index_factor1 * (*matrix0_index_factor2);
865 matrix1_index = matrix1_index_factor1 * (*matrix1_index_factor2); 865 matrix1_index = matrix1_index_factor1 * (*matrix1_index_factor2);
866 for (n = 0; n < inner_loop_count; n++) { 866 for (n = 0; n < inner_loop_count; n++) {
867 sum32 += (WEBRTC_SPL_MUL_16_32_RSFT16(matrix0[matrix0_index], 867 sum32 += WEBRTC_SPL_MUL_16_32_RSFT16(
868 matrix1[matrix1_index] << shift)); 868 matrix0[matrix0_index], matrix1[matrix1_index] * (1 << shift));
869 matrix0_index += matrix0_index_step; 869 matrix0_index += matrix0_index_step;
870 matrix1_index += matrix1_index_step; 870 matrix1_index += matrix1_index_step;
871 } 871 }
872 matrix_product[matrix_prod_index] = sum32; 872 matrix_product[matrix_prod_index] = sum32;
873 matrix_prod_index++; 873 matrix_prod_index++;
874 } 874 }
875 } 875 }
876 } 876 }
877 877
878 /* 878 /*
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 /* lo band LAR coeffs */ 1035 /* lo band LAR coeffs */
1036 for (n=0; n<ORDERLO; n++, pos++, poss++) { 1036 for (n=0; n<ORDERLO; n++, pos++, poss++) {
1037 tmp32 = WEBRTC_SPL_MUL_16_32_RSFT16(31208, tmpcoeffs_sQ17[poss]); // (Q16* Q17)>>16 = Q17, with 1/2.1 = 0.47619047619 ~= 31208 in Q16 1037 tmp32 = WEBRTC_SPL_MUL_16_32_RSFT16(31208, tmpcoeffs_sQ17[poss]); // (Q16* Q17)>>16 = Q17, with 1/2.1 = 0.47619047619 ~= 31208 in Q16
1038 tmp32 = tmp32 + WebRtcIsacfix_kMeansShapeQ17[model][poss]; // Q17+Q17 = Q1 7 1038 tmp32 = tmp32 + WebRtcIsacfix_kMeansShapeQ17[model][poss]; // Q17+Q17 = Q1 7
1039 LPCCoefQ17[pos] = tmp32; 1039 LPCCoefQ17[pos] = tmp32;
1040 } 1040 }
1041 1041
1042 /* hi band LAR coeffs */ 1042 /* hi band LAR coeffs */
1043 for (n=0; n<ORDERHI; n++, pos++, poss++) { 1043 for (n=0; n<ORDERHI; n++, pos++, poss++) {
1044 // ((Q13*Q17)>>16)<<3 = Q17, with 1/0.45 = 2.222222222222 ~= 18204 in Q13 1044 // ((Q13*Q17)>>16)<<3 = Q17, with 1/0.45 = 2.222222222222 ~= 18204 in Q13
1045 tmp32 = WEBRTC_SPL_MUL_16_32_RSFT16(18204, tmpcoeffs_sQ17[poss]) << 3; 1045 tmp32 =
1046 WEBRTC_SPL_MUL_16_32_RSFT16(18204, tmpcoeffs_sQ17[poss]) * (1 << 3);
1046 tmp32 = tmp32 + WebRtcIsacfix_kMeansShapeQ17[model][poss]; // Q17+Q17 = Q1 7 1047 tmp32 = tmp32 + WebRtcIsacfix_kMeansShapeQ17[model][poss]; // Q17+Q17 = Q1 7
1047 LPCCoefQ17[pos] = tmp32; 1048 LPCCoefQ17[pos] = tmp32;
1048 } 1049 }
1049 } 1050 }
1050 1051
1051 1052
1052 *outmodel=model; 1053 *outmodel=model;
1053 1054
1054 return 0; 1055 return 0;
1055 } 1056 }
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 2026
2026 index_gQQ[k] = pos2QQ + WebRtcIsacfix_kQuantMinGain[k]; //ATTN: ok? 2027 index_gQQ[k] = pos2QQ + WebRtcIsacfix_kQuantMinGain[k]; //ATTN: ok?
2027 if (index_gQQ[k] < 0) { 2028 if (index_gQQ[k] < 0) {
2028 index_gQQ[k] = 0; 2029 index_gQQ[k] = 0;
2029 } 2030 }
2030 else if (index_gQQ[k] > WebRtcIsacfix_kMaxIndGain[k]) { 2031 else if (index_gQQ[k] > WebRtcIsacfix_kMaxIndGain[k]) {
2031 index_gQQ[k] = WebRtcIsacfix_kMaxIndGain[k]; 2032 index_gQQ[k] = WebRtcIsacfix_kMaxIndGain[k];
2032 } 2033 }
2033 } 2034 }
2034 } 2035 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698