Skip to content

Commit 2c6ffca

Browse files
committed
fix [-Warray-bounds=]
1 parent b24898d commit 2c6ffca

File tree

2 files changed

+14
-65
lines changed

2 files changed

+14
-65
lines changed

src/opus_decoder/silk.cpp

Lines changed: 14 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,66 +2787,6 @@ void SilkDecoder::silk_PLC_glue_frames(uint8_t n, int16_t frame[], int32_t lengt
27872787
}
27882788
}
27892789
//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
2790-
/* Downsample by a factor 2/3, low quality */
2791-
void SilkDecoder::silk_resampler_down2_3(int32_t* S, /* I/O State vector [ 6 ] */
2792-
int16_t* out, /* O Output signal [ floor(2*inLen/3) ] */
2793-
const int16_t* in, /* I Input signal [ inLen ] */
2794-
int32_t inLen /* I Number of input samples */
2795-
) {
2796-
int32_t nSamplesIn, counter, res_Q6;
2797-
int32_t* buf_ptr;
2798-
2799-
ps_ptr<int32_t>buf; buf.alloc_array(RESAMPLER_MAX_BATCH_SIZE_IN + ORDER_FIR);
2800-
2801-
/* Copy buffered samples to start of buffer */
2802-
memcpy(buf.get(), S, ORDER_FIR * sizeof(int32_t));
2803-
2804-
/* Iterate over blocks of frameSizeIn input samples */
2805-
while(1) {
2806-
nSamplesIn = silk_min(inLen, RESAMPLER_MAX_BATCH_SIZE_IN);
2807-
2808-
/* Second-order AR filter (output in Q8) */
2809-
silk_resampler_private_AR2(&S[ORDER_FIR], &buf[ORDER_FIR], in, silk_Resampler_2_3_COEFS_LQ, nSamplesIn);
2810-
2811-
/* Interpolate filtered signal */
2812-
buf_ptr = buf.get();
2813-
counter = nSamplesIn;
2814-
while(counter > 2) {
2815-
/* Inner product */
2816-
res_Q6 = silk_SMULWB(buf_ptr[0], silk_Resampler_2_3_COEFS_LQ[2]);
2817-
res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[1], silk_Resampler_2_3_COEFS_LQ[3]);
2818-
res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[2], silk_Resampler_2_3_COEFS_LQ[5]);
2819-
res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[3], silk_Resampler_2_3_COEFS_LQ[4]);
2820-
2821-
/* Scale down, saturate and store in output array */
2822-
*out++ = (int16_t)silk_SAT16(silk_RSHIFT_ROUND(res_Q6, 6));
2823-
2824-
res_Q6 = silk_SMULWB(buf_ptr[1], silk_Resampler_2_3_COEFS_LQ[4]);
2825-
res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[2], silk_Resampler_2_3_COEFS_LQ[5]);
2826-
res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[3], silk_Resampler_2_3_COEFS_LQ[3]);
2827-
res_Q6 = silk_SMLAWB(res_Q6, buf_ptr[4], silk_Resampler_2_3_COEFS_LQ[2]);
2828-
2829-
/* Scale down, saturate and store in output array */
2830-
*out++ = (int16_t)silk_SAT16(silk_RSHIFT_ROUND(res_Q6, 6));
2831-
2832-
buf_ptr += 3;
2833-
counter -= 3;
2834-
}
2835-
2836-
in += nSamplesIn;
2837-
inLen -= nSamplesIn;
2838-
2839-
if(inLen > 0) {
2840-
/* More iterations to do; copy last part of filtered signal to beginning of buffer */
2841-
memcpy(buf.get(), &buf[nSamplesIn], ORDER_FIR * sizeof(int32_t));
2842-
}
2843-
else { break; }
2844-
}
2845-
2846-
/* Copy last part of filtered signal to the state for the next call */
2847-
memcpy(S, &buf[nSamplesIn], ORDER_FIR * sizeof(int32_t));
2848-
}
2849-
//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
28502790
/* Downsample by a factor 2 */
28512791
void SilkDecoder::silk_resampler_down2(int32_t* S, /* I/O State vector [ 2 ] */
28522792
int16_t* out, /* O Output signal [ floor(len/2) ] */
@@ -3084,7 +3024,11 @@ void SilkDecoder::silk_resampler_private_IIR_FIR(void* SS, /* I/O Re
30843024
int32_t nSamplesIn;
30853025
int32_t max_index_Q16, index_increment_Q16;
30863026

3087-
ps_ptr<int16_t>buf; buf.alloc_array(2 * S->batchSize + RESAMPLER_ORDER_FIR_12);
3027+
ps_ptr<int16_t> buf;
3028+
int32_t buf_size = 2 * S->batchSize + RESAMPLER_ORDER_FIR_12;
3029+
if (!buf.alloc_array(buf_size)) {
3030+
return; // Allocation failed
3031+
}
30883032

30893033
/* Copy buffered samples to start of buffer */
30903034
memcpy(buf.get(), S->sFIR.i16, RESAMPLER_ORDER_FIR_12 * sizeof(int16_t));
@@ -3095,7 +3039,7 @@ void SilkDecoder::silk_resampler_private_IIR_FIR(void* SS, /* I/O Re
30953039
nSamplesIn = silk_min(inLen, S->batchSize);
30963040

30973041
/* Upsample 2x */
3098-
silk_resampler_private_up2_HQ(S->sIIR, &buf[RESAMPLER_ORDER_FIR_12], in, nSamplesIn);
3042+
silk_resampler_private_up2_HQ(S->sIIR, buf.get() + RESAMPLER_ORDER_FIR_12, in, nSamplesIn);
30993043

31003044
max_index_Q16 = silk_LSHIFT32(nSamplesIn, 16 + 1); /* + 1 because 2x upsampling */
31013045
out = silk_resampler_private_IIR_FIR_INTERPOL(out, buf.get(), max_index_Q16, index_increment_Q16);
@@ -3104,13 +3048,19 @@ void SilkDecoder::silk_resampler_private_IIR_FIR(void* SS, /* I/O Re
31043048

31053049
if(inLen > 0) {
31063050
/* More iterations to do; copy last part of filtered signal to beginning of buffer */
3107-
memcpy(buf.get(), &buf[nSamplesIn << 1], RESAMPLER_ORDER_FIR_12 * sizeof(int16_t));
3051+
int32_t src_offset = nSamplesIn << 1;
3052+
if (src_offset + RESAMPLER_ORDER_FIR_12 <= buf_size) {
3053+
memcpy(buf.get(), buf.get() + src_offset, RESAMPLER_ORDER_FIR_12 * sizeof(int16_t));
3054+
}
31083055
}
31093056
else { break; }
31103057
}
31113058

31123059
/* Copy last part of filtered signal to the state for the next call */
3113-
memcpy(S->sFIR.i16, &buf[nSamplesIn << 1], RESAMPLER_ORDER_FIR_12 * sizeof(int16_t));
3060+
int32_t src_offset = nSamplesIn << 1;
3061+
if (src_offset + RESAMPLER_ORDER_FIR_12 <= buf_size) {
3062+
memcpy(S->sFIR.i16, buf.get() + src_offset, RESAMPLER_ORDER_FIR_12 * sizeof(int16_t));
3063+
}
31143064
}
31153065
//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
31163066
/* Upsample by a factor 2, high quality. Uses 2nd order allpass filters for the 2x upsampling, followed by a */

src/opus_decoder/silk.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ class SilkDecoder{
272272
void silk_PLC_update(uint8_t n);
273273
void silk_PLC_energy(int32_t *energy1, int32_t *shift1, int32_t *energy2, int32_t *shift2, const int32_t *exc_Q14, const int32_t *prevGain_Q10, int subfr_length, int nb_subfr);
274274
void silk_PLC_conceal(uint8_t n, int16_t frame[]);
275-
void silk_resampler_down2_3(int32_t *S, int16_t *out, const int16_t *in, int32_t inLen);
276275
void silk_resampler_down2(int32_t *S, int16_t *out, const int16_t *in, int32_t inLen);
277276
void silk_resampler_private_AR2(int32_t S[], int32_t out_Q8[], const int16_t in[], const int16_t A_Q14[], int32_t len);
278277
int16_t *silk_resampler_private_down_FIR_INTERPOL(int16_t *out, int32_t *buf, const int16_t *FIR_Coefs, int32_t FIR_Order, int32_t FIR_Fracs, int32_t max_index_Q16, int32_t index_increment_Q16);

0 commit comments

Comments
 (0)