Skip to content

BUG: Parenthesize macro arguments and replacement lists - #122

Merged
hjmjohnson merged 1 commit into
masterfrom
pr/fix-macro-parentheses
Nov 13, 2026
Merged

hjmjohnson merged 1 commit into
masterfrom
pr/fix-macro-parentheses

Conversation

@hjmjohnson

Copy link
Copy Markdown
Member

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

Base: pr/fix-extra-semi-stmt, not master. It edits the same lines as that
change, so merge that one first.

Commits
  • BUG: Parenthesize macro arguments and replacement lists

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
Clears all 155 bugprone-macro-parentheses findings: 152 in
nifti2/nifti_tool.c, 2 in niftilib/nifti1_tool.c, 1 in fsliolib/fslio.c.

An unparenthesized argument takes the precedence of whatever the caller
passed. NT_FILL(..., rv) expands to `rv = ...` and NT_MAT33_TO_MAT44 to
`m44.m[0][0] = ...`, which break for an argument that is not already a
postfix expression. Every current caller passes a plain identifier, a
literal or `nim->sto_xyz`, so nothing observable moves.

The NT_DCONVERT dtype and stype parameters stay bare behind a NOLINT
fence: they name types, so `(dtype) * pd = dptr;` would be a cast
expression rather than a declaration. FSL_RADIOLOGICAL is in an installed
header, so its replacement list changes from -1 to (-1); its value does not.

(cherry picked from commit dbfb59d)
@hjmjohnson
hjmjohnson force-pushed the pr/fix-macro-parentheses branch from 3e47a58 to 5c1c51f Compare October 6, 2026 19:13
@hjmjohnson
hjmjohnson changed the base branch from pr/fix-extra-semi-stmt to master 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

Clean macro parenthesization across fsliolib/fslio.h, niftilib/nifti1_tool.h, and nifti2/nifti_tool.h!

  • Wrapping FSL_RADIOLOGICAL as (-1), parenthesizing (rv), (fldp), (failure), (m33), (m44), (mout), (min0), (min1), and (M), and documenting why type parameters dtype/stype require /* NOLINTBEGIN(bugprone-macro-parentheses) */ eliminates all ~155 bugprone-macro-parentheses diagnostics enabled by PR #97.

Left one tiny non-blocking nit inline on dptr/sptr inside the NOLINT block (and note the stale Base: line in the PR description).

Comment thread nifti2/nifti_tool.h
@@ -157,89 +160,90 @@ typedef struct {
stype * ps = sptr; \

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] Minor nit inside the NOLINTBEGIN(bugprone-macro-parentheses) region: while dtype and stype cannot be parenthesized, dptr (line 159) and sptr (line 160) are value expressions (dtype * pd = (dptr);, stype * ps = (sptr);), so parenthesizing (dptr) and (sptr) guards callers passing e.g. base + off or ternary expressions that NOLINTBEGIN would otherwise silence.

@hjmjohnson
hjmjohnson merged commit 677862d into master Nov 13, 2026
4 checks passed
@hjmjohnson
hjmjohnson deleted the pr/fix-macro-parentheses branch November 13, 2026 18:41
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