Skip to content

BUG: Give the statement macros a do/while(0) body and drop the stray semicolons - #120

Open
hjmjohnson wants to merge 2 commits into
clang-tidy-fixesfrom
pr/fix-extra-semi-stmt
Open

hjmjohnson wants to merge 2 commits into
clang-tidy-fixesfrom
pr/fix-extra-semi-stmt

Conversation

@hjmjohnson

Copy link
Copy Markdown
Member

Re-submission of #49, reverted from master on 2026-09-24 so it can be
reviewed before merging. Content is unchanged from the original.

Base: clang-tidy-fixes, not master. It edits the same lines as that
change, so merge that one first.

Commits
  • BUG: Give the statement macros a do/while(0) body
  • STYLE: Align the continuations in the macros this branch rewrites

Ordering for all the re-submitted work is tracked in #84.

gdevenyi and others added 2 commits September 24, 2026 07:11
A macro whose body is a bare { ... } block cannot be used as a
statement:

    if( cond )
        FSLIOERR(...);         /* the ; ends the if, the block runs */
    else                       /* ...and this is a syntax error */

No current call site is written that way -- FSLIOERR has no `else`
after it anywhere, and none of the nifti_*_test macros appears in an
if or else arm -- so the change is prophylactic and nothing observable
moves.  The next person to write one, though, gets a syntax error a
long way from the cause.  clang reports the call sites as
-Wextra-semi-stmt, because the trailing semicolon at each is an empty
statement.

Wrapped: FSLIOERR in fslio.c and the seven nifti_*_test macros in
nifti_tester001.c.  The NT_FILL and NT_MAT* families in the tool
headers already have do/while bodies.

Two genuine empty statements go too: a doubled semicolon inside
unescape_string() in both io files, and a stray semicolon after the
closing brace of an if block in FslClose().

FSLIOERR is worth calling out: it expands to fprintf plus
exit(EXIT_FAILURE), and of its roughly fifty call sites several are
the whole body of a braceless if.  Those are correct today only
because the macro always exits.

(cherry picked from commit 4ac84e5)
The backslashes sat at four different columns within a single macro, one
of them past 80. Each macro is now aligned to its own width, one space
past its longest line, so a block stays as narrow as its content allows
rather than being widened by one long line.

Only the seven macros the preceding commit gives a do/while(0) body are
touched.

(cherry picked from commit 3f14c7e)
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.

3 participants