Skip to content

Commit

Permalink
Add assert to ensure loop termination
Browse files Browse the repository at this point in the history
Signed-off-by: 胡玮文 <[email protected]>
  • Loading branch information
huww98 committed Jan 14, 2023
1 parent 55bdfd1 commit ffdd48b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib/OpenEXR/ImfMisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <ImfStdIO.h>
#include <ImfTileDescription.h>
#include <ImfXdr.h>
#include <cassert>

OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER

Expand Down Expand Up @@ -275,6 +276,10 @@ copyIntoFrameBuffer (
//
endPtr += xStride;

// Make sure the copy loop below will terminate.
assert ((endPtr - writePtr) / xStride > 0);
assert ((endPtr - writePtr) % xStride == 0);

if (fill)
{
//
Expand Down Expand Up @@ -1533,6 +1538,11 @@ copyFromFrameBuffer (
char* localWritePtr = writePtr;
const char* localReadPtr = readPtr;
endPtr += xStride;

// Make sure the copy loop below will terminate.
assert ((endPtr - localReadPtr) / xStride > 0);
assert ((endPtr - localReadPtr) % xStride == 0);

//
// Copy a horizontal row of pixels from a frame
// buffer to an output file's line or tile buffer.
Expand Down

0 comments on commit ffdd48b

Please sign in to comment.