Skip to content

Commit d666520

Browse files
N-Dekkerhjmjohnson
authored andcommitted
STYLE: Declare local value in BMPImageIO::Read as unique_ptr<char[]>
Similar to pull request #3619 commit e2b7445 "STYLE: Declare local `buffer` in `GE5ImageIO::ReadHeader` as unique_ptr"
1 parent f4f126d commit d666520

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

Modules/IO/BMP/src/itkBMPImageIO.cxx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*=========================================================================*/
1818
#include "itkBMPImageIO.h"
1919
#include "itkByteSwapper.h"
20+
#include "itkMakeUniqueForOverwrite.h"
2021
#include "itksys/SystemTools.hxx"
2122
#include <iostream>
2223

@@ -171,7 +172,6 @@ BMPImageIO::Read(void * buffer)
171172
{
172173
auto * p = static_cast<char *>(buffer);
173174
unsigned long l = 0;
174-
char * value;
175175

176176
this->OpenFileForReading(m_Ifstream, m_FileName);
177177

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

188188
SizeValueType posLine = 0;
189189
SizeValueType line = m_Dimensions[1] - 1;
@@ -288,13 +288,13 @@ BMPImageIO::Read(void * buffer)
288288
{
289289
paddedStreamRead = ((streamRead / 4) + 1) * 4;
290290
}
291-
value = new char[paddedStreamRead + 1];
291+
const auto value = make_unique_for_overwrite<char[]>(paddedStreamRead + 1);
292292

293293
for (unsigned int id = 0; id < m_Dimensions[1]; ++id)
294294
{
295295
const unsigned int line_id = m_FileLowerLeft ? (m_Dimensions[1] - id - 1) : id;
296296
m_Ifstream.seekg(m_BitMapOffset + paddedStreamRead * line_id, std::ios::beg);
297-
m_Ifstream.read((char *)value, paddedStreamRead);
297+
m_Ifstream.read(value.get(), paddedStreamRead);
298298
for (long i = 0; i < streamRead; ++i)
299299
{
300300
if (this->GetNumberOfComponents() == 1)
@@ -331,7 +331,6 @@ BMPImageIO::Read(void * buffer)
331331
}
332332
}
333333
}
334-
delete[] value;
335334
m_Ifstream.close();
336335
}
337336

0 commit comments

Comments
 (0)