Fixed some warnings from the new cppcheck 2.19 - #23
Conversation
seanm
commented
Jan 14, 2026
- duplicateBreak,fsliolib/fslio.c:812,style,Consecutive return, break, continue, goto or throw statements are unnecessary.
- duplicateBreak,fsliolib/fslio.c:2095,style,Consecutive return, break, continue, goto or throw statements are unnecessary.
- nullPointerOutOfMemory,nifticdf/nifticdf.c:11053,warning,If memory allocation fails, then there is a possible null pointer dereference: upt
Closed PR Comment#26 includes the two Worth noting the assumption explicitly, since #26 also removes The third hunk, the #26 also generalises the class — nine allocations whose result was dereferenced within a line or two without a check, in Same offer as on #22: merge first and I will rebase, or close as covered. |
cafe3fb to
3af9a77
Compare
3af9a77 to
cf340f4
Compare
cf340f4 to
ad38c82
Compare
|
Rebased onto current The Rebase
Commit messagesThe single commit
No regression test — and why
The FSLIOERR question a maintainer should settle#define FSLIOERR(x) { fprintf(stderr,"Error:: %s\n",(x)); fflush(stderr); exit(EXIT_FAILURE); }
Two coherent positions:
I have not chosen for you — the Build and testmacOS/arm64, Ninja, Release, |
cppcheck 2.19 nullPointerOutOfMemory: the uppercase copy of the name was written into an unchecked malloc result. Return -1, the same value the function already uses for an unrecognized name.
cppcheck 2.19 unreachableCode: FSLIOERR ends in exit(EXIT_FAILURE), so the return statements following it in FslReadAllVolumes and FslReadHeader can never run.
ad38c82 to
a14818f
Compare
|
The objection previously raised against this PR is withdrawn. Rebased onto current Why the earlier objection no longer appliesThe concern was that these returns are unreachable only because the macro never returns, and that deleting them would make a later change to That change is now settled as one that will not happen. The measurement behind the decision: 71 So the returns are dead, and deleting dead code is the right call. Commit 1: the nifticdf allocation check unam = (char *)malloc(strlen(name)+1);
+ if (!unam)
+ return -1 ;
strcpy(unam,name);Correct and minimal. Independent of the Commit 2: the unreachable returnsBoth sites are braced, so this is a plain deletion with no effect on control flow: if (fslio->niftiptr == NULL) {
FSLIOERR("FslReadAllVolumes: error reading NIfTI image");
- return(NULL);
}
FslSetFileType(fslio,fslio->niftiptr->nifti_type);One thing worth seeing rather than glossing: after the deletion, the line following the block dereferences the pointer the block just found to be NULL. That is correct only because Test coverageNo test is added, and none applies:
Manufacturing a test for either would produce one that passes identically with and without the change. Verification
|
f5f3766
into
InsightSoftwareConsortium:master