Skip to content

Fix GCC 16 warnings in silk/float/pitch_analysis_core_FLP.c#461

Open
Nicolas0315 wants to merge 1 commit intoxiph:mainfrom
Nicolas0315:fix/gcc16-warnings-pitch-analysis
Open

Fix GCC 16 warnings in silk/float/pitch_analysis_core_FLP.c#461
Nicolas0315 wants to merge 1 commit intoxiph:mainfrom
Nicolas0315:fix/gcc16-warnings-pitch-analysis

Conversation

@Nicolas0315
Copy link

Fix two compiler warnings reported in #451 when building with GCC 16:

1. -Wmaybe-uninitialized for frame_8_FIX

GCC 16 cannot prove that frame_8_FIX is always initialized before use at line 157 (silk_resampler_down2 call), even though all three branches of the Fs_kHz conditional (16, 12, 8) write to it before the common path reads it.

Fix: Zero-initialize the array at declaration. The cost is negligible — 640 bytes (PE_MAX_FRAME_LENGTH_MS * 8 * sizeof(opus_int16) = 40 * 8 * 2), called once per pitch analysis invocation.

2. -Wstringop-overflow for silk_memset on C[]

The size expression sizeof(silk_float) * nb_subfr * ((PE_MAX_LAG >> 1) + 5) mixes size_t (from sizeof) with signed opus_int (nb_subfr). GCC 16's improved overflow analysis warns that the intermediate product could theoretically be negative and wrap to a huge value (~UINT64_MAX), exceeding the maximum object size.

Fix: Cast nb_subfr to size_t to make the arithmetic unambiguously unsigned. nb_subfr is always positive (validated by the caller and bounded by PE_MAX_NB_SUBFR = 4).

Fixes #451.

Fix two compiler warnings reported with GCC 16 (issue xiph#451):

1. -Wmaybe-uninitialized for 'frame_8_FIX': GCC cannot prove that
   frame_8_FIX is always initialized before use, even though all three
   branches of the Fs_kHz conditional write to it. Zero-initialize the
   array to silence the warning. The cost is negligible (640 bytes,
   called once per pitch analysis).

2. -Wstringop-overflow for silk_memset on C[]: The size expression
   'sizeof(silk_float) * nb_subfr * ((PE_MAX_LAG >> 1) + 5)' involves
   signed int 'nb_subfr' multiplied with unsigned size_t from sizeof.
   GCC 16 warns that the intermediate result could theoretically be
   negative and wrap to a huge value. Cast nb_subfr to size_t to make
   the arithmetic unambiguously unsigned.

Fixes: xiph#451
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 compiler warnings when compiling opus-1.6.1 using gcc-16

1 participant