diff --git a/lib_com/options.h b/lib_com/options.h index 865e54b2f78761e39ad06e06d7335e3ca30d8684..e6eeefe4f40f8153471ab4acd2814404dd02682b 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -157,6 +157,10 @@ // #define FIX_966_VAR_OVERFLOW_IN_HARM_MODEL_ARI /* FhG: fix and undef behaviour bug in the harmonic TCX model arithmetic coder */ #define FIX_983_DISC_ISM_DIGEST_NUM_OBJS /* FhG: issue #983: the discrete ISM digest function uses the wrong number of objects */ + +#define FIX_976_USAN_PVQ_ENC_DEC_EVS_CR /* Ericsson: premature cast to unsigned detected by USAN corrected */ + + /* #################### End BE switches ################################## */ /* #################### Start NON-BE switches ############################ */ diff --git a/lib_dec/pvq_core_dec.c b/lib_dec/pvq_core_dec.c index 841b31077ab6e67e25a759a27ae47dad7dd54038..a736792c31bad50b98a1443958b3183e840e9428 100644 --- a/lib_dec/pvq_core_dec.c +++ b/lib_dec/pvq_core_dec.c @@ -98,6 +98,7 @@ static void pvq_decode_band( } set_s( g_part_s, -32768, Np ); + if ( Np > 1 ) { decode_energies( st, hPVQ, Np, dim_part, bits_part, g_part_s, band_bits_tot, bits_left, sfmsize, strict_bits ); @@ -113,10 +114,23 @@ static void pvq_decode_band( for ( j = 0; j < Np; j++ ) { g_part[j] = -( (float) g_part_s[j] ) / 32768; +#ifdef FIX_976_USAN_PVQ_ENC_DEC_EVS_CR + /* note: here g_part needs to be become exactly 1.0(float) thus in BASOP Word16 g_part_s is in the negative Q15 domain */ +#endif + + +#ifdef FIX_976_USAN_PVQ_ENC_DEC_EVS_CR + /* aligned to BASOP to avoid USAN undefined negation warning for -(-32768) */ + g_part_s[j] = negate( g_part_s[j] ); +#else g_part_s[j] = -g_part_s[j]; +#endif } + srt_vec_ind( g_part_s, sg_part, idx_sort, Np ); + + for ( j = 0; j < Np; j++ ) { js = idx_sort[Np - 1 - j]; @@ -415,11 +429,16 @@ static void densitySymbolIndexDecode( #undef WMC_TOOL_SKIP res_c = res - c; + if ( c == 0 ) { tot = res * ( res + 1 ) + 1; dec_freq = rc_decode( &st->BER_detect, hPVQ, tot ); +#ifdef FIX_976_USAN_PVQ_ENC_DEC_EVS_CR + alpha = (int16_t) floor_sqrt_exact( (uint32_t) ( ( res + 1 ) * ( res + 1 ) - dec_freq ) ) + res + 1; +#else alpha = (int16_t) floor_sqrt_exact( (uint32_t) ( res + 1 ) * ( res + 1 ) - dec_freq ) + res + 1; +#endif sym_freq = 2 * ( res - alpha ) + 1; cum_freq = alpha * ( 2 * ( res + 1 ) - alpha ); } @@ -437,7 +456,12 @@ static void densitySymbolIndexDecode( dec_freq = rc_decode( &st->BER_detect, hPVQ, tot ); if ( dec_freq < tot - ( res + 1 ) - ( res - ( c + 1 ) ) * ( res - c ) * c + c + 1 ) { +#ifdef FIX_976_USAN_PVQ_ENC_DEC_EVS_CR + alpha = ( res_c - 1 + (int16_t) floor_sqrt_exact( (uint32_t) ( res_c * ( res_c + 4 * dec_freq - 2 ) + 1 ) ) ) / ( 2 * res_c ); +#else alpha = ( res_c - 1 + (int16_t) floor_sqrt_exact( (uint32_t) res_c * ( res_c + 4 * dec_freq - 2 ) + 1 ) ) / ( 2 * res_c ); +#endif + sym_freq = 2 * alpha * res_c + 1; cum_freq = alpha * ( ( alpha - 1 ) * res_c + 1 ); } diff --git a/lib_enc/pvq_core_enc.c b/lib_enc/pvq_core_enc.c index ddb62560382fc70c93d35737a6c29dbb8aa0f03c..a8ca315ff5fe797b2294a17d90d5969a0c577f7f 100644 --- a/lib_enc/pvq_core_enc.c +++ b/lib_enc/pvq_core_enc.c @@ -124,7 +124,12 @@ static void pvq_encode_band( for ( j = 0; j < Np; j++ ) { g_part[j] = -( (float) g_part_s[j] ) / 32768; +#ifdef FIX_976_USAN_PVQ_ENC_DEC_EVS_CR + /* aligned to BASOP to avoid USAN undefined negation warning with -(-32768) */ + g_part_s[j] = negate( g_part_s[j] ); +#else g_part_s[j] = -g_part_s[j]; +#endif } srt_vec_ind( g_part_s, sg_part, idx_sort, Np ); diff --git a/scripts/ubsan.supp b/scripts/ubsan.supp index fc3f22e328b802ceb69a3447e5591957963195f5..c1602085d2fc8036d0b083fbfed56f21e9a30ebe 100644 --- a/scripts/ubsan.supp +++ b/scripts/ubsan.supp @@ -30,8 +30,6 @@ implicit-signed-integer-truncation:dec_tcx.c implicit-signed-integer-truncation:hdecnrm.c implicit-signed-integer-truncation:lib_dec.c implicit-signed-integer-truncation:longarith.c -implicit-signed-integer-truncation:pvq_core_dec.c -implicit-signed-integer-truncation:pvq_core_enc.c implicit-signed-integer-truncation:tcq_position_arith.c implicit-signed-integer-truncation:tools.c shift-base:basop32.c