Fix build-SITL-Mac VLA-folding-constant error in log.c (9.1 backport)#11680
Conversation
_logBufferHex() sized a stack buffer using two `const size_t` locals (charsPerByte, maxBytes). In C, const-qualified objects are not integer constant expressions, so the array size expression was technically a variable-length array; recent AppleClang treats reliance on its extension that folds such expressions back to a constant as an error under -Werror -Wgnu-folding-constant, breaking build-SITL-Mac. Replace the const locals with a local enum, whose members are genuine integer constant expressions in C. The buffer size and behavior are unchanged (13 + 5*8 + 1 = 54 bytes either way).
PR Summary by QodoFix AppleClang VLA folding warning in log.c (9.1 backport)
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
STATIC_ASSERT expands to a typedef of a char array sized by the condition, a common compile-time-assertion trick. This call site's condition compared GPS_DEGREES_DIVIDER (already 10000000L) against the floating-point literal 1e7. Per C11 6.6p6, integer constant expressions may not contain floating constants, so despite being trivially foldable, AppleClang's -Wgnu-folding-constant -Werror rejects it. Replace 1e7 with 10000000L to match GPS_DEGREES_DIVIDER's own literal form, making the condition a pure integer constant expression. No change to the assertion's truth value or any runtime behavior.
|
Test firmware build ready — commit Download firmware for PR #11680 240 targets built. Find your board's
|
Summary
Backport of #11679 to
release/9.1. Fixes the same-Wgnu-folding-constantAppleClang build failure insrc/main/common/log.c(_logBufferHex()), which exists identically on this branch.Root Cause
_logBufferHex()sizes a stack buffer with:In C (unlike C++), a
const-qualified object is not an integer constant expression, so this array size is technically a variable-length array. AppleClang on the macOS CI runner now warns (and-Werrorpromotes to error) when relying on the GNU extension that folds it back to a fixed size.Fix
Replace the two
const size_tlocals with a localenum:Enum constants are genuine integer constant expressions in C (C11 6.6p6), so this is a real fix rather than a suppression. No behavior change: buffer size is
13 + 5*8 + 1 = 54bytes both before and after.Testing
release/9.1— identical diff, no conflicts.log.c.build-SITL-MacCI leg on this PR will provide the authoritative confirmation against the actual AppleClang toolchain.Code Review
Same fix already reviewed with inav-code-review agent on #11679 — no critical or important issues found. Approved.
Companion PR (maintenance-10.x): #11679