Skip to content

Commit

Permalink
COMP: Fix gcc 13.2 compiler warning of large allocation size
Browse files Browse the repository at this point in the history
ITK/Modules/Segmentation/LevelSets/include/itkParallelSparseFieldLevelSetImageFilter.hxx: In member function ‘ThreadedAllocateData’:
ITK/Modules/Segmentation/LevelSets/include/itkParallelSparseFieldLevelSetImageFilter.hxx:789:49: warning: argument 1 value ‘18446744073709551615’ exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
  789 |   m_Data[ThreadId].m_LoadTransferBufferLayers = new LayerListType[2 * m_NumberOfLayers + 1];
      |                                                 ^
/usr/include/c++/13/new:128:26: note: in a call to allocation function ‘operator new []’ declared here
  128 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |                          ^
ITK/Modules/Segmentation/LevelSets/include/itkParallelSparseFieldLevelSetImageFilter.hxx: In member function ‘ThreadedAllocateData’:
ITK/Modules/Segmentation/LevelSets/include/itkParallelSparseFieldLevelSetImageFilter.hxx:789:49: warning: argument 1 value ‘18446744073709551615’ exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
  789 |   m_Data[ThreadId].m_LoadTransferBufferLayers = new LayerListType[2 * m_NumberOfLayers + 1];
      |                                                 ^
/usr/include/c++/13/new:128:26: note: in a call to allocation function ‘operator new []’ declared here
  128 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
      |
  • Loading branch information
hjmjohnson committed May 2, 2024
1 parent 9704108 commit 95f966e
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,9 @@ ParallelSparseFieldLevelSetImageFilter<TInputImage, TOutputImage>::ThreadedAlloc
m_Data[ThreadId].m_Semaphore[0] = 0;
m_Data[ThreadId].m_Semaphore[1] = 0;

const std::size_t bufferLayerSize = 2 * m_NumberOfLayers + 1;
// Allocate the layers for the sparse field.
m_Data[ThreadId].m_Layers.reserve(2 * m_NumberOfLayers + 1);
m_Data[ThreadId].m_Layers.reserve(bufferLayerSize);
for (unsigned int i = 0; i < 2 * static_cast<unsigned int>(m_NumberOfLayers) + 1; ++i)
{
m_Data[ThreadId].m_Layers.push_back(LayerType::New());
Expand All @@ -785,7 +786,8 @@ ParallelSparseFieldLevelSetImageFilter<TInputImage, TOutputImage>::ThreadedAlloc
}

// Layers used as buffers for transferring pixels during load balancing
m_Data[ThreadId].m_LoadTransferBufferLayers = new LayerListType[2 * m_NumberOfLayers + 1];

m_Data[ThreadId].m_LoadTransferBufferLayers = new LayerListType[bufferLayerSize];
for (unsigned int i = 0; i < 2 * static_cast<unsigned int>(m_NumberOfLayers) + 1; ++i)
{
m_Data[ThreadId].m_LoadTransferBufferLayers[i].reserve(m_NumOfWorkUnits);
Expand All @@ -802,8 +804,7 @@ ParallelSparseFieldLevelSetImageFilter<TInputImage, TOutputImage>::ThreadedAlloc

// The SAFETY_FACTOR simple ensures that the number of nodes created
// is larger than those required to start with for each thread.
auto nodeNum =
static_cast<unsigned int>(SAFETY_FACTOR * m_Layers[0]->Size() * (2 * m_NumberOfLayers + 1) / m_NumOfWorkUnits);
auto nodeNum = static_cast<unsigned int>(SAFETY_FACTOR * m_Layers[0]->Size() * (bufferLayerSize) / m_NumOfWorkUnits);

m_Data[ThreadId].m_LayerNodeStore->Reserve(nodeNum);
m_Data[ThreadId].m_RMSChange = m_ValueZero;
Expand Down

0 comments on commit 95f966e

Please sign in to comment.