Skip to content

Commit

Permalink
STYLE: Remove unreachable code from GE5ImageIO if (buffer == nullptr)
Browse files Browse the repository at this point in the history
In C++, `new char[N]` does not return a `nullptr`, it might just throw an
`std::bad_alloc` exception, in case of allocation failure. So there is no need
to do something like "if (buffer == nullptr) clean up and throw an exception".
  • Loading branch information
N-Dekker committed Sep 15, 2022
1 parent 2f2b29c commit 7482c80
Showing 1 changed file with 0 additions and 30 deletions.
30 changes: 0 additions & 30 deletions Modules/IO/GE/src/itkGE5ImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -255,22 +255,12 @@ GE5ImageIO::ReadHeader(const char * FileNameToRead)
if (pixelHdrFlag)
{
buffer = new char[imageHdr.GENESIS_IH_img_l_exam];
if (buffer == nullptr)
{
f.close();
itkExceptionMacro("GE5ImageIO:Unable to allocate memory for exam header!");
}
f.seekg(imageHdr.GENESIS_IH_img_p_exam, std::ios::beg);
f.read(buffer, imageHdr.GENESIS_IH_img_l_exam);
}
else
{
buffer = new char[GENESIS_EX_HDR_LEN];
if (buffer == nullptr)
{
f.close();
itkExceptionMacro("GE5ImageIO:Unable to allocate memory for exam header!");
}
f.seekg(GENESIS_EX_HDR_START, std::ios::beg);
f.read(buffer, GENESIS_EX_HDR_LEN);
}
Expand Down Expand Up @@ -314,22 +304,12 @@ GE5ImageIO::ReadHeader(const char * FileNameToRead)
if (pixelHdrFlag)
{
buffer = new char[imageHdr.GENESIS_IH_img_l_series];
if (buffer == nullptr)
{
f.close();
itkExceptionMacro("GE5ImageIO:Unable to allocate memory for series header!");
}
f.seekg(imageHdr.GENESIS_IH_img_p_series, std::ios::beg);
f.read(buffer, imageHdr.GENESIS_IH_img_l_series);
}
else
{
buffer = new char[GENESIS_SE_HDR_LEN];
if (buffer == nullptr)
{
f.close();
itkExceptionMacro("GE5ImageIO:Unable to allocate memory for series header!");
}
f.seekg(GENESIS_SE_HDR_START);
f.read(buffer, GENESIS_SE_HDR_LEN);
}
Expand All @@ -351,23 +331,13 @@ GE5ImageIO::ReadHeader(const char * FileNameToRead)
if (pixelHdrFlag)
{
buffer = new char[imageHdr.GENESIS_IH_img_l_image];
if (buffer == nullptr)
{
f.close();
itkExceptionMacro("GE5ImageIO:Unable to allocate memory for MR header!");
}
// Now seek to the MR header and read the data into the buffer.
f.seekg(imageHdr.GENESIS_IH_img_p_image, std::ios::beg);
f.read(buffer, imageHdr.GENESIS_IH_img_l_image);
}
else
{
buffer = new char[GENESIS_MR_HDR_LEN];
if (buffer == nullptr)
{
f.close();
itkExceptionMacro("GE5ImageIO:Unable to allocate memory for MR header!");
}
f.seekg(GENESIS_IM_HDR_START, std::ios::beg);
f.read(buffer, GENESIS_MR_HDR_LEN);
}
Expand Down

0 comments on commit 7482c80

Please sign in to comment.