JianyuWang0623 commented on PR #19555:
URL: https://github.com/apache/nuttx/pull/19555#issuecomment-5397889289
While debugging a CI failure on an unrelated PR (nuttx-apps#3751), I found a
false positive in the `Bad left brace alignment` check that the
regression-introducing commit `bdeb262b8d3` ("tools/nxstyle: indent code
against its enclosing brace, not modulo 4") added, and confirmed this PR
already fixes it.
Root cause: the exemption for a macro-that-takes-a-block (e.g.
`list_for_every_entry(...)`) only compares against `prevcodeindent` (the
indentation of the *previous line*):
```c
else if (prevlastcode == ')' && indent == prevcodeindent + 2)
{
}
```
When the macro call wraps its arguments onto a continuation line,
`prevcodeindent` becomes the indentation of that continuation line instead of
the line where the macro call started, so the exemption never matches and the
brace is flagged.
Minimal repro (built master's `tools/nxstyle.c` as of this comment, `nxstyle
repro.c`):
```c
void add_ready(FAR struct action_manager_s *am,
FAR struct action_s *ready)
{
list_for_every_entry(&am->ready_actions, ready, struct action_s,
ready_node)
{
do_something(ready);
}
}
```
```
$ ./nxstyle repro.c
repro.c:19:4: error: Bad left brace alignment
```
This isn't an isolated case — the same false positive currently fires on
existing, unmodified code such as `drivers/vhost/vhost.c` on master.
I confirmed this branch (`nxstyle_fixes`) already resolves it. The relevant
change extends the exemption with a second alternative, `stmt_lineindent + 2`,
which covers the continuation-line case:
```c
else if (prevlastcode == ')' &&
(indent == prevcodeindent + 2 ||
indent == stmt_lineindent + 2))
{
}
```
```
$ ./nxstyle repro.c # built from this branch
$ echo $?
0
```
Given the scope of this PR is large and it currently has merge conflicts
against master, would it be worth splitting out just the nxstyle.c fix (or at
least this specific brace-alignment exemption) into its own smaller PR so the
regression can be addressed independently? Happy to help if useful.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]