InsightSoftwareConsortium / InsightSoftwareConsortium/ITK
UBSan finds invalid cast in itkPeriodicBoundaryCondition.hxx
- Dominant language
- C++
- Stars
- 1.7k
- Forks
- 748
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 64
Description
Building current itk master using clang UBSan (undefined behaviour sanitizer) I get this error from the `itkPeriodicBoundaryConditionTest` test:
```
/ITK/Modules/Core/Common/include/itkPeriodicBoundaryCondition.hxx:60:17: runtime error: member call on address 0x00016d7da420 which does not point to an object of type 'itk::ConstNeighborhoodIterator, itk::PeriodicBoundaryCondition, itk::Image>>'
```
It's from [this code](https://github.com/InsightSoftwareConsortium/ITK/blob/4d592ddc293191a5e615b7fa22b9cce650cc00ef/Modules/Core/Common/include/itkPeriodicBoundaryCondition.hxx#L34):
```
namespace itk
{
template
typename PeriodicBoundaryCondition::OutputPixelType
PeriodicBoundaryCondition::operator()(const OffsetType & point_index,
const OffsetType & boundary_offset,
const NeighborhoodType * data) const
{
// This is guaranteed to be called with an object that is using
// PeriodicBoundaryCondition
const auto * iterator = reinterpret_cast *>(data);
```
If you change that to `dynamic_cast` and `assert` the result, you'll see it's null. (That's a way to repro/debug without UBSan).
Alas, I don't know this code enough to debug further...
Contributor guide
Assessment
This issue has not been assessed yet.