Unverified Commit ebf62959 authored by norvell's avatar norvell
Browse files

Add FIX_1495_INCORRECT_FREAD_CALL to fix wrong order of size and number of elements in fread call

parent a0051869
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -116,6 +116,7 @@
#define FIX_2290_COPY_OF_UNINIT_DATA                    /* VA: prevent the copy of un-initialized data */
#define CLEANUP_ACELP_ENC                               /* VA: basop issue 2304: Remove duplicated code in excitation encoding in the ACELP core */
#define CLEANUP_VBR_CAM_ENC                             /* VA: basop issue 2299: Remove unused core-encoder VBR and CAM code */
#define FIX_1495_INCORRECT_FREAD_CALL                   /* Eri: Switched size and number of elements in fread call. */

/* #################### End BE switches ################################## */

+60 −0
Original line number Diff line number Diff line
@@ -306,7 +306,11 @@ static ivas_error TDREND_LoadBSplineBinaryITD(
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
    }
#ifdef FIX_1495_INCORRECT_FREAD_CALL
    fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf );
#else
    fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf );
#endif
    fread( v_tmp16, sizeof( Word16 ), modelITD->elevDim3 - 2, f_hrtf );
    for ( j = 0; j < modelITD->elevDim3 - 2; j++ )
    {
@@ -325,7 +329,11 @@ static ivas_error TDREND_LoadBSplineBinaryITD(
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
    }
#ifdef FIX_1495_INCORRECT_FREAD_CALL
    fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf );
#else
    fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf );
#endif
    fread( v_tmp16, sizeof( Word16 ), ( modelITD->azimDim3 + 1 ) / 2 - 2, f_hrtf );
    for ( j = 0; j < ( modelITD->azimDim3 + 1 ) / 2 - 2; j++ )
    {
@@ -344,7 +352,11 @@ static ivas_error TDREND_LoadBSplineBinaryITD(
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
    }

#ifdef FIX_1495_INCORRECT_FREAD_CALL
    fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf );
#else    
    fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf );
#endif 
    v_tmp16 = (Word16 *) malloc( tmp * sizeof( Word16 ) );
    if ( v_tmp16 == NULL )
    {
@@ -392,7 +404,11 @@ static ivas_error TDREND_LoadBSplineBinaryITD(
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
    }
#ifdef FIX_1495_INCORRECT_FREAD_CALL
    fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf );
#else    
    fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf );
#endif 
    fread( v_tmp16, sizeof( Word16 ), tmp, f_hrtf );
    for ( j = 0; j < tmp; j++ )
    {
@@ -440,7 +456,11 @@ static ivas_error TDREND_LoadBSplineBinaryITD(
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
    }
#ifdef FIX_1495_INCORRECT_FREAD_CALL
    fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf );
#else    
    fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf );
#endif 
    fread( v_tmp16, sizeof( Word16 ), tmp, f_hrtf );
    for ( j = 0; j < tmp; j++ )
    {
@@ -485,9 +505,17 @@ static ivas_error TDREND_LoadBSplineBinary(
        return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    }

#ifdef FIX_1495_INCORRECT_FREAD_CALL
    fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf );
#else    
    fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf );
#endif 
    HrFiltSet_p->latency_s_Q_fx = Q31 - factor_Q;
#ifdef FIX_1495_INCORRECT_FREAD_CALL
    fread( &HrFiltSet_p->latency_s_fx, sizeof( Word32 ), 1, f_hrtf );
#else
    fread( &HrFiltSet_p->latency_s_fx, 1, sizeof( Word32 ), f_hrtf );
#endif
    model = &( HrFiltSet_p->ModelParams );

    /* Set ROM flag for correct deallocation */
@@ -536,7 +564,11 @@ static ivas_error TDREND_LoadBSplineBinary(
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
    }
#ifdef FIX_1495_INCORRECT_FREAD_CALL
    fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf );
#else    
    fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf );
#endif 
    fread( v_tmp16, sizeof( Word16 ), model->elevDim3 - 2, f_hrtf );
    for ( j = 0; j < model->elevDim3 - 2; j++ )
    {
@@ -578,7 +610,11 @@ static ivas_error TDREND_LoadBSplineBinary(
        {
            return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
        }
#ifdef FIX_1495_INCORRECT_FREAD_CALL
        fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf );
#else    
        fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf );
#endif 
        fread( v_tmp16, sizeof( Word16 ), ( model->azimDim3_dyn[i] + 1 ), f_hrtf );
        for ( j = 0; j < model->azimDim3_dyn[i] + 1; j++ )
        {
@@ -598,7 +634,11 @@ static ivas_error TDREND_LoadBSplineBinary(
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
    }
#ifdef FIX_1495_INCORRECT_FREAD_CALL
    fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf );
#else    
    fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf );
#endif 

    model->AlphaL_e = Q15 - factor_Q;
    //    model->AlphaL_dyn_e = 1; /* force to 6 to be corrected  */
@@ -661,7 +701,11 @@ static ivas_error TDREND_LoadBSplineBinary(
        {
            return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
        }
#ifdef FIX_1495_INCORRECT_FREAD_CALL
        fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf );
#else    
        fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf );
#endif 
        v_tmp16 = (Word16 *) malloc( tmp * sizeof( Word16 ) );
        if ( v_tmp16 == NULL )
        {
@@ -731,7 +775,11 @@ static ivas_error TDREND_LoadBSplineBinary(
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
    }

#ifdef FIX_1495_INCORRECT_FREAD_CALL
    fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf );
#else    
    fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf );
#endif 
    fread( v_tmp16, sizeof( Word16 ), tmp, f_hrtf );
    for ( j = 0; j < tmp; j++ )
    {
@@ -750,7 +798,11 @@ static ivas_error TDREND_LoadBSplineBinary(
    {
        return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
    }
#ifdef FIX_1495_INCORRECT_FREAD_CALL
    fread( &factor_Q, sizeof( Word16 ), 1, f_hrtf );
#else    
    fread( &factor_Q, 1, sizeof( Word16 ), f_hrtf );
#endif 

    model->EL_e = Q31 - factor_Q;
    model->ER_e = model->EL_e;
@@ -1024,7 +1076,11 @@ static ivas_error TDREND_MIX_LoadHRTF(

        /* try if it is old format for BE tests*/
        fseek( f_hrtf, 0, SEEK_SET );
#ifdef FIX_1495_INCORRECT_FREAD_CALL
        if ( fread( &tmp, sizeof( Word16 ), 1, f_hrtf ) == 0 )
#else
        if ( fread( &tmp, 1, sizeof( Word16 ), f_hrtf ) == 0 )
#endif
        {
            header_check_result = IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "Error in HRTF file reading" );
        }
@@ -1096,7 +1152,11 @@ static ivas_error TDREND_MIX_LoadHRTF(

    if ( is_tdrend )
    {
#ifdef FIX_1495_INCORRECT_FREAD_CALL
        if ( fread( &tmp, sizeof( Word16 ), 1, f_hrtf ) == 0 )
#else
        if ( fread( &tmp, 1, sizeof( Word16 ), f_hrtf ) == 0 )
#endif
        {
            return IVAS_ERROR( IVAS_ERR_FAILED_FILE_READ, "Error in HRTF file reading" );
        }