Skip to content

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

Merged
hjmjohnson merged 2 commits into
masterfrom
pr/fix-extra-semi-stmt
Nov 14, 2026
Merged

hjmjohnson merged 2 commits into
masterfrom
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.

@hjmjohnson
hjmjohnson marked this pull request as ready for review September 24, 2026 12:18
@hjmjohnson
hjmjohnson marked this pull request as draft October 6, 2026 15:02
Base automatically changed from clang-tidy-fixes to master October 6, 2026 19:07
gdevenyi and others added 2 commits October 6, 2026 14:13
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)
@hjmjohnson
hjmjohnson force-pushed the pr/fix-extra-semi-stmt branch from 7cabeef to 694c21e Compare October 6, 2026 19:13
@hjmjohnson
hjmjohnson marked this pull request as ready for review October 6, 2026 19:13

@gdevenyi gdevenyi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by Google Carbon

Verdict: Approve

Verified every macro definition and semicolon removal across fsliolib/fslio.c, nifti2/nifti2_io.c, niftilib/nifti1_io.c, and niftilib/nifti_tester001.c:

  • Wrapping FSLIOERR(x) and the 7 nifti_*_test macros in do { ... } while(0) (and parenthesizing (x), (rval), (Nbyper), (Swapsize)) makes them safe single-statement macros in unbraced if/else arms and brings Clang's -Wextra-semi-stmt count from 74 (173 with tests) down to 0!
  • Minor PR-metadata nit: the PR body still says Base: clang-tidy-fixes, not master, whereas the GitHub PR actually targets master cleanly (1 commit).

Comment thread fsliolib/fslio.c
static int FslOverrideOutputType=-1;

#define FSLIOERR(x) { fprintf(stderr,"Error:: %s\n",(x)); fflush(stderr); exit(EXIT_FAILURE); }
#define FSLIOERR(x) do { fprintf(stderr,"Error:: %s\n",(x)); fflush(stderr); exit(EXIT_FAILURE); } while(0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Google Carbon] Clean do { ... } while(0) wrap + (x) parenthesization — verified all FSLIOERR(...) call sites in fslio.c terminate with ;.

&Errors); \
}
#define nifti_datatype_test(constant,string) \
do { \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Google Carbon] Verified all 7 nifti_*_test macro expansions in nifti_tester001.c — wrapping the block + local char buf[64] declaration in do { ... } while(0) cleanly eliminates the trailing empty statements after } ;.

@hjmjohnson
hjmjohnson merged commit 6d1e906 into master Nov 14, 2026
8 checks passed
@hjmjohnson
hjmjohnson deleted the pr/fix-extra-semi-stmt branch November 14, 2026 14:30
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