Skip to content

Commit

Permalink
fix(pnm): Initialize m_pfm_flip before use to avoid UB. (#4446)
Browse files Browse the repository at this point in the history
Fixes #4445

This avoids UB by initializing a variable.

## Tests

I ran valgrind after the fix: no longer issues error.

```
==77256== 
==77256== HEAP SUMMARY:
==77256==     in use at exit: 25,167,390 bytes in 8,232 blocks
==77256==   total heap usage: 183,524 allocs, 175,292 frees, 4,415,783,216 bytes allocated
==77256== 
==77256== LEAK SUMMARY:
==77256==    definitely lost: 0 bytes in 0 blocks
==77256==    indirectly lost: 0 bytes in 0 blocks
==77256==      possibly lost: 0 bytes in 0 blocks
==77256==    still reachable: 25,167,390 bytes in 8,232 blocks
==77256==         suppressed: 0 bytes in 0 blocks
==77256== Rerun with --leak-check=full to see details of leaked memory
==77256== 
==77256== For lists of detected and suppressed errors, rerun with: -s
==77256== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
```

---

Signed-off-by: Bram Stolk <[email protected]>
  • Loading branch information
stolk authored and lgritz committed Sep 29, 2024
1 parent 0470526 commit b10e86f
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/pnm.imageio/pnminput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ PNMInput::open(const std::string& name, ImageSpec& newspec)
m_file_contents.resize(m_io->size());
m_io->pread(m_file_contents.data(), m_file_contents.size(), 0);
m_remaining = string_view(m_file_contents.data(), m_file_contents.size());
m_pfm_flip = false;

if (!read_file_header())
return false;
Expand Down

0 comments on commit b10e86f

Please sign in to comment.