Skip to content

Backport to 9.x: fix build-SITL-Mac VLA-folding-constant error in log.c - #11724

Closed
MakeSomeFakeNews wants to merge 1 commit into
iNavFlight:maintenance-9.xfrom
MakeSomeFakeNews:backport-sitl-mac-log-fix
Closed

Backport to 9.x: fix build-SITL-Mac VLA-folding-constant error in log.c#11724
MakeSomeFakeNews wants to merge 1 commit into
iNavFlight:maintenance-9.xfrom
MakeSomeFakeNews:backport-sitl-mac-log-fix

Conversation

@MakeSomeFakeNews

Copy link
Copy Markdown
Contributor

Cherry-pick of 87ed42b from master onto maintenance-9.x (original author credited in the commit).

build-SITL-Mac currently fails on every PR targeting maintenance-9.x: src/main/common/log.c:210 sizes a stack buffer with const size_t locals, which clang on the macOS runners now rejects under -Werror,-Wgnu-folding-constant. Replacing the locals with an enum (as already done on master) makes the array size a true constant expression.

Example of an affected PR: #11723 (all jobs pass except build-SITL-Mac).

_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).

(cherry picked from commit 87ed42b)
@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@sensei-hacker

Copy link
Copy Markdown
Member

Closing — maintenance-9.x is not an actively maintained target branch right now (we're working from release/9.1 and maintenance-10.x), and release/9.1 already has both this fix and the related osd.c GPS_DEGREES_DIVIDER integer-literal fix, so build-SITL-Mac is green there. Thanks for tracking this down, though — the second failure you'd have hit next (the osd.c STATIC_ASSERT) was a good catch pattern, it's just already fixed on the branches we're building from.

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 participants