Skip to content

COMP: Declare the exported functions that no header declares - #90

Open
hjmjohnson wants to merge 6 commits into
masterfrom
pr/fix-missing-prototypes
Open

hjmjohnson wants to merge 6 commits into
masterfrom
pr/fix-missing-prototypes

Conversation

@hjmjohnson

@hjmjohnson hjmjohnson commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

COMP: Declare the exported functions that no header declares

Clears every -Wmissing-declarations warning with USE_FSL_CODE=ON,
USE_CIFTI_CODE=ON, and the apps on, for both FSLSTYLE=OFF and ON, so
the CI job proposed in #92 can make that flag an error.

ABI note: seven fsliolib functions become static and two uncalled ones
(FslSetVoxUnits, FslGetVoxUnits) are deleted, so libfslio exports nine
fewer symbols. Under FSLSTYLE=ON, libniftiio and libnifti2 also stop
exporting doPigz and doPigz2. None is declared in any header, but this
belongs in the next minor tag's release notes.

Base: master. Independent of the rest of the re-submitted stack.

Commits
  • ENH: Declare the three functions that have a published counterpart
    (FslGetHdrImgNames, FslSetIntensityScaling, axml_recur_find_xml).
  • BUG: Recurse into the children in axml_recur_find_xml. It passed the
    current node instead of the child, so it never searched below the root
    and overflowed the stack with no depth limit; adds a ctest.
  • COMP: Give the fsliolib internal functions static linkage (seven made
    static, two deleted).
  • COMP: Declare nifti_fileexists where it is defined. A file-scope
    prototype in nifti1_io.c and nifti2_io.c; both libraries still define
    and export it, and deduplicating it is left for a later change because it
    alters the exported API.
  • STYLE: Derive the aux_file bound from sizeof.
  • COMP: Give the pigz writers internal linkage (doPigz, doPigz2; only
    compiled under FSLSTYLE=ON, which enables PIGZ). The NIFTI-1 copy of
    doPigz2, uncalled and identical to doPigz, is deleted.
Verification

Built with Homebrew gcc-16, -DCMAKE_C_FLAGS=-Wmissing-declarations,
USE_FSL_CODE=ON, USE_CIFTI_CODE=ON, NIFTI_BUILD_APPLICATIONS=ON,
NIFTI_BUILD_TESTING=ON, Release, at d61944c:

FSLSTYLE missing-declarations warnings ctest
OFF 0 348/348
ON 0 348/348

Before the pigz commit, FSLSTYLE=ON reported four warnings (doPigz and
doPigz2 in each of nifti1_io.c and nifti2_io.c).

@hjmjohnson
hjmjohnson marked this pull request as ready for review September 24, 2026 12:03
@hjmjohnson
hjmjohnson force-pushed the pr/fix-missing-prototypes branch from 9fc0c69 to b58fbc6 Compare October 6, 2026 14:39
@hjmjohnson
hjmjohnson changed the base branch from ci/widen-coverage to master October 6, 2026 14:39
@hjmjohnson
hjmjohnson force-pushed the pr/fix-missing-prototypes branch from b58fbc6 to 36416fd Compare November 6, 2026 15:11
@hjmjohnson

Copy link
Copy Markdown
Member Author

Force-push 36416fd -> b612547 is a plain rebase onto master (no content change), so #89, which carries the same three declaration commits, drops them cleanly once this merges.

@hjmjohnson
hjmjohnson force-pushed the pr/fix-missing-prototypes branch from 36416fd to b612547 Compare November 6, 2026 15:22
@hjmjohnson

Copy link
Copy Markdown
Member Author

@greptileai review

Comment thread niftilib/nifti1_io.c Resolved
@hjmjohnson
hjmjohnson force-pushed the pr/fix-missing-prototypes branch 2 times, most recently from 026c6cb to d61944c Compare November 9, 2026 18:35
@hjmjohnson

Copy link
Copy Markdown
Member Author

Two force-pushes: b612547 → 026c6cb is the review fix only (the dead NIFTI-1 doPigz2 deleted); 026c6cb → d61944c is a plain rebase onto master, all five commits = in range-diff.

