Repository navigation
Fix gcc 16 array-bounds, maybe-uninitialized and enum-conversion warnings - #183
Merged
Merged
Conversation
FDKmemclear() sized the ipd table as PS_MAX_ENVELOPES * PS_MAX_BANDS * sizeof(PS_DELTA), but ipd is declared INT ipd[PS_MAX_ENVELOPES] [PS_MAX_BANDS]. The two element types only happen to have the same size, and multiplying the two enumerators is arithmetic between different enumeration types, which gcc warns about with -Wdeprecated-enum-enum-conversion: ps_encode.cpp:1002:34: warning: arithmetic between different enumeration types 'PS_CONSTS' and 'PS_BANDS' is deprecated Use sizeof(hPsOut->ipd) so the clear follows the declaration.
When allStreamsSameTimeFraming is not set, CreateStreamMuxConfig() reads the configuration of layer - 1 to decide whether to write coreFrameOffset. Layer 0 has no layer below it, and LATM_MAX_LAYERS and MAX_LAYERS are both 1, so the index is always -1. gcc flags it: tpenc_latm.cpp:391:72: warning: array subscript -1 is below array bounds of 'CODER_CONFIG* [1]' [-Warray-bounds=] latm_interface.c:361:66: warning: array subscript -1 is below array bounds of 'struct CODER_CONFIG_INFO *[1]' [-Warray-bounds=] coreFrameOffset describes a scalable layer relative to its core layer, which only exists from layer 1 up, so only make the check for layer > 0.
HANDLE_HUFF_NODE cast every Huffman node table to a pointer to a
SHORT[168][2] array, whatever size the table really is. With
huff_read() inlined, gcc sees the reshape table, which has 39 rows,
read through that type:
nlc_dec.cpp:239:37: warning: array subscript 'const SHORT [168][2]
{aka const short int [168][2]}[0]' is partly outside array bounds of
'const HUFF_RES_NODES [1]' [-Warray-bounds=]
Every table is a SHORT[N][2], so pass them as const SHORT (*)[2] and
let each one decay to that type. The casts, HANDLE_HUFF_NODE and
MAX_ENTRIES are then unused and are removed.
calc_diff_freq() and calc_diff_time() copy in_data[0] (and prev_data[0]) before looking at num_val. The callers only fill the quantised MSB arrays for the dataBands bands they code, so with dataBands of 0 the first element is read uninitialised, and gcc reports it once the helpers are inlined: sacenc_nlc_enc.cpp:181:26: warning: 'quant_data_msb' may be used uninitialized [-Wmaybe-uninitialized] sac_nlc_enc.c:162:24: warning: 'quant_data_msb' may be used uninitialized [-Wmaybe-uninitialized] Return early when there is nothing to difference. In the xhe-aac copy, split_lsb(), calc_diff_freq() and calc_diff_time() also took num_val as a short while every caller passes the int dataBands, and the quant_offset path fills the arrays with an int loop. The helpers and the fill loops could then disagree about how many bands there are, which keeps the warning alive in EcDataSingleEnc(). Take num_val as an int, as the libSACenc versions already do.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Building 3.0.0 with gcc 16.2 at -O2 -Wall produces several warnings that point at real (if unreachable) issues. These four commits fix them:
Tested: test/run-test.sh passes with hashes identical to the references, both before and after the series (x86_64, gcc 16).