From dfea7efef077b7029827f4ab58f2ccbcfb1022a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=BCller?= Date: Fri, 23 May 2025 15:27:29 +0200 Subject: [PATCH 01/17] Fix fread size/count argument order --- lib_util/mime_io.c | 2 +- lib_util/rtpdump.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_util/mime_io.c b/lib_util/mime_io.c index 9bdd20e453..9ca8ba1b83 100644 --- a/lib_util/mime_io.c +++ b/lib_util/mime_io.c @@ -317,7 +317,7 @@ static bool readByte( FILE *file, uint8_t *value ) static bool readLong( FILE *file, uint16_t *value ) { char buffer[4] = { 0 }; - if ( fread( buffer, 4, 1, file ) != 1U ) + if ( fread( buffer, 1, 4, file ) != 1U ) { return false; } diff --git a/lib_util/rtpdump.c b/lib_util/rtpdump.c index e3eb4c1f4a..9b25633a93 100644 --- a/lib_util/rtpdump.c +++ b/lib_util/rtpdump.c @@ -80,7 +80,7 @@ static unsigned char *parseByte( unsigned char *buffer, unsigned char *value ) static int readLong( FILE *file, unsigned int *value ) { char buffer[4] = { 0 }; - if ( fread( buffer, 4, 1, file ) != 1U ) + if ( fread( buffer, 1, 4, file ) != 1U ) { return -1; } @@ -96,7 +96,7 @@ static int readLong( FILE *file, unsigned int *value ) static int readShort( FILE *file, unsigned short *value ) { char buffer[2] = { 0 }; - if ( fread( buffer, 2, 1, file ) != 1U ) + if ( fread( buffer, 1, 2, file ) != 1U ) { return -1; } -- GitLab From 5bc8fff681bda08d06c5dbd615dff9cd9a499159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=BCller?= Date: Fri, 23 May 2025 15:31:11 +0200 Subject: [PATCH 02/17] Avoid the use of reserved names https://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html --- lib_util/g192.c | 8 ++++---- lib_util/g192.h | 4 ++-- lib_util/tinywavein_c.h | 4 ++-- lib_util/tinywaveout_c.h | 22 +++++++++++----------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib_util/g192.c b/lib_util/g192.c index f61971ef14..a45c673270 100644 --- a/lib_util/g192.c +++ b/lib_util/g192.c @@ -62,7 +62,7 @@ *-----------------------------------------------------------------------*/ /* main handle */ -struct __G192 +struct G192_STRUCT { FILE *file; int16_t ownFileHandle; /* flag whether FILE handle created by instance or externally */ @@ -79,12 +79,12 @@ G192_ERROR G192_Reader_Open_filename( const char *filename ) { /* create handle */ - *phG192 = (G192_HANDLE) calloc( 1, sizeof( struct __G192 ) ); + *phG192 = (G192_HANDLE) calloc( 1, sizeof( struct G192_STRUCT ) ); if ( !phG192 ) { return G192_MEMORY_ERROR; } - memset( *phG192, 0, sizeof( struct __G192 ) ); + memset( *phG192, 0, sizeof( struct G192_STRUCT ) ); /* open file stream */ ( *phG192 )->file = fopen( filename, "rb" ); @@ -422,7 +422,7 @@ G192_ERROR G192_Writer_Open_filename( const char *filename ) { /* create handle */ - *phG192 = (G192_HANDLE) calloc( 1, sizeof( struct __G192 ) ); + *phG192 = (G192_HANDLE) calloc( 1, sizeof( struct G192_STRUCT ) ); if ( !phG192 ) { return G192_MEMORY_ERROR; diff --git a/lib_util/g192.h b/lib_util/g192.h index 8014f52368..751f1324fb 100644 --- a/lib_util/g192.h +++ b/lib_util/g192.h @@ -67,8 +67,8 @@ typedef enum _G192_ERROR *-----------------------------------------------------------------------*/ /* main handle */ -struct __G192; -typedef struct __G192 *G192_HANDLE; +struct G192_STRUCT; +typedef struct G192_STRUCT *G192_HANDLE; /*-----------------------------------------------------------------------* diff --git a/lib_util/tinywavein_c.h b/lib_util/tinywavein_c.h index b86d97c964..1ff6f26bb7 100644 --- a/lib_util/tinywavein_c.h +++ b/lib_util/tinywavein_c.h @@ -54,14 +54,14 @@ #define __TWI_SUCCESS ( 0 ) #define __TWI_ERROR ( -1 ) -typedef struct __tinyWaveInHandle +typedef struct tinyWaveInHandle { FILE *theFile; fpos_t dataChunkPos; uint32_t position; uint32_t length; uint32_t bps; -} __tinyWaveInHandle, WAVEFILEIN; +} tinyWaveInHandle, WAVEFILEIN; typedef struct { diff --git a/lib_util/tinywaveout_c.h b/lib_util/tinywaveout_c.h index 693beccf95..a3982ba19c 100644 --- a/lib_util/tinywaveout_c.h +++ b/lib_util/tinywaveout_c.h @@ -70,15 +70,15 @@ #endif #endif -typedef struct __tinyWaveOutHeader +typedef struct tinyWaveOutHeader { uint32_t riffType; /* 'RIFF' */ uint32_t riffSize; /* file size */ uint32_t waveType; /* 'WAVE' */ -} __tinyWaveOutHeader; +} tinyWaveOutHeader; -typedef struct __tinyWaveOutFmtChunk +typedef struct tinyWaveOutFmtChunk { uint32_t formatType; uint32_t formatSize; @@ -91,16 +91,16 @@ typedef struct __tinyWaveOutFmtChunk uint16_t bitsPerSample; /* wav fmt ext hdr here */ -} __tinyWaveOutFmtChunk; +} tinyWaveOutFmtChunk; -typedef struct __tinyWaveOutDataChunk +typedef struct tinyWaveOutDataChunk { uint32_t dataType; uint32_t dataSize; -} __tinyWaveOutDataChunk; +} tinyWaveOutDataChunk; -typedef struct __tinyWaveOutHandle +typedef struct tinyWaveOutHandle { FILE *theFile; uint32_t dataSize; @@ -109,7 +109,7 @@ typedef struct __tinyWaveOutHandle uint32_t dataChunkOffset; uint32_t bps; uint32_t clipCount; -} __tinyWaveOutHandle, WAVEFILEOUT; +} tinyWaveOutHandle, WAVEFILEOUT; /*--- local protos --------------------------------------------------*/ static __inline uint32_t BigEndian32( char, char, char, char ); @@ -132,9 +132,9 @@ static WAVEFILEOUT *CreateBWF( /* ,const uint32_t writeWaveExt */ ) { WAVEFILEOUT *self; - __tinyWaveOutHeader whdr; - __tinyWaveOutFmtChunk wfch; - __tinyWaveOutDataChunk wdch; + tinyWaveOutHeader whdr; + tinyWaveOutFmtChunk wfch; + tinyWaveOutDataChunk wdch; uint32_t blockAlignment = 0; uint32_t ByteCnt = 0; /* Byte counter for fwrite */ -- GitLab From bcc1edc030a958a98b6cbbf8e9ad029f128c3e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=BCller?= Date: Fri, 23 May 2025 15:37:29 +0200 Subject: [PATCH 03/17] Improve readability of is_numeric_float Also fixes an implicit narrowing. --- lib_com/tools.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/lib_com/tools.c b/lib_com/tools.c index 024fe71c7a..0d770111f4 100644 --- a/lib_com/tools.c +++ b/lib_com/tools.c @@ -1742,19 +1742,9 @@ double anint( int16_t is_numeric_float( float x ) { -#ifndef BASOP_NOGLOB - union float_int -#else /* BASOP_NOGLOB */ - union float_int -#endif /* BASOP_NOGLOB */ - { - float float_val; - int32_t int_val; - } float_int; - - float_int.float_val = x; - - return ( ( float_int.int_val & 0x7f800000 ) != 0x7f800000 ); +#define WMC_TOOL_SKIP + return (int16_t) ( !isnan( x ) && !isinf( x ) ); +#undef WMC_TOOL_SKIP } /*-------------------------------------------------------------------* -- GitLab From fbfb6355bff78b580c64d3838a05c96e45d1fb31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=BCller?= Date: Fri, 23 May 2025 15:40:12 +0200 Subject: [PATCH 04/17] Remove redundant indexing and deref operator --- lib_rend/ivas_rom_rend.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib_rend/ivas_rom_rend.c b/lib_rend/ivas_rom_rend.c index bf6776ab04..87a9197f93 100644 --- a/lib_rend/ivas_rom_rend.c +++ b/lib_rend/ivas_rom_rend.c @@ -163,9 +163,9 @@ const float ap_lattice_coeffs_3[DIRAC_DECORR_FILTER_LEN_3*DIRAC_MAX_NUM_DECORR_F const float * const ap_lattice_coeffs[DIRAC_DECORR_NUM_SPLIT_BANDS] = { - &ap_lattice_coeffs_1[0], - &ap_lattice_coeffs_2[0], - &ap_lattice_coeffs_3[0], + ap_lattice_coeffs_1, + ap_lattice_coeffs_2, + ap_lattice_coeffs_3, }; const float ap_split_frequencies[DIRAC_DECORR_NUM_SPLIT_BANDS + 1] = -- GitLab From 8625b3d0903ee5391ecd0ac9ceeb746134979352 Mon Sep 17 00:00:00 2001 From: Kacper Sagnowski Date: Fri, 23 May 2025 17:19:58 +0200 Subject: [PATCH 05/17] Fix memory alignment warning in lib_rend --- lib_rend/lib_rend.c | 66 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 98b3177a15..f1d0a89dfe 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -3291,31 +3291,72 @@ static ivas_error getConstInputById( return IVAS_ERR_OK; } +static void *getInputByIndex( void *inputsArray, const size_t index, const IVAS_REND_AudioConfigType inputType ) +{ + switch ( inputType ) + { + case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED: + return (input_mc *) inputsArray + index; + case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS: + return (input_sba *) inputsArray + index; + case IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED: + return (input_ism *) inputsArray + index; + case IVAS_REND_AUDIO_CONFIG_TYPE_MASA: + return (input_masa *) inputsArray + index; + default: + break; + } + + /* this should be unreachable */ + assert( 0 ); + return NULL; +} + +/* Const variant of getInputByIndex. Unfortunately, this duplication is required to keep const-correctness. */ +static const void *getConstInputByIndex( const void *inputsArray, const size_t index, const IVAS_REND_AudioConfigType inputType ) +{ + switch ( inputType ) + { + case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED: + return (const input_mc *) inputsArray + index; + case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS: + return (const input_sba *) inputsArray + index; + case IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED: + return (const input_ism *) inputsArray + index; + case IVAS_REND_AUDIO_CONFIG_TYPE_MASA: + return (const input_masa *) inputsArray + index; + default: + break; + } + + /* this should be unreachable */ + assert( 0 ); + return NULL; +} static ivas_error findFreeInputSlot( const void *inputs, - const int32_t inputStructSize, + const IVAS_REND_AudioConfigType inputType, const int32_t maxInputs, int32_t *inputIndex ) { - /* Using a void pointer and a separately provided size is a hack for this function + /* Using a void pointer and a separately provided type is a hack for this function to be reusable for arrays of any input type (input_ism, input_mc, input_sba, input_masa). Assumptions: - input_base is always the first member in the input struct - - provided size is correct + - memory alignments of original input type and input_base are the same */ int32_t i; bool canAddInput; - const uint8_t *pByte; const input_base *pInputBase; canAddInput = false; /* Find first unused input in array */ - for ( i = 0, pByte = inputs; i < maxInputs; ++i, pByte += inputStructSize ) + for ( i = 0; i < maxInputs; ++i ) { - pInputBase = (const input_base *) pByte; + pInputBase = (const input_base *) getConstInputByIndex( inputs, i, inputType ); if ( pInputBase->inConfig == IVAS_AUDIO_CONFIG_INVALID ) { @@ -3457,7 +3498,7 @@ ivas_error IVAS_REND_AddInput( ivas_error error; int32_t maxNumInputsOfType; void *inputsArray; - int32_t inputStructSize; + IVAS_REND_AudioConfigType inputType; ivas_error ( *activateInput )( void *, AUDIO_CONFIG, IVAS_REND_InputId, RENDER_CONFIG_DATA *, hrtf_handles * ); int32_t inputIndex; @@ -3478,30 +3519,27 @@ ivas_error IVAS_REND_AddInput( } } - switch ( getAudioConfigType( inConfig ) ) + inputType = getAudioConfigType( inConfig ); + switch ( inputType ) { case IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED: maxNumInputsOfType = RENDERER_MAX_ISM_INPUTS; inputsArray = hIvasRend->inputsIsm; - inputStructSize = sizeof( *hIvasRend->inputsIsm ); activateInput = setRendInputActiveIsm; break; case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED: maxNumInputsOfType = RENDERER_MAX_MC_INPUTS; inputsArray = hIvasRend->inputsMc; - inputStructSize = sizeof( *hIvasRend->inputsMc ); activateInput = setRendInputActiveMc; break; case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS: maxNumInputsOfType = RENDERER_MAX_SBA_INPUTS; inputsArray = hIvasRend->inputsSba; - inputStructSize = sizeof( *hIvasRend->inputsSba ); activateInput = setRendInputActiveSba; break; case IVAS_REND_AUDIO_CONFIG_TYPE_MASA: maxNumInputsOfType = RENDERER_MAX_MASA_INPUTS; inputsArray = hIvasRend->inputsMasa; - inputStructSize = sizeof( *hIvasRend->inputsMasa ); activateInput = setRendInputActiveMasa; break; default: @@ -3509,13 +3547,13 @@ ivas_error IVAS_REND_AddInput( } /* Find first free input in array corresponding to input type */ - if ( ( error = findFreeInputSlot( inputsArray, inputStructSize, maxNumInputsOfType, &inputIndex ) ) != IVAS_ERR_OK ) + if ( ( error = findFreeInputSlot( inputsArray, inputType, maxNumInputsOfType, &inputIndex ) ) != IVAS_ERR_OK ) { return error; } *inputId = makeInputId( inConfig, inputIndex ); - if ( ( error = activateInput( (uint8_t *) inputsArray + inputStructSize * inputIndex, inConfig, *inputId, hIvasRend->hRendererConfig, &hIvasRend->hHrtfs ) ) != IVAS_ERR_OK ) + if ( ( error = activateInput( getInputByIndex( inputsArray, inputIndex, inputType ), inConfig, *inputId, hIvasRend->hRendererConfig, &hIvasRend->hHrtfs ) ) != IVAS_ERR_OK ) { return error; } -- GitLab From ef695613bb82ae743f2be51d0241d241090b4822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=BCller?= Date: Tue, 27 May 2025 11:54:45 +0200 Subject: [PATCH 06/17] Move unreachable code into switch-case --- lib_rend/lib_rend.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index f1d0a89dfe..978744a1c4 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -3304,12 +3304,10 @@ static void *getInputByIndex( void *inputsArray, const size_t index, const IVAS_ case IVAS_REND_AUDIO_CONFIG_TYPE_MASA: return (input_masa *) inputsArray + index; default: - break; + /* this should be unreachable */ + assert( 0 ); + return NULL; } - - /* this should be unreachable */ - assert( 0 ); - return NULL; } /* Const variant of getInputByIndex. Unfortunately, this duplication is required to keep const-correctness. */ @@ -3326,12 +3324,10 @@ static const void *getConstInputByIndex( const void *inputsArray, const size_t i case IVAS_REND_AUDIO_CONFIG_TYPE_MASA: return (const input_masa *) inputsArray + index; default: - break; + /* this should be unreachable */ + assert( 0 ); + return NULL; } - - /* this should be unreachable */ - assert( 0 ); - return NULL; } static ivas_error findFreeInputSlot( -- GitLab From 01e9e91c1faf926f34c86a13da2dcb5a62fbb0d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=BCller?= Date: Tue, 27 May 2025 16:54:46 +0200 Subject: [PATCH 07/17] Remove getConstInputByIndex again --- lib_rend/lib_rend.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 978744a1c4..4d8cc35d56 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -3310,28 +3310,8 @@ static void *getInputByIndex( void *inputsArray, const size_t index, const IVAS_ } } -/* Const variant of getInputByIndex. Unfortunately, this duplication is required to keep const-correctness. */ -static const void *getConstInputByIndex( const void *inputsArray, const size_t index, const IVAS_REND_AudioConfigType inputType ) -{ - switch ( inputType ) - { - case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED: - return (const input_mc *) inputsArray + index; - case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS: - return (const input_sba *) inputsArray + index; - case IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED: - return (const input_ism *) inputsArray + index; - case IVAS_REND_AUDIO_CONFIG_TYPE_MASA: - return (const input_masa *) inputsArray + index; - default: - /* this should be unreachable */ - assert( 0 ); - return NULL; - } -} - static ivas_error findFreeInputSlot( - const void *inputs, + void *inputs, const IVAS_REND_AudioConfigType inputType, const int32_t maxInputs, int32_t *inputIndex ) @@ -3352,7 +3332,7 @@ static ivas_error findFreeInputSlot( /* Find first unused input in array */ for ( i = 0; i < maxInputs; ++i ) { - pInputBase = (const input_base *) getConstInputByIndex( inputs, i, inputType ); + pInputBase = (const input_base *) getInputByIndex( inputs, i, inputType ); if ( pInputBase->inConfig == IVAS_AUDIO_CONFIG_INVALID ) { -- GitLab From 5dc8c9a80db014dc98193a9fadcaa1776c2ff908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=BCller?= Date: Mon, 2 Jun 2025 09:09:08 +0200 Subject: [PATCH 08/17] Fix code style --- lib_rend/lib_rend.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 4d8cc35d56..2ac0cad5ee 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -3291,7 +3291,10 @@ static ivas_error getConstInputById( return IVAS_ERR_OK; } -static void *getInputByIndex( void *inputsArray, const size_t index, const IVAS_REND_AudioConfigType inputType ) +static void *getInputByIndex( + void *inputsArray, + const size_t index, + const IVAS_REND_AudioConfigType inputType ) { switch ( inputType ) { -- GitLab From d248032cf684e79cb43500da7f1f7eb15d41b5d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=BCller?= Date: Tue, 3 Jun 2025 21:57:29 +0200 Subject: [PATCH 09/17] Add CODE_IMPROVEMENTS define --- lib_com/options.h | 1 + lib_com/tools.c | 16 +++++++++++ lib_rend/ivas_rom_rend.c | 6 +++++ lib_rend/lib_rend.c | 57 +++++++++++++++++++++++++++++++++++++++- lib_util/g192.h | 5 ++++ lib_util/mime_io.c | 4 +++ lib_util/rtpdump.c | 4 +++ lib_util/tinywavein_c.h | 8 ++++++ lib_util/tinywaveout_c.h | 39 ++++++++++++++++++++++++++- 9 files changed, 138 insertions(+), 2 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index aec5a9e672..2caa691dc5 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -154,6 +154,7 @@ /* ################## Start DEVELOPMENT switches ######################### */ +#define CODE_IMPROVEMENTS /* Small code improvements that do not change the functionality */ /* ################### Start BE switches ################################# */ /* only BE switches wrt selection floating point code */ diff --git a/lib_com/tools.c b/lib_com/tools.c index 0d770111f4..cb1d121629 100644 --- a/lib_com/tools.c +++ b/lib_com/tools.c @@ -1742,9 +1742,25 @@ double anint( int16_t is_numeric_float( float x ) { +#ifdef CODE_IMPROVEMENTS #define WMC_TOOL_SKIP return (int16_t) ( !isnan( x ) && !isinf( x ) ); #undef WMC_TOOL_SKIP +#else +#ifndef BASOP_NOGLOB + union float_int +#else /* BASOP_NOGLOB */ + union float_int +#endif /* BASOP_NOGLOB */ + { + float float_val; + int32_t int_val; + } float_int; + + float_int.float_val = x; + + return ( ( float_int.int_val & 0x7f800000 ) != 0x7f800000 ); +#endif } /*-------------------------------------------------------------------* diff --git a/lib_rend/ivas_rom_rend.c b/lib_rend/ivas_rom_rend.c index 87a9197f93..b14a5303a0 100644 --- a/lib_rend/ivas_rom_rend.c +++ b/lib_rend/ivas_rom_rend.c @@ -163,9 +163,15 @@ const float ap_lattice_coeffs_3[DIRAC_DECORR_FILTER_LEN_3*DIRAC_MAX_NUM_DECORR_F const float * const ap_lattice_coeffs[DIRAC_DECORR_NUM_SPLIT_BANDS] = { +#ifdef CODE_IMPROVEMENTS ap_lattice_coeffs_1, ap_lattice_coeffs_2, ap_lattice_coeffs_3, +#else + &ap_lattice_coeffs_1[0], + &ap_lattice_coeffs_2[0], + &ap_lattice_coeffs_3[0], +#endif }; const float ap_split_frequencies[DIRAC_DECORR_NUM_SPLIT_BANDS + 1] = diff --git a/lib_rend/lib_rend.c b/lib_rend/lib_rend.c index 2ac0cad5ee..0bcde62a65 100644 --- a/lib_rend/lib_rend.c +++ b/lib_rend/lib_rend.c @@ -3291,6 +3291,7 @@ static ivas_error getConstInputById( return IVAS_ERR_OK; } +#ifdef CODE_IMPROVEMENTS static void *getInputByIndex( void *inputsArray, const size_t index, @@ -3312,30 +3313,56 @@ static void *getInputByIndex( return NULL; } } +#endif static ivas_error findFreeInputSlot( +#ifdef CODE_IMPROVEMENTS void *inputs, const IVAS_REND_AudioConfigType inputType, +#else + const void *inputs, + const int32_t inputStructSize, +#endif const int32_t maxInputs, int32_t *inputIndex ) { +#ifdef CODE_IMPROVEMENTS /* Using a void pointer and a separately provided type is a hack for this function to be reusable for arrays of any input type (input_ism, input_mc, input_sba, input_masa). Assumptions: - input_base is always the first member in the input struct - memory alignments of original input type and input_base are the same */ +#else + /* Using a void pointer and a separately provided size is a hack for this function + to be reusable for arrays of any input type (input_ism, input_mc, input_sba, input_masa). + Assumptions: + - input_base is always the first member in the input struct + - provided size is correct + */ +#endif int32_t i; bool canAddInput; +#ifndef CODE_IMPROVEMENTS + const uint8_t *pByte; +#endif const input_base *pInputBase; canAddInput = false; /* Find first unused input in array */ +#ifdef CODE_IMPROVEMENTS for ( i = 0; i < maxInputs; ++i ) +#else + for ( i = 0, pByte = inputs; i < maxInputs; ++i, pByte += inputStructSize ) +#endif { +#ifdef CODE_IMPROVEMENTS pInputBase = (const input_base *) getInputByIndex( inputs, i, inputType ); +#else + pInputBase = (const input_base *) pByte; +#endif if ( pInputBase->inConfig == IVAS_AUDIO_CONFIG_INVALID ) { @@ -3477,7 +3504,11 @@ ivas_error IVAS_REND_AddInput( ivas_error error; int32_t maxNumInputsOfType; void *inputsArray; +#ifdef CODE_IMPROVEMENTS IVAS_REND_AudioConfigType inputType; +#else + int32_t inputStructSize; +#endif ivas_error ( *activateInput )( void *, AUDIO_CONFIG, IVAS_REND_InputId, RENDER_CONFIG_DATA *, hrtf_handles * ); int32_t inputIndex; @@ -3498,41 +3529,65 @@ ivas_error IVAS_REND_AddInput( } } +#ifdef CODE_IMPROVEMENTS inputType = getAudioConfigType( inConfig ); switch ( inputType ) +#else + switch ( getAudioConfigType( inConfig ) ) +#endif { case IVAS_REND_AUDIO_CONFIG_TYPE_OBJECT_BASED: maxNumInputsOfType = RENDERER_MAX_ISM_INPUTS; inputsArray = hIvasRend->inputsIsm; +#ifndef CODE_IMPROVEMENTS + inputStructSize = sizeof( *hIvasRend->inputsIsm ); +#endif activateInput = setRendInputActiveIsm; break; case IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED: maxNumInputsOfType = RENDERER_MAX_MC_INPUTS; inputsArray = hIvasRend->inputsMc; +#ifndef CODE_IMPROVEMENTS + inputStructSize = sizeof( *hIvasRend->inputsMc ); +#endif activateInput = setRendInputActiveMc; break; case IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS: maxNumInputsOfType = RENDERER_MAX_SBA_INPUTS; inputsArray = hIvasRend->inputsSba; +#ifndef CODE_IMPROVEMENTS + inputStructSize = sizeof( *hIvasRend->inputsSba ); +#endif activateInput = setRendInputActiveSba; break; case IVAS_REND_AUDIO_CONFIG_TYPE_MASA: maxNumInputsOfType = RENDERER_MAX_MASA_INPUTS; inputsArray = hIvasRend->inputsMasa; +#ifndef CODE_IMPROVEMENTS + inputStructSize = sizeof( *hIvasRend->inputsMasa ); +#endif activateInput = setRendInputActiveMasa; break; default: return IVAS_ERR_INVALID_INPUT_FORMAT; } - /* Find first free input in array corresponding to input type */ + /* Find first free input in array corresponding to input type */ +#ifdef CODE_IMPROVEMENTS if ( ( error = findFreeInputSlot( inputsArray, inputType, maxNumInputsOfType, &inputIndex ) ) != IVAS_ERR_OK ) +#else + if ( ( error = findFreeInputSlot( inputsArray, inputStructSize, maxNumInputsOfType, &inputIndex ) ) != IVAS_ERR_OK ) +#endif { return error; } *inputId = makeInputId( inConfig, inputIndex ); +#ifdef CODE_IMPROVEMENTS if ( ( error = activateInput( getInputByIndex( inputsArray, inputIndex, inputType ), inConfig, *inputId, hIvasRend->hRendererConfig, &hIvasRend->hHrtfs ) ) != IVAS_ERR_OK ) +#else + if ( ( error = activateInput( (uint8_t *) inputsArray + inputStructSize * inputIndex, inConfig, *inputId, hIvasRend->hRendererConfig, &hIvasRend->hHrtfs ) ) != IVAS_ERR_OK ) +#endif { return error; } diff --git a/lib_util/g192.h b/lib_util/g192.h index 751f1324fb..f94c69f0da 100644 --- a/lib_util/g192.h +++ b/lib_util/g192.h @@ -67,8 +67,13 @@ typedef enum _G192_ERROR *-----------------------------------------------------------------------*/ /* main handle */ +#ifdef CODE_IMPROVEMENTS struct G192_STRUCT; typedef struct G192_STRUCT *G192_HANDLE; +#else +struct __G192; +typedef struct __G192 *G192_HANDLE; +#endif /*-----------------------------------------------------------------------* diff --git a/lib_util/mime_io.c b/lib_util/mime_io.c index 9ca8ba1b83..ee2a9c12a5 100644 --- a/lib_util/mime_io.c +++ b/lib_util/mime_io.c @@ -317,7 +317,11 @@ static bool readByte( FILE *file, uint8_t *value ) static bool readLong( FILE *file, uint16_t *value ) { char buffer[4] = { 0 }; +#ifdef CODE_IMPROVEMENTS if ( fread( buffer, 1, 4, file ) != 1U ) +#else + if ( fread( buffer, 4, 1, file ) != 1U ) +#endif { return false; } diff --git a/lib_util/rtpdump.c b/lib_util/rtpdump.c index 9b25633a93..ac143bb8f6 100644 --- a/lib_util/rtpdump.c +++ b/lib_util/rtpdump.c @@ -80,7 +80,11 @@ static unsigned char *parseByte( unsigned char *buffer, unsigned char *value ) static int readLong( FILE *file, unsigned int *value ) { char buffer[4] = { 0 }; +#ifdef CODE_IMPROVEMENTS if ( fread( buffer, 1, 4, file ) != 1U ) +#else + if ( fread( buffer, 4, 1, file ) != 1U ) +#endif { return -1; } diff --git a/lib_util/tinywavein_c.h b/lib_util/tinywavein_c.h index 1ff6f26bb7..179c676a81 100644 --- a/lib_util/tinywavein_c.h +++ b/lib_util/tinywavein_c.h @@ -54,14 +54,22 @@ #define __TWI_SUCCESS ( 0 ) #define __TWI_ERROR ( -1 ) +#ifdef CODE_IMPROVEMENTS typedef struct tinyWaveInHandle +#else +typedef struct __tinyWaveInHandle +#endif { FILE *theFile; fpos_t dataChunkPos; uint32_t position; uint32_t length; uint32_t bps; +#ifdef CODE_IMPROVEMENTS } tinyWaveInHandle, WAVEFILEIN; +#else +} __tinyWaveInHandle, WAVEFILEIN; +#endif typedef struct { diff --git a/lib_util/tinywaveout_c.h b/lib_util/tinywaveout_c.h index a3982ba19c..a511b932dd 100644 --- a/lib_util/tinywaveout_c.h +++ b/lib_util/tinywaveout_c.h @@ -70,15 +70,27 @@ #endif #endif +#ifdef CODE_IMPROVEMENTS typedef struct tinyWaveOutHeader +#else +typedef struct __tinyWaveOutHeader +#endif { uint32_t riffType; /* 'RIFF' */ uint32_t riffSize; /* file size */ uint32_t waveType; /* 'WAVE' */ +#ifdef CODE_IMPROVEMENTS } tinyWaveOutHeader; +#else +} __tinyWaveOutHeader; +#endif +#ifdef CODE_IMPROVEMENTS typedef struct tinyWaveOutFmtChunk +#else +typedef struct __tinyWaveOutFmtChunk +#endif { uint32_t formatType; uint32_t formatSize; @@ -91,16 +103,31 @@ typedef struct tinyWaveOutFmtChunk uint16_t bitsPerSample; /* wav fmt ext hdr here */ +#ifdef CODE_IMPROVEMENTS } tinyWaveOutFmtChunk; +#else +} tinyWaveOutFmtChunk; +#endif +#ifdef CODE_IMPROVEMENTS +typedef struct tinyWaveOutDataChunk +#else typedef struct tinyWaveOutDataChunk +#endif { uint32_t dataType; uint32_t dataSize; - +#ifdef CODE_IMPROVEMENTS } tinyWaveOutDataChunk; +#else +} __tinyWaveOutDataChunk; +#endif +#ifdef CODE_IMPROVEMENTS +typedef struct tinyWaveOutHandle +#else typedef struct tinyWaveOutHandle +#endif { FILE *theFile; uint32_t dataSize; @@ -109,7 +136,11 @@ typedef struct tinyWaveOutHandle uint32_t dataChunkOffset; uint32_t bps; uint32_t clipCount; +#ifdef CODE_IMPROVEMENTS } tinyWaveOutHandle, WAVEFILEOUT; +#else +} __tinyWaveOutHandle, WAVEFILEOUT; +#endif /*--- local protos --------------------------------------------------*/ static __inline uint32_t BigEndian32( char, char, char, char ); @@ -132,9 +163,15 @@ static WAVEFILEOUT *CreateBWF( /* ,const uint32_t writeWaveExt */ ) { WAVEFILEOUT *self; +#ifdef CODE_IMPROVEMENTS tinyWaveOutHeader whdr; tinyWaveOutFmtChunk wfch; tinyWaveOutDataChunk wdch; +#else + __tinyWaveOutHeader whdr; + __tinyWaveOutFmtChunk wfch; + __tinyWaveOutDataChunk wdch; +#endif uint32_t blockAlignment = 0; uint32_t ByteCnt = 0; /* Byte counter for fwrite */ -- GitLab From e01c21c621abf3e4c87910a175e396258895c7a1 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 11 Jun 2025 15:43:38 +0200 Subject: [PATCH 10/17] fix build with the switch CODE_IMPROVEMENTS deactivated --- lib_com/options.h | 4 ++-- lib_util/g192.h | 5 ----- lib_util/tinywaveout_c.h | 4 ++-- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 2caa691dc5..dc9793ef16 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -154,8 +154,6 @@ /* ################## Start DEVELOPMENT switches ######################### */ -#define CODE_IMPROVEMENTS /* Small code improvements that do not change the functionality */ - /* ################### Start BE switches ################################# */ /* only BE switches wrt selection floating point code */ @@ -167,6 +165,8 @@ #define FIX_RENDERER_STACK /* VA: issue 1322: reduction of renderers' buffers size */ #define FIX_1319_STACK_SBA_DECODER /* VA: issue 1319: Optimize the definition of buffer lengths in the SBA decoder */ #define JBM_MEMORY_OPT /* VA: issue 916: optimization of RAM in the JBM decoder */ +#define CODE_IMPROVEMENTS /* FhG: Small code improvements that do not change the functionality */ + /* #################### End BE switches ################################## */ diff --git a/lib_util/g192.h b/lib_util/g192.h index f94c69f0da..751f1324fb 100644 --- a/lib_util/g192.h +++ b/lib_util/g192.h @@ -67,13 +67,8 @@ typedef enum _G192_ERROR *-----------------------------------------------------------------------*/ /* main handle */ -#ifdef CODE_IMPROVEMENTS struct G192_STRUCT; typedef struct G192_STRUCT *G192_HANDLE; -#else -struct __G192; -typedef struct __G192 *G192_HANDLE; -#endif /*-----------------------------------------------------------------------* diff --git a/lib_util/tinywaveout_c.h b/lib_util/tinywaveout_c.h index a511b932dd..e7d568dc83 100644 --- a/lib_util/tinywaveout_c.h +++ b/lib_util/tinywaveout_c.h @@ -106,7 +106,7 @@ typedef struct __tinyWaveOutFmtChunk #ifdef CODE_IMPROVEMENTS } tinyWaveOutFmtChunk; #else -} tinyWaveOutFmtChunk; +} __tinyWaveOutFmtChunk; #endif #ifdef CODE_IMPROVEMENTS @@ -126,7 +126,7 @@ typedef struct tinyWaveOutDataChunk #ifdef CODE_IMPROVEMENTS typedef struct tinyWaveOutHandle #else -typedef struct tinyWaveOutHandle +typedef struct __tinyWaveOutHandle #endif { FILE *theFile; -- GitLab From d54146405f21698695c91e19633f37ab73854514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=BCller?= Date: Wed, 11 Jun 2025 17:19:02 +0200 Subject: [PATCH 11/17] Fix calloc argument order --- lib_debug/debug.c | 2 +- lib_lc3plus/dct4.c | 4 ++-- lib_lc3plus/mdct.c | 2 +- lib_util/aeid_file_reader.c | 4 ++-- lib_util/audio_file_reader.c | 2 +- lib_util/audio_file_writer.c | 2 +- lib_util/hrtf_file_reader.c | 4 ++-- lib_util/ism_file_reader.c | 4 ++-- lib_util/ism_file_writer.c | 4 ++-- lib_util/jbm_file_reader.c | 4 ++-- lib_util/jbm_file_writer.c | 8 ++++---- lib_util/ls_custom_file_reader.c | 4 ++-- lib_util/masa_file_reader.c | 2 +- lib_util/masa_file_writer.c | 6 +++--- lib_util/obj_edit_file_reader.c | 6 +++--- lib_util/render_config_reader.c | 2 +- lib_util/rotation_file_reader.c | 4 ++-- lib_util/split_rend_bfi_file_reader.c | 4 ++-- lib_util/tsm_scale_file_reader.c | 4 ++-- lib_util/vector3_pair_file_reader.c | 4 ++-- 20 files changed, 38 insertions(+), 38 deletions(-) diff --git a/lib_debug/debug.c b/lib_debug/debug.c index 6336e911fc..012183c5ac 100644 --- a/lib_debug/debug.c +++ b/lib_debug/debug.c @@ -820,7 +820,7 @@ int16_t make_dirs( const char *const pathname ) if ( sep != 0 ) { - temp = calloc( 1, strlen( pathname ) + 1 ); + temp = calloc( strlen( pathname ) + 1, sizeof( char ) ); p = pathname; while ( ( p = strchr( p, sep ) ) != NULL ) { diff --git a/lib_lc3plus/dct4.c b/lib_lc3plus/dct4.c index 4b4a3f6a0f..d45687ffa7 100644 --- a/lib_lc3plus/dct4.c +++ b/lib_lc3plus/dct4.c @@ -52,8 +52,8 @@ void dct4_init(Dct4* dct, int length) int i; assert(length <= MAX_LEN); dct->length = length; - dct->twid1 = calloc(sizeof(*dct->twid1), length / 2); - dct->twid2 = calloc(sizeof(*dct->twid2), length / 2); + dct->twid1 = calloc(length / 2, sizeof(*dct->twid1)); + dct->twid2 = calloc(length / 2, sizeof(*dct->twid2)); for (i = 0; i < length / 2; i++) { dct->twid1[i] = cexpi(-(LC3_FLOAT)M_PI_LC3PLUS * (i + (LC3_FLOAT)0.25) / length); dct->twid2[i] = cexpi(-(LC3_FLOAT)M_PI_LC3PLUS * i / length); diff --git a/lib_lc3plus/mdct.c b/lib_lc3plus/mdct.c index 4698afd4bf..0e41b4f745 100644 --- a/lib_lc3plus/mdct.c +++ b/lib_lc3plus/mdct.c @@ -109,7 +109,7 @@ void mdct_init(Mdct* mdct, LC3_INT length, LC3_INT frame_dms, LC3_INT fs_idx, LC mdct->length = length; mdct->mem_length = length - mdct->leading_zeros; mdct->window = mdct_window(length, frame_dms, hrmode); - mdct->mem = calloc(sizeof(*mdct->mem), mdct->mem_length); + mdct->mem = calloc(mdct->mem_length, sizeof(*mdct->mem)); dct4_init(&mdct->dct, length); } diff --git a/lib_util/aeid_file_reader.c b/lib_util/aeid_file_reader.c index e569dbdc7c..6f877452e5 100644 --- a/lib_util/aeid_file_reader.c +++ b/lib_util/aeid_file_reader.c @@ -69,9 +69,9 @@ ivas_error aeidFileReader_open( return IVAS_ERR_FAILED_FILE_OPEN; } - self = calloc( sizeof( aeidFileReader ), 1 ); + self = calloc( 1, sizeof( aeidFileReader ) ); self->aeidFile = aeidFile; - self->file_path = calloc( sizeof( char ), strlen( aeidFilePath ) + 1 ); + self->file_path = calloc( strlen( aeidFilePath ) + 1, sizeof( char ) ); strcpy( self->file_path, aeidFilePath ); *aeidReader = self; diff --git a/lib_util/audio_file_reader.c b/lib_util/audio_file_reader.c index 1b52daaa77..92bfe89789 100644 --- a/lib_util/audio_file_reader.c +++ b/lib_util/audio_file_reader.c @@ -94,7 +94,7 @@ ivas_error AudioFileReader_open( { return IVAS_ERR_FAILED_FILE_OPEN; } - self = calloc( sizeof( AudioFileReader ), 1 ); + self = calloc( 1, sizeof( AudioFileReader ) ); self->samplingRate = 0; self->numChannels = 0; diff --git a/lib_util/audio_file_writer.c b/lib_util/audio_file_writer.c index 3210631019..eb93018341 100644 --- a/lib_util/audio_file_writer.c +++ b/lib_util/audio_file_writer.c @@ -89,7 +89,7 @@ ivas_error AudioFileWriter_open( return IVAS_ERR_FAILED_FILE_OPEN; } - self = calloc( sizeof( AudioFileWriter ), 1 ); + self = calloc( 1, sizeof( AudioFileWriter ) ); if ( self == NULL ) { return IVAS_ERR_FAILED_ALLOC; diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 53a5d340e1..3347a0c9ab 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -83,9 +83,9 @@ ivas_error hrtfFileReader_open( return IVAS_ERR_FAILED_FILE_OPEN; } - self = calloc( sizeof( hrtfFileReader ), 1 ); + self = calloc( 1, sizeof( hrtfFileReader ) ); self->file = file; - self->file_path = calloc( sizeof( char ), strlen( filePath ) + 1 ); + self->file_path = calloc( strlen( filePath ) + 1, sizeof( char ) ); strcpy( self->file_path, filePath ); *hrtfReader = self; diff --git a/lib_util/ism_file_reader.c b/lib_util/ism_file_reader.c index 088a4134f9..83a32b7a01 100644 --- a/lib_util/ism_file_reader.c +++ b/lib_util/ism_file_reader.c @@ -72,9 +72,9 @@ IsmFileReader *IsmFileReader_open( return NULL; } - self = calloc( sizeof( IsmFileReader ), 1 ); + self = calloc( 1, sizeof( IsmFileReader ) ); self->file = file; - self->file_path = calloc( sizeof( char ), strlen( filePath ) + 1 ); + self->file_path = calloc( strlen( filePath ) + 1, sizeof( char ) ); strcpy( self->file_path, filePath ); return self; diff --git a/lib_util/ism_file_writer.c b/lib_util/ism_file_writer.c index fff4cc4ff0..10efc1ea3d 100644 --- a/lib_util/ism_file_writer.c +++ b/lib_util/ism_file_writer.c @@ -81,9 +81,9 @@ ivas_error IsmFileWriter_open( return IVAS_ERR_FAILED_FILE_OPEN; } - self = calloc( sizeof( IsmFileWriter ), 1 ); + self = calloc( 1, sizeof( IsmFileWriter ) ); self->file = file; - self->file_path = calloc( sizeof( char ), strlen( filePath ) + 1 ); + self->file_path = calloc( strlen( filePath ) + 1, sizeof( char ) ); strcpy( self->file_path, filePath ); *ismWriter = self; diff --git a/lib_util/jbm_file_reader.c b/lib_util/jbm_file_reader.c index b657ab7892..68caf5ae73 100644 --- a/lib_util/jbm_file_reader.c +++ b/lib_util/jbm_file_reader.c @@ -68,9 +68,9 @@ JbmFileReader *JbmFileReader_open( return NULL; } - self = calloc( sizeof( JbmFileReader ), 1 ); + self = calloc( 1, sizeof( JbmFileReader ) ); self->file = file; - self->file_path = calloc( sizeof( char ), strlen( filePath ) + 1 ); + self->file_path = calloc( strlen( filePath ) + 1, sizeof( char ) ); strcpy( self->file_path, filePath ); return self; diff --git a/lib_util/jbm_file_writer.c b/lib_util/jbm_file_writer.c index 76a5a67d25..9d11dad904 100644 --- a/lib_util/jbm_file_writer.c +++ b/lib_util/jbm_file_writer.c @@ -77,9 +77,9 @@ ivas_error JbmOffsetFileWriter_open( return IVAS_ERR_FAILED_FILE_OPEN; } - self = calloc( sizeof( JbmOffsetFileWriter ), 1 ); + self = calloc( 1, sizeof( JbmOffsetFileWriter ) ); self->file = file; - self->file_path = calloc( sizeof( char ), strlen( jbmOffsetFilename ) + 1 ); + self->file_path = calloc( strlen( jbmOffsetFilename ) + 1, sizeof( char ) ); strcpy( self->file_path, jbmOffsetFilename ); *jbmOffsetWriter = self; @@ -204,9 +204,9 @@ ivas_error JbmTraceFileWriter_open( fprintf( file, "#rtpSeqNo;rtpTs;rcvTime;playTime;active\n" ); - self = calloc( sizeof( JbmTraceFileWriter ), 1 ); + self = calloc( 1, sizeof( JbmTraceFileWriter ) ); self->file = file; - self->file_path = calloc( sizeof( char ), strlen( jbmTraceFilename ) + 1 ); + self->file_path = calloc( strlen( jbmTraceFilename ) + 1, sizeof( char ) ); strcpy( self->file_path, jbmTraceFilename ); *jbmTraceWriter = self; diff --git a/lib_util/ls_custom_file_reader.c b/lib_util/ls_custom_file_reader.c index 48c87a88ea..43c9959e68 100644 --- a/lib_util/ls_custom_file_reader.c +++ b/lib_util/ls_custom_file_reader.c @@ -70,9 +70,9 @@ ivas_error CustomLsReader_open( return IVAS_ERR_FAILED_FILE_OPEN; } - self = calloc( sizeof( LsCustomFileReader ), 1 ); + self = calloc( 1, sizeof( LsCustomFileReader ) ); self->file = lsFile; - self->file_path = calloc( sizeof( char ), strlen( LsFilePath ) + 1 ); + self->file_path = calloc( strlen( LsFilePath ) + 1, sizeof( char ) ); strcpy( self->file_path, LsFilePath ); *hLsCustomReader = self; diff --git a/lib_util/masa_file_reader.c b/lib_util/masa_file_reader.c index 2cb76f96e6..1122878f8a 100644 --- a/lib_util/masa_file_reader.c +++ b/lib_util/masa_file_reader.c @@ -70,7 +70,7 @@ MasaFileReader *MasaFileReader_open( return NULL; } - self = calloc( sizeof( MasaFileReader ), 1 ); + self = calloc( 1, sizeof( MasaFileReader ) ); self->file = file; generate_gridEq( &self->sph_grid16 ); diff --git a/lib_util/masa_file_writer.c b/lib_util/masa_file_writer.c index 8cac01ff5a..3f269a6871 100644 --- a/lib_util/masa_file_writer.c +++ b/lib_util/masa_file_writer.c @@ -212,14 +212,14 @@ ivas_error MasaFileWriter_open( return IVAS_ERR_FAILED_FILE_OPEN; } - self = calloc( sizeof( MasaFileWriter ), 1 ); + self = calloc( 1, sizeof( MasaFileWriter ) ); self->file = file; - self->file_path = calloc( sizeof( char ), strlen( filePath ) + 1 ); + self->file_path = calloc( strlen( filePath ) + 1, sizeof( char ) ); strcpy( self->file_path, filePath ); if ( !delayCompensationEnabled ) { - self->delayStorage = calloc( sizeof( MASA_META_DELAY_STORAGE ), 1 ); + self->delayStorage = calloc( 1, sizeof( MASA_META_DELAY_STORAGE ) ); self->delayStorage->prevDelay = DELAY_MASA_PARAM_DEC_SFR; } diff --git a/lib_util/obj_edit_file_reader.c b/lib_util/obj_edit_file_reader.c index 9963e722ba..2dde08ecc3 100644 --- a/lib_util/obj_edit_file_reader.c +++ b/lib_util/obj_edit_file_reader.c @@ -76,13 +76,13 @@ ivas_error ObjectEditFileReader_open( return IVAS_ERR_FAILED_FILE_OPEN; } - self = (ObjectEditFileReader *) calloc( sizeof( ObjectEditFileReader ), 1 ); + self = (ObjectEditFileReader *) calloc( 1, sizeof( ObjectEditFileReader ) ); self->maxLineLen = 256; self->editFileHandle = fileHandle; - self->inLine = (char *) calloc( sizeof( char ), self->maxLineLen ); + self->inLine = (char *) calloc( self->maxLineLen, sizeof( char ) ); - self->readInfo = (ReadObjectEditInfo *) calloc( sizeof( ReadObjectEditInfo ), 1 ); + self->readInfo = (ReadObjectEditInfo *) calloc( 1, sizeof( ReadObjectEditInfo ) ); self->readInfo->bg_gain = 0.0f; self->readInfo->bg_gain_edited = false; diff --git a/lib_util/render_config_reader.c b/lib_util/render_config_reader.c index dd3e84ac87..7729efbc7c 100644 --- a/lib_util/render_config_reader.c +++ b/lib_util/render_config_reader.c @@ -1398,7 +1398,7 @@ ivas_error RenderConfigReader_open( return IVAS_ERR_FAILED_FILE_OPEN; } - pSelf = calloc( sizeof( RenderConfigReader ), 1 ); + pSelf = calloc( 1, sizeof( RenderConfigReader ) ); pSelf->pConfigFile = pConfigFile; pSelf->nFG = 0; pSelf->pFG = NULL; diff --git a/lib_util/rotation_file_reader.c b/lib_util/rotation_file_reader.c index f659fbb9fa..024b083737 100644 --- a/lib_util/rotation_file_reader.c +++ b/lib_util/rotation_file_reader.c @@ -72,10 +72,10 @@ ivas_error RotationFileReader_open( return IVAS_ERR_FAILED_FILE_OPEN; } - self = calloc( sizeof( RotFileReader ), 1 ); + self = calloc( 1, sizeof( RotFileReader ) ); self->trajFile = trajFile; self->frameCounter = 0; - self->file_path = calloc( sizeof( char ), strlen( trajFilePath ) + 1 ); + self->file_path = calloc( strlen( trajFilePath ) + 1, sizeof( char ) ); strcpy( self->file_path, trajFilePath ); self->fileRewind = false; diff --git a/lib_util/split_rend_bfi_file_reader.c b/lib_util/split_rend_bfi_file_reader.c index 70e695048e..07b71e2219 100644 --- a/lib_util/split_rend_bfi_file_reader.c +++ b/lib_util/split_rend_bfi_file_reader.c @@ -76,10 +76,10 @@ ivas_error SplitRendBFIFileReader_open( txtfile = ( strcmp( bfiFilePath + strlen( bfiFilePath ) - 4, ".txt" ) ? false : true ); - self = calloc( sizeof( SplitRendBFIFileReader ), 1 ); + self = calloc( 1, sizeof( SplitRendBFIFileReader ) ); self->bfiFile = bfiFile; self->frameCounter = 0; - self->file_path = calloc( sizeof( char ), strlen( bfiFilePath ) + 1 ); + self->file_path = calloc( strlen( bfiFilePath ) + 1, sizeof( char ) ); strcpy( self->file_path, bfiFilePath ); self->fileRewind = false; self->txtfile = txtfile; diff --git a/lib_util/tsm_scale_file_reader.c b/lib_util/tsm_scale_file_reader.c index 653fc0f2f6..65182061e2 100644 --- a/lib_util/tsm_scale_file_reader.c +++ b/lib_util/tsm_scale_file_reader.c @@ -73,9 +73,9 @@ TsmScaleFileReader *TsmScaleFileReader_open( return NULL; } - self = calloc( sizeof( TsmScaleFileReader ), 1 ); + self = calloc( 1, sizeof( TsmScaleFileReader ) ); self->file = file; - self->file_path = calloc( sizeof( char ), strlen( filePath ) + 1 ); + self->file_path = calloc( strlen( filePath ) + 1, sizeof( char ) ); strcpy( self->file_path, filePath ); return self; diff --git a/lib_util/vector3_pair_file_reader.c b/lib_util/vector3_pair_file_reader.c index 8a46a97d1d..5f6116c747 100644 --- a/lib_util/vector3_pair_file_reader.c +++ b/lib_util/vector3_pair_file_reader.c @@ -68,9 +68,9 @@ ivas_error Vector3PairFileReader_open( return IVAS_ERR_FAILED_FILE_OPEN; } - self = calloc( sizeof( Vector3PairFileReader ), 1 ); + self = calloc( 1, sizeof( Vector3PairFileReader ) ); self->trajFile = trajFile; - self->file_path = calloc( sizeof( char ), strlen( trajFilePath ) + 1 ); + self->file_path = calloc( strlen( trajFilePath ) + 1, sizeof( char ) ); strcpy( self->file_path, trajFilePath ); *vector3PairReader = self; -- GitLab From 083de2781953d7c072ba517540de632b805ba334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=BCller?= Date: Wed, 11 Jun 2025 17:27:38 +0200 Subject: [PATCH 12/17] Replace malloc/memset(0) with calloc --- apps/decoder.c | 3 +-- lib_util/bitstream_reader.c | 7 +++---- lib_util/bitstream_writer.c | 7 +++---- lib_util/g192.c | 1 - 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 6a1d823f76..d4f5989373 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1858,13 +1858,12 @@ static ivas_error initOnFirstGoodFrame( return error; } - int16_t *zeroBuf = malloc( pcmFrameSize * sizeof( int16_t ) ); + int16_t *zeroBuf = calloc( pcmFrameSize, sizeof( int16_t ) ); if ( zeroBuf == NULL ) { fprintf( stdout, "Error: Unable to allocate memory for output buffer.\n" ); return IVAS_ERR_FAILED_ALLOC; } - memset( zeroBuf, 0, pcmFrameSize * sizeof( int16_t ) ); for ( int16_t i = 0; i < numInitialBadFrames; ++i ) { diff --git a/lib_util/bitstream_reader.c b/lib_util/bitstream_reader.c index a250a34a70..c6fe784fbd 100644 --- a/lib_util/bitstream_reader.c +++ b/lib_util/bitstream_reader.c @@ -203,16 +203,15 @@ static void init_for_mime( BS_READER_HANDLE hBsReader ) static ivas_error init_for_format( BS_READER_HANDLE *phBsReader, BS_READER_FORMAT format ) { /* Allocate memory under handle and check if allocation successful */ - ( *phBsReader ) = (BS_READER_HANDLE) malloc( sizeof( struct BS_Reader ) ); + /* Initialize all struct members to NULL - supported functions + * will be overwritten below in init_for_ */ + ( *phBsReader ) = (BS_READER_HANDLE) calloc( 1, sizeof( struct BS_Reader ) ); if ( *phBsReader == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "could not allocate bitstream reader" ); } - /* Initialize all struct members to NULL - supported functions - * will be overwritten below in init_for_ */ BS_READER_HANDLE hBsReader = *phBsReader; - memset( hBsReader, 0, sizeof( struct BS_Reader ) ); /* Set function pointers to selected format */ switch ( format ) diff --git a/lib_util/bitstream_writer.c b/lib_util/bitstream_writer.c index 8c4b64cd48..bff9f461b1 100644 --- a/lib_util/bitstream_writer.c +++ b/lib_util/bitstream_writer.c @@ -156,16 +156,15 @@ static void init_for_mime( BS_WRITER_HANDLE hBsWriter ) static ivas_error init_for_format( BS_WRITER_HANDLE *phBsWriter, BS_WRITER_FORMAT format ) { /* Allocate memory under handle and check if allocation successful */ - ( *phBsWriter ) = (BS_WRITER_HANDLE) malloc( sizeof( struct BS_Writer ) ); + /* Initialize all struct members to NULL - supported functions + * will be overwritten below in init_for_ */ + ( *phBsWriter ) = (BS_WRITER_HANDLE) calloc( 1, sizeof( struct BS_Writer ) ); if ( *phBsWriter == NULL ) { IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "could not allocate bitstream writer" ); } - /* Initialize all struct members to NULL - supported functions - * will be overwritten below in init_for_ */ BS_WRITER_HANDLE hBsWriter = *phBsWriter; - memset( hBsWriter, 0, sizeof( struct BS_Writer ) ); /* Set function pointers to selected format */ switch ( format ) diff --git a/lib_util/g192.c b/lib_util/g192.c index a45c673270..a96a8ee56d 100644 --- a/lib_util/g192.c +++ b/lib_util/g192.c @@ -84,7 +84,6 @@ G192_ERROR G192_Reader_Open_filename( { return G192_MEMORY_ERROR; } - memset( *phG192, 0, sizeof( struct G192_STRUCT ) ); /* open file stream */ ( *phG192 )->file = fopen( filename, "rb" ); -- GitLab From cee4a2ad25fcb3225e46af9e68d42e9904c8d20c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=BCller?= Date: Tue, 1 Jul 2025 11:23:31 +0200 Subject: [PATCH 13/17] Fix calloc argument order --- lib_debug/debug.c | 2 +- lib_util/aeid_file_reader.c | 4 ++-- lib_util/audio_file_reader.c | 2 +- lib_util/audio_file_writer.c | 2 +- lib_util/hrtf_file_reader.c | 4 ++-- lib_util/ism_file_reader.c | 4 ++-- lib_util/ism_file_writer.c | 4 ++-- lib_util/jbm_file_reader.c | 4 ++-- lib_util/jbm_file_writer.c | 8 ++++---- lib_util/ls_custom_file_reader.c | 4 ++-- lib_util/masa_file_reader.c | 2 +- lib_util/masa_file_writer.c | 6 +++--- lib_util/obj_edit_file_reader.c | 6 +++--- lib_util/render_config_reader.c | 2 +- lib_util/rotation_file_reader.c | 4 ++-- lib_util/split_rend_bfi_file_reader.c | 4 ++-- lib_util/tsm_scale_file_reader.c | 4 ++-- lib_util/vector3_pair_file_reader.c | 4 ++-- 18 files changed, 35 insertions(+), 35 deletions(-) diff --git a/lib_debug/debug.c b/lib_debug/debug.c index 6336e911fc..012183c5ac 100644 --- a/lib_debug/debug.c +++ b/lib_debug/debug.c @@ -820,7 +820,7 @@ int16_t make_dirs( const char *const pathname ) if ( sep != 0 ) { - temp = calloc( 1, strlen( pathname ) + 1 ); + temp = calloc( strlen( pathname ) + 1, sizeof( char ) ); p = pathname; while ( ( p = strchr( p, sep ) ) != NULL ) { diff --git a/lib_util/aeid_file_reader.c b/lib_util/aeid_file_reader.c index e569dbdc7c..6f877452e5 100644 --- a/lib_util/aeid_file_reader.c +++ b/lib_util/aeid_file_reader.c @@ -69,9 +69,9 @@ ivas_error aeidFileReader_open( return IVAS_ERR_FAILED_FILE_OPEN; } - self = calloc( sizeof( aeidFileReader ), 1 ); + self = calloc( 1, sizeof( aeidFileReader ) ); self->aeidFile = aeidFile; - self->file_path = calloc( sizeof( char ), strlen( aeidFilePath ) + 1 ); + self->file_path = calloc( strlen( aeidFilePath ) + 1, sizeof( char ) ); strcpy( self->file_path, aeidFilePath ); *aeidReader = self; diff --git a/lib_util/audio_file_reader.c b/lib_util/audio_file_reader.c index 1b52daaa77..92bfe89789 100644 --- a/lib_util/audio_file_reader.c +++ b/lib_util/audio_file_reader.c @@ -94,7 +94,7 @@ ivas_error AudioFileReader_open( { return IVAS_ERR_FAILED_FILE_OPEN; } - self = calloc( sizeof( AudioFileReader ), 1 ); + self = calloc( 1, sizeof( AudioFileReader ) ); self->samplingRate = 0; self->numChannels = 0; diff --git a/lib_util/audio_file_writer.c b/lib_util/audio_file_writer.c index 3210631019..eb93018341 100644 --- a/lib_util/audio_file_writer.c +++ b/lib_util/audio_file_writer.c @@ -89,7 +89,7 @@ ivas_error AudioFileWriter_open( return IVAS_ERR_FAILED_FILE_OPEN; } - self = calloc( sizeof( AudioFileWriter ), 1 ); + self = calloc( 1, sizeof( AudioFileWriter ) ); if ( self == NULL ) { return IVAS_ERR_FAILED_ALLOC; diff --git a/lib_util/hrtf_file_reader.c b/lib_util/hrtf_file_reader.c index 53a5d340e1..3347a0c9ab 100644 --- a/lib_util/hrtf_file_reader.c +++ b/lib_util/hrtf_file_reader.c @@ -83,9 +83,9 @@ ivas_error hrtfFileReader_open( return IVAS_ERR_FAILED_FILE_OPEN; } - self = calloc( sizeof( hrtfFileReader ), 1 ); + self = calloc( 1, sizeof( hrtfFileReader ) ); self->file = file; - self->file_path = calloc( sizeof( char ), strlen( filePath ) + 1 ); + self->file_path = calloc( strlen( filePath ) + 1, sizeof( char ) ); strcpy( self->file_path, filePath ); *hrtfReader = self; diff --git a/lib_util/ism_file_reader.c b/lib_util/ism_file_reader.c index 088a4134f9..83a32b7a01 100644 --- a/lib_util/ism_file_reader.c +++ b/lib_util/ism_file_reader.c @@ -72,9 +72,9 @@ IsmFileReader *IsmFileReader_open( return NULL; } - self = calloc( sizeof( IsmFileReader ), 1 ); + self = calloc( 1, sizeof( IsmFileReader ) ); self->file = file; - self->file_path = calloc( sizeof( char ), strlen( filePath ) + 1 ); + self->file_path = calloc( strlen( filePath ) + 1, sizeof( char ) ); strcpy( self->file_path, filePath ); return self; diff --git a/lib_util/ism_file_writer.c b/lib_util/ism_file_writer.c index fff4cc4ff0..10efc1ea3d 100644 --- a/lib_util/ism_file_writer.c +++ b/lib_util/ism_file_writer.c @@ -81,9 +81,9 @@ ivas_error IsmFileWriter_open( return IVAS_ERR_FAILED_FILE_OPEN; } - self = calloc( sizeof( IsmFileWriter ), 1 ); + self = calloc( 1, sizeof( IsmFileWriter ) ); self->file = file; - self->file_path = calloc( sizeof( char ), strlen( filePath ) + 1 ); + self->file_path = calloc( strlen( filePath ) + 1, sizeof( char ) ); strcpy( self->file_path, filePath ); *ismWriter = self; diff --git a/lib_util/jbm_file_reader.c b/lib_util/jbm_file_reader.c index b657ab7892..68caf5ae73 100644 --- a/lib_util/jbm_file_reader.c +++ b/lib_util/jbm_file_reader.c @@ -68,9 +68,9 @@ JbmFileReader *JbmFileReader_open( return NULL; } - self = calloc( sizeof( JbmFileReader ), 1 ); + self = calloc( 1, sizeof( JbmFileReader ) ); self->file = file; - self->file_path = calloc( sizeof( char ), strlen( filePath ) + 1 ); + self->file_path = calloc( strlen( filePath ) + 1, sizeof( char ) ); strcpy( self->file_path, filePath ); return self; diff --git a/lib_util/jbm_file_writer.c b/lib_util/jbm_file_writer.c index 76a5a67d25..9d11dad904 100644 --- a/lib_util/jbm_file_writer.c +++ b/lib_util/jbm_file_writer.c @@ -77,9 +77,9 @@ ivas_error JbmOffsetFileWriter_open( return IVAS_ERR_FAILED_FILE_OPEN; } - self = calloc( sizeof( JbmOffsetFileWriter ), 1 ); + self = calloc( 1, sizeof( JbmOffsetFileWriter ) ); self->file = file; - self->file_path = calloc( sizeof( char ), strlen( jbmOffsetFilename ) + 1 ); + self->file_path = calloc( strlen( jbmOffsetFilename ) + 1, sizeof( char ) ); strcpy( self->file_path, jbmOffsetFilename ); *jbmOffsetWriter = self; @@ -204,9 +204,9 @@ ivas_error JbmTraceFileWriter_open( fprintf( file, "#rtpSeqNo;rtpTs;rcvTime;playTime;active\n" ); - self = calloc( sizeof( JbmTraceFileWriter ), 1 ); + self = calloc( 1, sizeof( JbmTraceFileWriter ) ); self->file = file; - self->file_path = calloc( sizeof( char ), strlen( jbmTraceFilename ) + 1 ); + self->file_path = calloc( strlen( jbmTraceFilename ) + 1, sizeof( char ) ); strcpy( self->file_path, jbmTraceFilename ); *jbmTraceWriter = self; diff --git a/lib_util/ls_custom_file_reader.c b/lib_util/ls_custom_file_reader.c index 1629a6d59e..d874342c11 100644 --- a/lib_util/ls_custom_file_reader.c +++ b/lib_util/ls_custom_file_reader.c @@ -70,9 +70,9 @@ ivas_error CustomLsReader_open( return IVAS_ERR_FAILED_FILE_OPEN; } - self = calloc( sizeof( LsCustomFileReader ), 1 ); + self = calloc( 1, sizeof( LsCustomFileReader ) ); self->file = lsFile; - self->file_path = calloc( sizeof( char ), strlen( LsFilePath ) + 1 ); + self->file_path = calloc( strlen( LsFilePath ) + 1, sizeof( char ) ); strcpy( self->file_path, LsFilePath ); *hLsCustomReader = self; diff --git a/lib_util/masa_file_reader.c b/lib_util/masa_file_reader.c index 2cb76f96e6..1122878f8a 100644 --- a/lib_util/masa_file_reader.c +++ b/lib_util/masa_file_reader.c @@ -70,7 +70,7 @@ MasaFileReader *MasaFileReader_open( return NULL; } - self = calloc( sizeof( MasaFileReader ), 1 ); + self = calloc( 1, sizeof( MasaFileReader ) ); self->file = file; generate_gridEq( &self->sph_grid16 ); diff --git a/lib_util/masa_file_writer.c b/lib_util/masa_file_writer.c index 8cac01ff5a..3f269a6871 100644 --- a/lib_util/masa_file_writer.c +++ b/lib_util/masa_file_writer.c @@ -212,14 +212,14 @@ ivas_error MasaFileWriter_open( return IVAS_ERR_FAILED_FILE_OPEN; } - self = calloc( sizeof( MasaFileWriter ), 1 ); + self = calloc( 1, sizeof( MasaFileWriter ) ); self->file = file; - self->file_path = calloc( sizeof( char ), strlen( filePath ) + 1 ); + self->file_path = calloc( strlen( filePath ) + 1, sizeof( char ) ); strcpy( self->file_path, filePath ); if ( !delayCompensationEnabled ) { - self->delayStorage = calloc( sizeof( MASA_META_DELAY_STORAGE ), 1 ); + self->delayStorage = calloc( 1, sizeof( MASA_META_DELAY_STORAGE ) ); self->delayStorage->prevDelay = DELAY_MASA_PARAM_DEC_SFR; } diff --git a/lib_util/obj_edit_file_reader.c b/lib_util/obj_edit_file_reader.c index 9963e722ba..2dde08ecc3 100644 --- a/lib_util/obj_edit_file_reader.c +++ b/lib_util/obj_edit_file_reader.c @@ -76,13 +76,13 @@ ivas_error ObjectEditFileReader_open( return IVAS_ERR_FAILED_FILE_OPEN; } - self = (ObjectEditFileReader *) calloc( sizeof( ObjectEditFileReader ), 1 ); + self = (ObjectEditFileReader *) calloc( 1, sizeof( ObjectEditFileReader ) ); self->maxLineLen = 256; self->editFileHandle = fileHandle; - self->inLine = (char *) calloc( sizeof( char ), self->maxLineLen ); + self->inLine = (char *) calloc( self->maxLineLen, sizeof( char ) ); - self->readInfo = (ReadObjectEditInfo *) calloc( sizeof( ReadObjectEditInfo ), 1 ); + self->readInfo = (ReadObjectEditInfo *) calloc( 1, sizeof( ReadObjectEditInfo ) ); self->readInfo->bg_gain = 0.0f; self->readInfo->bg_gain_edited = false; diff --git a/lib_util/render_config_reader.c b/lib_util/render_config_reader.c index dd3e84ac87..7729efbc7c 100644 --- a/lib_util/render_config_reader.c +++ b/lib_util/render_config_reader.c @@ -1398,7 +1398,7 @@ ivas_error RenderConfigReader_open( return IVAS_ERR_FAILED_FILE_OPEN; } - pSelf = calloc( sizeof( RenderConfigReader ), 1 ); + pSelf = calloc( 1, sizeof( RenderConfigReader ) ); pSelf->pConfigFile = pConfigFile; pSelf->nFG = 0; pSelf->pFG = NULL; diff --git a/lib_util/rotation_file_reader.c b/lib_util/rotation_file_reader.c index f659fbb9fa..024b083737 100644 --- a/lib_util/rotation_file_reader.c +++ b/lib_util/rotation_file_reader.c @@ -72,10 +72,10 @@ ivas_error RotationFileReader_open( return IVAS_ERR_FAILED_FILE_OPEN; } - self = calloc( sizeof( RotFileReader ), 1 ); + self = calloc( 1, sizeof( RotFileReader ) ); self->trajFile = trajFile; self->frameCounter = 0; - self->file_path = calloc( sizeof( char ), strlen( trajFilePath ) + 1 ); + self->file_path = calloc( strlen( trajFilePath ) + 1, sizeof( char ) ); strcpy( self->file_path, trajFilePath ); self->fileRewind = false; diff --git a/lib_util/split_rend_bfi_file_reader.c b/lib_util/split_rend_bfi_file_reader.c index 70e695048e..07b71e2219 100644 --- a/lib_util/split_rend_bfi_file_reader.c +++ b/lib_util/split_rend_bfi_file_reader.c @@ -76,10 +76,10 @@ ivas_error SplitRendBFIFileReader_open( txtfile = ( strcmp( bfiFilePath + strlen( bfiFilePath ) - 4, ".txt" ) ? false : true ); - self = calloc( sizeof( SplitRendBFIFileReader ), 1 ); + self = calloc( 1, sizeof( SplitRendBFIFileReader ) ); self->bfiFile = bfiFile; self->frameCounter = 0; - self->file_path = calloc( sizeof( char ), strlen( bfiFilePath ) + 1 ); + self->file_path = calloc( strlen( bfiFilePath ) + 1, sizeof( char ) ); strcpy( self->file_path, bfiFilePath ); self->fileRewind = false; self->txtfile = txtfile; diff --git a/lib_util/tsm_scale_file_reader.c b/lib_util/tsm_scale_file_reader.c index 653fc0f2f6..65182061e2 100644 --- a/lib_util/tsm_scale_file_reader.c +++ b/lib_util/tsm_scale_file_reader.c @@ -73,9 +73,9 @@ TsmScaleFileReader *TsmScaleFileReader_open( return NULL; } - self = calloc( sizeof( TsmScaleFileReader ), 1 ); + self = calloc( 1, sizeof( TsmScaleFileReader ) ); self->file = file; - self->file_path = calloc( sizeof( char ), strlen( filePath ) + 1 ); + self->file_path = calloc( strlen( filePath ) + 1, sizeof( char ) ); strcpy( self->file_path, filePath ); return self; diff --git a/lib_util/vector3_pair_file_reader.c b/lib_util/vector3_pair_file_reader.c index 8a46a97d1d..5f6116c747 100644 --- a/lib_util/vector3_pair_file_reader.c +++ b/lib_util/vector3_pair_file_reader.c @@ -68,9 +68,9 @@ ivas_error Vector3PairFileReader_open( return IVAS_ERR_FAILED_FILE_OPEN; } - self = calloc( sizeof( Vector3PairFileReader ), 1 ); + self = calloc( 1, sizeof( Vector3PairFileReader ) ); self->trajFile = trajFile; - self->file_path = calloc( sizeof( char ), strlen( trajFilePath ) + 1 ); + self->file_path = calloc( strlen( trajFilePath ) + 1, sizeof( char ) ); strcpy( self->file_path, trajFilePath ); *vector3PairReader = self; -- GitLab From 2ef8b7cb3e6f3b9904e798dc4be3cc3c9d426612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=BCller?= Date: Wed, 11 Jun 2025 17:27:38 +0200 Subject: [PATCH 14/17] Replace malloc/memset(0) with calloc --- apps/decoder.c | 3 +-- lib_util/bitstream_reader.c | 7 +++---- lib_util/bitstream_writer.c | 7 +++---- lib_util/g192.c | 1 - 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/apps/decoder.c b/apps/decoder.c index 6a1d823f76..d4f5989373 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1858,13 +1858,12 @@ static ivas_error initOnFirstGoodFrame( return error; } - int16_t *zeroBuf = malloc( pcmFrameSize * sizeof( int16_t ) ); + int16_t *zeroBuf = calloc( pcmFrameSize, sizeof( int16_t ) ); if ( zeroBuf == NULL ) { fprintf( stdout, "Error: Unable to allocate memory for output buffer.\n" ); return IVAS_ERR_FAILED_ALLOC; } - memset( zeroBuf, 0, pcmFrameSize * sizeof( int16_t ) ); for ( int16_t i = 0; i < numInitialBadFrames; ++i ) { diff --git a/lib_util/bitstream_reader.c b/lib_util/bitstream_reader.c index a250a34a70..c6fe784fbd 100644 --- a/lib_util/bitstream_reader.c +++ b/lib_util/bitstream_reader.c @@ -203,16 +203,15 @@ static void init_for_mime( BS_READER_HANDLE hBsReader ) static ivas_error init_for_format( BS_READER_HANDLE *phBsReader, BS_READER_FORMAT format ) { /* Allocate memory under handle and check if allocation successful */ - ( *phBsReader ) = (BS_READER_HANDLE) malloc( sizeof( struct BS_Reader ) ); + /* Initialize all struct members to NULL - supported functions + * will be overwritten below in init_for_ */ + ( *phBsReader ) = (BS_READER_HANDLE) calloc( 1, sizeof( struct BS_Reader ) ); if ( *phBsReader == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "could not allocate bitstream reader" ); } - /* Initialize all struct members to NULL - supported functions - * will be overwritten below in init_for_ */ BS_READER_HANDLE hBsReader = *phBsReader; - memset( hBsReader, 0, sizeof( struct BS_Reader ) ); /* Set function pointers to selected format */ switch ( format ) diff --git a/lib_util/bitstream_writer.c b/lib_util/bitstream_writer.c index 8c4b64cd48..bff9f461b1 100644 --- a/lib_util/bitstream_writer.c +++ b/lib_util/bitstream_writer.c @@ -156,16 +156,15 @@ static void init_for_mime( BS_WRITER_HANDLE hBsWriter ) static ivas_error init_for_format( BS_WRITER_HANDLE *phBsWriter, BS_WRITER_FORMAT format ) { /* Allocate memory under handle and check if allocation successful */ - ( *phBsWriter ) = (BS_WRITER_HANDLE) malloc( sizeof( struct BS_Writer ) ); + /* Initialize all struct members to NULL - supported functions + * will be overwritten below in init_for_ */ + ( *phBsWriter ) = (BS_WRITER_HANDLE) calloc( 1, sizeof( struct BS_Writer ) ); if ( *phBsWriter == NULL ) { IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "could not allocate bitstream writer" ); } - /* Initialize all struct members to NULL - supported functions - * will be overwritten below in init_for_ */ BS_WRITER_HANDLE hBsWriter = *phBsWriter; - memset( hBsWriter, 0, sizeof( struct BS_Writer ) ); /* Set function pointers to selected format */ switch ( format ) diff --git a/lib_util/g192.c b/lib_util/g192.c index f61971ef14..f7eeaf6f6d 100644 --- a/lib_util/g192.c +++ b/lib_util/g192.c @@ -84,7 +84,6 @@ G192_ERROR G192_Reader_Open_filename( { return G192_MEMORY_ERROR; } - memset( *phG192, 0, sizeof( struct __G192 ) ); /* open file stream */ ( *phG192 )->file = fopen( filename, "rb" ); -- GitLab From 3d0ab448b6463301e3ebad0c14b8aa0fdd2ed729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=BCller?= Date: Tue, 15 Jul 2025 10:53:47 +0200 Subject: [PATCH 15/17] Revert changes on lc3plus The fixes will be introduced by a future lc3plus update MR. --- lib_lc3plus/dct4.c | 4 ++-- lib_lc3plus/mdct.c | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib_lc3plus/dct4.c b/lib_lc3plus/dct4.c index d45687ffa7..4b4a3f6a0f 100644 --- a/lib_lc3plus/dct4.c +++ b/lib_lc3plus/dct4.c @@ -52,8 +52,8 @@ void dct4_init(Dct4* dct, int length) int i; assert(length <= MAX_LEN); dct->length = length; - dct->twid1 = calloc(length / 2, sizeof(*dct->twid1)); - dct->twid2 = calloc(length / 2, sizeof(*dct->twid2)); + dct->twid1 = calloc(sizeof(*dct->twid1), length / 2); + dct->twid2 = calloc(sizeof(*dct->twid2), length / 2); for (i = 0; i < length / 2; i++) { dct->twid1[i] = cexpi(-(LC3_FLOAT)M_PI_LC3PLUS * (i + (LC3_FLOAT)0.25) / length); dct->twid2[i] = cexpi(-(LC3_FLOAT)M_PI_LC3PLUS * i / length); diff --git a/lib_lc3plus/mdct.c b/lib_lc3plus/mdct.c index 0e41b4f745..ebea9a2c83 100644 --- a/lib_lc3plus/mdct.c +++ b/lib_lc3plus/mdct.c @@ -108,8 +108,7 @@ void mdct_init(Mdct* mdct, LC3_INT length, LC3_INT frame_dms, LC3_INT fs_idx, LC mdct->length = length; mdct->mem_length = length - mdct->leading_zeros; - mdct->window = mdct_window(length, frame_dms, hrmode); - mdct->mem = calloc(mdct->mem_length, sizeof(*mdct->mem)); + mdct->mem = calloc(sizeof(*mdct->mem), mdct->mem_length); dct4_init(&mdct->dct, length); } -- GitLab From 6a3f1700677b16f9bca7de7e0b741eca2cfc76ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=BCller?= Date: Tue, 15 Jul 2025 11:04:34 +0200 Subject: [PATCH 16/17] Restore accidentally deleted line --- lib_lc3plus/mdct.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib_lc3plus/mdct.c b/lib_lc3plus/mdct.c index ebea9a2c83..4698afd4bf 100644 --- a/lib_lc3plus/mdct.c +++ b/lib_lc3plus/mdct.c @@ -108,6 +108,7 @@ void mdct_init(Mdct* mdct, LC3_INT length, LC3_INT frame_dms, LC3_INT fs_idx, LC mdct->length = length; mdct->mem_length = length - mdct->leading_zeros; + mdct->window = mdct_window(length, frame_dms, hrmode); mdct->mem = calloc(sizeof(*mdct->mem), mdct->mem_length); dct4_init(&mdct->dct, length); } -- GitLab From 65b2c8a3fa821416503b8b90b83ef8c9651ee004 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 15 Jul 2025 12:27:59 +0200 Subject: [PATCH 17/17] add comment --- apps/decoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/decoder.c b/apps/decoder.c index d4f5989373..71379c6575 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -1858,6 +1858,7 @@ static ivas_error initOnFirstGoodFrame( return error; } + /* Write zeros to the output audio buffer */ int16_t *zeroBuf = calloc( pcmFrameSize, sizeof( int16_t ) ); if ( zeroBuf == NULL ) { @@ -1887,7 +1888,6 @@ static ivas_error initOnFirstGoodFrame( } else { - if ( *pRemainingDelayNumSamples < *numOutSamples ) { if ( ( error = AudioFileWriter_write( *ppAfWriter, zeroBuf, *numOutSamples * *pNumOutChannels - ( *pRemainingDelayNumSamples * *pNumOutChannels ) ) ) != IVAS_ERR_OK ) -- GitLab