@hjmjohnson
hjmjohnson requested review from gdevenyi and seanm November 11, 2026 18:38

@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: Request Changes

Verified that this PR reduces both -Wmissing-prototypes (Clang & GCC) and -Wmissing-declarations (GCC) from 18 warnings to 0 across all library and test configurations (FSLSTYLE=OFF/ON). Making the 7 uncalled internal fslio.c helpers and doPigz/doPigz2 static (and deleting NIFTI-1's duplicate dead doPigz2) is clean and well-reasoned.

However, one newly published header declaration exposes a broken infinite-recursion function:

  • [BLOCKER] axml_recur_find_xml (cifti/afni_xml.h:91-92 / cifti/afni_xml.c:556-578): Adding axml_recur_find_xml to the installed header cifti/afni_xml.h turns an uncalled function into public API, but its implementation in cifti/afni_xml.c:573 passes ax instead of ax->xchild[ind] to the recursive call:
    rx = axml_recur_find_xml(func, ax, depth+1, max_depth);
    It never visits any child node, and whenever max_depth <= 0 ("unlimited depth", per line 567) and ax->nchild > 0, calling it causes unbounded recursion and an immediate stack overflow! Please either fix ax -> ax->xchild[ind] in cifti/afni_xml.c:573 (with a small unit test) if publishing it intentionally, or keep it out of afni_xml.h / remove the dead function if ABI baseline policy permits (note also #93 annotates it CIF_API).

Comment thread cifti/afni_xml.h Resolved
Comment thread fsliolib/fslio.h Resolved
Comment thread nifti2/nifti2_io.c Resolved
FslGetHdrImgNames and FslSetIntensityScaling are defined here but
declared nowhere, while FslGetIntensityScaling and FslInit are already
published.  axml_recur_find_xml sits beside axml_recur in afni_xml.h
the same way.

The upstream fslio was deleted in 2015 in favor of a C++ replacement,
so this copy is the surviving one and its header is ours to correct.

Additive; no symbol changes.
The depth-first search passed the current node, not its child, to the
recursive call, so it never visited a child.  With max_depth <= 0 and
any child present it recursed without bound and overflowed the stack;
with a depth limit it returned NULL for any match below the root.

The new test builds a three-level tree and checks limited, unlimited,
and leaf searches.  Without the fix it aborts under ASan with a stack
overflow.
Nine functions in fslio.c have external linkage and no declaration in
any header.  Nothing in the tree calls them across a translation unit,
AFNI's vendored copy never calls them, and no public source outside a
vendored copy of this file references them, so a caller would have had
to declare them itself.

Seven of them are used within fslio.c and become static, with their
prototypes collected in one block so the boundary between internal and
published is visible in one place.

FslSetVoxUnits and FslGetVoxUnits have no caller at all and are
deleted.

Removes nine exported symbols from libfslio.
nifti1_io.c and nifti2_io.c each define nifti_fileexists with external
linkage, so libniftiio and libnifti2 export the same name and ELF link
order decides which one a caller linking both resolves to.

Declaring it locally silences the warning without choosing between
publishing it and making it static; that choice needs the duplication
settled first, and it covers a hundred names, not this one.

The duplicate definition is left for a later change, because removing
either copy or making it static alters the exported API.
Keeps FslGetAuxFile and FslSetAuxFile deriving the same length so the
pair cannot drift if the field width changes.  sizeof is 24, so the
copy still writes at most 23 bytes.
doPigz and doPigz2 are called only from the file that defines them and
appear in no header, so they are internal. Declaring them so is what
lets -Wmissing-declarations be promoted to an error on the FSLSTYLE
path, where they were the only offenders.

The NIFTI-1 library also carried a doPigz2, taking a nifti_1_header
despite its name, byte-identical to doPigz beside it and called from
nowhere. It is removed.

The exported symbol set of the default build is unchanged: this code
compiles only under PIGZ, which FSLSTYLE enables.
@hjmjohnson
hjmjohnson force-pushed the pr/fix-missing-prototypes branch from d61944c to 5c2f709 Compare November 17, 2026 22:33
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