Repository navigation
COMP: Address scan-build warnings - #5940
Merged
hjmjohnson merged 17 commits intoMar 16, 2026
Merged
hjmjohnson merged 17 commits into
hjmjohnson merged 17 commits into
Conversation
dzenanz
approved these changes
Mar 13, 2026
hjmjohnson
force-pushed
the
1261-scan-build-warnings
branch
2 times, most recently
from
March 13, 2026 14:23
9527b5a to
0525edc
Compare
hjmjohnson
force-pushed
the
1261-scan-build-warnings
branch
from
March 13, 2026 16:21
cb6f4eb to
c68b2c8
Compare
N-Dekker
reviewed
Mar 13, 2026
hjmjohnson
force-pushed
the
1261-scan-build-warnings
branch
4 times, most recently
from
March 13, 2026 18:25
5f1ace3 to
356b689
Compare
hjmjohnson
marked this pull request as ready for review
March 13, 2026 19:05
hjmjohnson
force-pushed
the
1261-scan-build-warnings
branch
from
March 13, 2026 22:32
356b689 to
c50738e
Compare
dzenanz
reviewed
Mar 13, 2026
| { | ||
| itkExceptionMacro("TIFF palette images require at most 16 bits per sample, but got " << bps); | ||
| } | ||
| const tmsize_t array_size = (tmsize_t{ 1 } << bps) * sizeof(uint16_t); |
Member
There was a problem hiding this comment.
The commit message sounds outrageous. Is this correct? @issakomi @malaterre
1. Silences the cplusplus.Move checker for these intentional accesses and silences the corresponding clang-tidy bugprone-use-after-move check 2. Keeps the valuable test logic that verifies move semantics are implemented properly
When TestQECellInterface is called with a 0-vertex QEPolygonCellType, `new PointIdentifier[0]` produces a zero-sized heap allocation. While technically valid C++, any dereference would be undefined behavior. The clang static analyzer (cplusplus.NewDelete) correctly flags this as "Use of memory allocated with size zero." Wrap the allocation, population, and SetPointIds/iterator exercise block in a `numberOfPoints > 0` guard. The 0-vertex case still exercises the empty-cell iterator paths earlier in the function. Addresses cplusplus.NewDelete finding from issue InsightSoftwareConsortium#1261. Co-Authored-By: Claude Opus 4.6 <[email protected]>
The base class ReadHeader returns nullptr, and subclass overrides may also return null without throwing. Two call sites in ReadImageInformation dereference the result without null checks: 1. m_ImageHeader->modality (line 140) — null dereference when ReadHeader fails silently. Now throws itkExceptionMacro on null return. 2. curImageHeader->examNumber (line 223) — null dereference in the directory scan loop. Now skips null results with continue. Addresses nullability.NullPassedToNonnull and core.NullDereference findings from issue InsightSoftwareConsortium#1261.
The Singleton<T>() template used `new T` (default-initialization) which
leaves POD types like bool and unsigned int with indeterminate values.
While the itkGetGlobalInitializeMacro immediately assigns the intended
value on first creation, the analyzer cannot trace through the singleton
index indirection and correctly flags the intermediate indeterminate
state.
Change to `new T{}` (value-initialization) which zero-initializes POD
types, eliminating undefined behavior and resolving:
- core.uninitialized.UndefReturn in itkDataObject.cxx:142
- core.uninitialized.UndefReturn in itkObject.cxx:452
- core.uninitialized.UndefReturn in itkMetaImageIO.cxx:940
- core.UndefinedBinaryOperatorResult in itkDataObject.cxx:131
Addresses scan-build findings from issue InsightSoftwareConsortium#1261.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
AllocateTiffPalette had two bugs on the array_size computation:
1. Operator precedence: `tmsize_t{1} << bps * sizeof(uint16_t)` was
parsed as `1 << (bps * 2)` instead of `(1 << bps) * sizeof(uint16_t)`.
For bps=8 this over-allocated 128x; for bps=16 it attempted ~4GB.
2. Undefined behavior: with bps=32 (float), the shift amount was 64,
which is UB for a 64-bit type. The TIFF spec limits palette images
to at most 16 bits per sample but this was not enforced.
Add a bps > 16 guard (with itkExceptionMacro) and fix parentheses
to compute the intended allocation size.
Addresses core.BitwiseShift finding from issue InsightSoftwareConsortium#1261.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
…test Cache GetNumberOfPoints() result and value-initialize dynamically allocated PointIdentifier arrays to fix core.CallAndMessage warnings from clang static analyzer about uninitialized values passed to SetPointIds/InternalSetPointIds. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Move the `numberOfElements == 0` check before the size-mismatch check in CalculateFitError to help the clang static analyzer verify the division-by-zero guard on line 55. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Remove three dead store patterns flagged by clang scan-build: - itkPoolMultiThreader.cxx: discard unused return from GetSplit() after the work-unit loop (side effect on iRegion is what matters) - itkCSVFileReaderBase.cxx: remove trailing OnANewLine=false at end of scope where the local is never read again - itkGiftiMeshIO.cxx: remove assignments to compType/pixelType in switch default cases that unconditionally throw Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Use `if (testStatus != EXIT_SUCCESS)` to ensure test failures are correctly detected and reported. - Replace dead stores and improve the consistency of test status handling by using bitwise OR (`|=`) for cumulative test statuses. - Add failure return conditions for helper functions to avoid unreported test failures. - Replace uninitialized variables with `const` initialization for clarity and safety against potential unintended usage.
The second verification loop used a hardcoded bound of 10, which exceeds NumberOfSteps() for small Hilbert orders (e.g., order=1 in 2D has only 4 steps). Replace with path->NumberOfSteps() to match the actual path size. Co-Authored-By: Claude Opus 4.6 <[email protected]>
The helper function had two pre-existing bugs exposed by the |= accumulation fix: 1. The FloatAlmostEqual check was inverted (set pass=false when values ARE equal). Since ULP comparison never matched the optimizer's approximate convergence, this was effectively dead code. Replace with std::abs tolerance check (1e-2). 2. The GetCurrentIteration()>0 check was intended only for the zero-iterations case but ran for all calls. Guard it with a numberOfIterations==0 condition. Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Eliminated a dead store in `itkLevelSetDenseImageTest.cxx`. - Updated `theoreticalValue` and `value` variables to use `const` for clarity and safety.
- Eliminated duplicate statements for `optimizerInitialRadius` and `filter->SetOptimizerInitialRadius` to improve clarity and prevent unnecessary operations.
- Removed unnecessary `start = &x[0]` assignment to improve test code clarity and avoid dead store.
- Replace repetitive try-catch blocks with `ITK_TRY_EXPECT_EXCEPTION` macros for improved clarity and maintainability.
Replace raw `new PointIdentifier[]` with `std::vector<PointIdentifier>` and `std::iota` in TestCellInterface and TestQECellInterface. This resolves core.CallAndMessage scan-build findings where the analyzer could not verify value-initialization of raw new[] arrays. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Warns if std::move is applied to a forwarding reference (a T&& parameter where T is a deduced template type). In such cases std::forward should be used instead, to preserve the value category of the argument.
hjmjohnson
force-pushed
the
1261-scan-build-warnings
branch
from
March 13, 2026 23:48
c50738e to
14c265b
Compare
Member
Author
|
Arm failures fixed in previously merged PR. |
hjmjohnson
added a commit
to hjmjohnson/ITK
that referenced
this pull request
May 6, 2026
…1-scan-build-warnings COMP: Address scan-build warnings
hjmjohnson
added a commit
to hjmjohnson/ITK
that referenced
this pull request
May 12, 2026
…1-scan-build-warnings COMP: Address scan-build warnings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cplusplus.Movewarning initkArray2DGTest.cxxmove-semantics tests that deliberately verify moved-from object statecplusplus.NewDeletezero-sized allocation initkQuadEdgeMeshCellInterfaceTest.cxxby guarding withnumberOfPoints > 0cplusplus.NewDeletefindings initkSmartPointer.hare confirmed false positives (refcount prevents use-after-free); no code change neededTest plan
ITKCommonGTestDriverbuilds and allArray2D.*tests passITKQuadEdgeMeshTestDriverbuilds anditkQuadEdgeMeshCellInterfaceTestpassesAddresses #1261 (scan-build report comment)
🤖 Generated with Claude Code