From 4891a9568856bb775d0889b47c3808880803423b Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Wed, 15 Apr 2020 04:26:14 -0700 Subject: [PATCH] Fix corrupted memory cards --- lib/kabufuda/BlockAllocationTable.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/kabufuda/BlockAllocationTable.cpp b/lib/kabufuda/BlockAllocationTable.cpp index 2a16951..25939f7 100644 --- a/lib/kabufuda/BlockAllocationTable.cpp +++ b/lib/kabufuda/BlockAllocationTable.cpp @@ -23,7 +23,8 @@ void BlockAllocationTable::updateChecksum() { } bool BlockAllocationTable::valid() const { - uint16_t ckSum, ckSumInv; + uint16_t ckSum = 0; + uint16_t ckSumInv = 0; const_cast(*this).swapEndian(); calculateChecksumBE(reinterpret_cast(raw.data() + 4), 0xFFE, &ckSum, &ckSumInv); bool res = (ckSum == m_checksum && ckSumInv == m_checksumInv); @@ -32,7 +33,12 @@ bool BlockAllocationTable::valid() const { } BlockAllocationTable::BlockAllocationTable(uint32_t blockCount) -: m_freeBlocks{uint16_t(blockCount - FSTBlocks)}, m_lastAllocated{4} { +: m_checksum{0} +, m_checksumInv{0} +, m_updateCounter{0} +, m_freeBlocks{uint16_t(blockCount - FSTBlocks)} +, m_lastAllocated{4} +, m_map{{0}} { updateChecksum(); }