Skip to content

Commit

Permalink
Fix target step calculation avoiding integer overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
pnorbert committed Jan 26, 2022
1 parent d9d98b4 commit 4fbeca5
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions source/adios2/engine/bp5/BP5Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,14 +682,16 @@ uint64_t BP5Writer::CountStepsInMetadataIndex(format::BufferSTL &bufferSTL)
}

unsigned int targetStep = 0;
if (m_Parameters.AppendAfterSteps + static_cast<int>(availableSteps) < 0)
{
targetStep = 0;
}
else if (m_Parameters.AppendAfterSteps < 0)

if (m_Parameters.AppendAfterSteps < 0)
{
// -1 means last step
targetStep = availableSteps + m_Parameters.AppendAfterSteps + 1;
// -1 means append after last step
int s = (int)availableSteps + m_Parameters.AppendAfterSteps + 1;
if (s < 0)
{
s = 0;
}
targetStep = static_cast<unsigned int>(s);
}
else
{
Expand Down

0 comments on commit 4fbeca5

Please sign in to comment.