Skip to content

Render config reader: warning about pointer comparison

The following code in the render config reader raises a warning:

if ( i > pRenderConfigReader->nFG || &pRenderConfigReader->pFG[i] == NULL )
{
    return IVAS_ERR_INVALID_RENDER_CONFIG;
}
lib_util/render_config_reader.c: In function ‘RenderConfigReader_read’:
lib_util/render_config_reader.c:2372:91: warning: the comparison will always evaluate as ‘false’ for the pointer operand in ‘pRenderConfigReader->pFG + (sizetype)((long unsigned int)i * 16)’ must not be NULL [-Waddress]
 2372 |                         if ( i > pRenderConfigReader->nFG || &pRenderConfigReader->pFG[i] == NULL )
      |                                                                                           ^~

https://forge.3gpp.org/rep/ivas-codec-pc/ivas-codec/-/blob/main/lib_util/render_config_reader.c#L2372-2375

Allocation is performed above:

/* Allocate memory for the frequency grids */
if ( ( pRenderConfigReader->pFG = (FrequencyGrid *) malloc( pRenderConfigReader->nFG * sizeof( FrequencyGrid ) ) ) == NULL )
{
    return IVAS_ERR_FAILED_ALLOC;
}
for ( idx = 0; idx < nFG; idx++ )
{
    pRenderConfigReader->pFG[idx].nrBands = 0;
    pRenderConfigReader->pFG[idx].pFc = NULL;
}

https://forge.3gpp.org/rep/ivas-codec-pc/ivas-codec/-/blob/main/lib_util/render_config_reader.c#L2038-2047

The correct comparison would be to either check pRenderConfigReader->pFG == NULL or pRenderConfigReader->pFG[i].pFC == NULL.