Skip to content

Commit

Permalink
STYLE: Declare local value in BMPImageIO::Read as unique_ptr<char[]>
Browse files Browse the repository at this point in the history
Similar to pull request #3619
commit e2b7445 "STYLE: Declare local `buffer`
in `GE5ImageIO::ReadHeader` as unique_ptr"
  • Loading branch information
N-Dekker authored and hjmjohnson committed Oct 12, 2022
1 parent f4f126d commit d666520
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions Modules/IO/BMP/src/itkBMPImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*=========================================================================*/
#include "itkBMPImageIO.h"
#include "itkByteSwapper.h"
#include "itkMakeUniqueForOverwrite.h"
#include "itksys/SystemTools.hxx"
#include <iostream>

Expand Down Expand Up @@ -171,7 +172,6 @@ BMPImageIO::Read(void * buffer)
{
auto * p = static_cast<char *>(buffer);
unsigned long l = 0;
char * value;

this->OpenFileForReading(m_Ifstream, m_FileName);

Expand All @@ -181,9 +181,9 @@ BMPImageIO::Read(void * buffer)
// https://msdn.microsoft.com/en-us/library/windows/desktop/dd183383%28v=vs.85%29.aspx
if (m_BMPCompression == 1 && (this->GetNumberOfComponents() == 3 || this->GetIsReadAsScalarPlusPalette()))
{
value = new char[m_BMPDataSize + 1];
const auto value = make_unique_for_overwrite<char[]>(m_BMPDataSize + 1);
m_Ifstream.seekg(m_BitMapOffset, std::ios::beg);
m_Ifstream.read((char *)value, m_BMPDataSize);
m_Ifstream.read(value.get(), m_BMPDataSize);

SizeValueType posLine = 0;
SizeValueType line = m_Dimensions[1] - 1;
Expand Down Expand Up @@ -288,13 +288,13 @@ BMPImageIO::Read(void * buffer)
{
paddedStreamRead = ((streamRead / 4) + 1) * 4;
}
value = new char[paddedStreamRead + 1];
const auto value = make_unique_for_overwrite<char[]>(paddedStreamRead + 1);

for (unsigned int id = 0; id < m_Dimensions[1]; ++id)
{
const unsigned int line_id = m_FileLowerLeft ? (m_Dimensions[1] - id - 1) : id;
m_Ifstream.seekg(m_BitMapOffset + paddedStreamRead * line_id, std::ios::beg);
m_Ifstream.read((char *)value, paddedStreamRead);
m_Ifstream.read(value.get(), paddedStreamRead);
for (long i = 0; i < streamRead; ++i)
{
if (this->GetNumberOfComponents() == 1)
Expand Down Expand Up @@ -331,7 +331,6 @@ BMPImageIO::Read(void * buffer)
}
}
}
delete[] value;
m_Ifstream.close();
}

Expand Down

0 comments on commit d666520

Please sign in to comment.