Conversation
3c93dfb to
95930d1
Compare
95930d1 to
e40e0ba
Compare
e40e0ba to
fd4bec6
Compare
|
Rebased onto No test added — the defect is not demonstrable at runtime. The Why no testThe switch selectors are vbest = -666.0F ; ibest=pbest=qbest=rbest=1 ; jbest=2 ; kbest=3 ;and the loops only ever reassign There is no sanitizer path either: AddressSanitizer does not detect uninitialized reads, and MemorySanitizer is not configured for this project — and would not fire here anyway, since the read never happens. A test that called Message and comment cleanupRemoved the AI The commit body was also corrected: it claimed an unexpected switch value "falls through and the function writes an indeterminate value". That is true of the code shape but not reachable today, and the body now says so rather than overstating the bug. BuildRelease, Ninja, full option set. 362/362 pass. Functional diff unchanged: |
fd4bec6 to
1acc43c
Compare
seanm
left a comment
There was a problem hiding this comment.
Does the 0 init of i actually affect the warning given? i is unconditionally init to 1 at the start of the for loop, unless I need more coffee.
assert(0) should mean that reaching that branch is impossible. If it's in fact possible, then we could put default: i = 0; there instead, which is probably clearer that it's returning the error value.
2ed7dfd to
f06ee47
Compare
|
You were right on both counts, and the second suggestion turns out to be better than what the PR did. Reworked to follow it, in Measured,
The four that remain are an unrelated variable On your first question: yes, the zero-init of i did nothingYou were right that I checked rather than guessed. Of the three warnings the old approach removed, all three were So On your second: assert(0) is right, and the default should still assignThe But Both are kept: the assert still fires in a debug build, and the assignment makes the release path defined. default: assert(0) ; i = 0 ; break ;One thing your suggestion also reached that the old approach missed
That is also why the count lands at 4 rather than 5. VerificationRebased onto current
|
d6cb104 to
7b88e9a
Compare
nifti_mat44_to_orientation() and its two siblings assign i, j and k from three switches on ibest*pbest, jbest*qbest and kbest*rbest. The default arm fell through without assigning, leaving the variable holding the loop counter that last wrote it, which is not an orientation code. Assigning 0 there gives the fall-through a value outside the valid range 1..6 and says so at the point it happens, rather than initialising at the declaration where the reason is no longer visible. Under -Wconditional-uninitialized the tree goes from 11 warnings to 4, and the four that remain are an unrelated variable. Co-Authored-By: Sean McBride <sean@rogue-research.com> (cherry picked from commit 7b88e9a)
7b88e9a to
14f072a
Compare
nifti_mat44_to_orientation() and its dmat44 twin end with
where i, j and k are each assigned only inside a switch whose default arm
is assert(0). Under NDEBUG -- which is to say in every release build --
that arm compiles to nothing, so an unexpected switch value falls through
and the function writes an indeterminate value into the caller's
orientation code. k was already declared
k=0, so somebody hit thisonce and fixed a third of it. i and j now match.
Found by clang's -Wconditional-uninitialized.
Interface impact: none. On the union of all these changes, configured with
USE_FSL_CODE=ONandUSE_CIFTI_CODE=ON: all 448 exported symbols acrosslibniftiio,libnifti2,libznz,libfslio,libnifticdfandlibciftiare identical tomasterundernm -D --defined-only, and all ten installed headers are identical undergcc -E -P. Undergcc -dM -Eone macro definition differs, intentionally and only in text: #61 makesFSL_RADIOLOGICALread(-1)so it is safe inside an expression. Its value is still-1, checked by compiling against each installedfslio.hand printing it.Verification. This branch: builds with gcc 16.1.1,
ctestunchanged frommaster(2 of 345 fail onmasteritself in this environment; #31 and #29 each fix one). The union of all the PRs: 0 errors under both gcc 16.1.1 and clang 22.1.8,ctest345/345 under each, and the whole suite under valgrind memcheck with--trace-children=yesgives 484 traced processes with no invalid access, no uninitialised value and no leak in any nifti binary.Coordination. Every line of every branch was compared, whitespace-normalised, against the diffs of the open PRs (#11, #21, #22, #23, #24). Where one of those already changes a line, the line was left alone, and the few deliberate overlaps are named in the text above. What survives is 17 compiler warnings, all of them on those lines: 9
-Wsign-conversion(5 infslio.cfor #22, 2 innifti2_io.cand 2 innifti_tester001.cfor #24) and 8-Wcalloc-transposed-argsinnifti_findhdrnameandnifti_findimgname, which #11 rewrites. No formatting changes appear anywhere, to stay clear of #10 and #12.One of a set of independent, single-purpose PRs. Each bases on
masterand can be merged on its own, in any order.The full set of PRs (35)
The union of all of them is on the fork as
all-changes, if you want to build and test the lot at once.CI and build
Configuration and documentation
Defects
Warning and check classes