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