From b10e86f3ace161ebf30d6df10760926c7497d430 Mon Sep 17 00:00:00 2001 From: Bram Stolk Date: Fri, 27 Sep 2024 04:03:49 -0700 Subject: [PATCH] fix(pnm): Initialize m_pfm_flip before use to avoid UB. (#4446) 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 --- src/pnm.imageio/pnminput.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pnm.imageio/pnminput.cpp b/src/pnm.imageio/pnminput.cpp index dfcc38c3b3..1b08c0d35e 100644 --- a/src/pnm.imageio/pnminput.cpp +++ b/src/pnm.imageio/pnminput.cpp @@ -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;