From 42b9ddaec69004b98ebaef6a2f889a85e5784245 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Tue, 26 Sep 2023 12:07:13 +0800 Subject: [PATCH] fix fatal CKStateChunk read error. fix return statement in CKFile --- LibCmo/CK2/CKFileReader.cpp | 4 ++-- LibCmo/CK2/CKFileWriter.cpp | 2 +- LibCmo/CK2/CKStateChunkReader.cpp | 10 +++++----- LibCmo/CK2/CKStateChunkWriter.cpp | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/LibCmo/CK2/CKFileReader.cpp b/LibCmo/CK2/CKFileReader.cpp index adc822e..8d2f235 100644 --- a/LibCmo/CK2/CKFileReader.cpp +++ b/LibCmo/CK2/CKFileReader.cpp @@ -17,7 +17,7 @@ namespace LibCmo::CK2 { CKERROR CKFileReader::ShallowLoad(CKSTRING u8_filename) { // check document status - if (this->m_Done) CKERROR::CKERR_CANCELLED; + if (this->m_Done) return CKERROR::CKERR_CANCELLED; // check file and open memory if (u8_filename == nullptr) return CKERROR::CKERR_INVALIDPARAMETER; @@ -334,7 +334,7 @@ namespace LibCmo::CK2 { CKERROR CKFileReader::DeepLoad(CKSTRING u8_filename) { // check document status - if (this->m_Done) CKERROR::CKERR_CANCELLED; + if (this->m_Done) return CKERROR::CKERR_CANCELLED; // ========== prepare work ========== CKERROR err = CKERROR::CKERR_OK; diff --git a/LibCmo/CK2/CKFileWriter.cpp b/LibCmo/CK2/CKFileWriter.cpp index 3045a9b..afb41d8 100644 --- a/LibCmo/CK2/CKFileWriter.cpp +++ b/LibCmo/CK2/CKFileWriter.cpp @@ -11,7 +11,7 @@ namespace LibCmo::CK2 { CKERROR CKFileWriter::Save(CKSTRING u8_filename) { // check document status - if (this->m_Done) CKERROR::CKERR_CANCELLED; + if (this->m_Done) return CKERROR::CKERR_CANCELLED; // encoding conv helper XContainer::XString name_conv; diff --git a/LibCmo/CK2/CKStateChunkReader.cpp b/LibCmo/CK2/CKStateChunkReader.cpp index 22fdf72..c1b93a4 100644 --- a/LibCmo/CK2/CKStateChunkReader.cpp +++ b/LibCmo/CK2/CKStateChunkReader.cpp @@ -57,11 +57,11 @@ namespace LibCmo::CK2 { } bool CKStateChunk::LockReadBuffer(const void** ppData, CKDWORD size_in_byte) { - // check arguments - if (*ppData == nullptr) return false; - *ppData = nullptr; // check self status if (this->m_Parser.m_Status != CKStateChunkStatus::READ) return false; + // check arguments + if (ppData == nullptr) return false; + *ppData = nullptr; // get corresponding size CKDWORD size_in_dword = this->GetCeilDwordSize(size_in_byte); @@ -94,7 +94,7 @@ namespace LibCmo::CK2 { } CKStateChunk::LockedReadBuffer_t CKStateChunk::LockReadBufferWrapper(CKDWORD size_in_byte) { - const void* pData; + const void* pData = nullptr; bool ret = LockReadBuffer(&pData, size_in_byte); if (ret) { return LockedReadBuffer_t(pData, LockedReadBufferDeleter(this, size_in_byte)); @@ -109,7 +109,7 @@ namespace LibCmo::CK2 { bool CKStateChunk::ReadByteData(void* data_ptr, CKDWORD size_in_byte) { if (data_ptr == nullptr) return false; - const void* pData; + const void* pData = nullptr; bool ret = LockReadBuffer(&pData, size_in_byte); if (ret) { std::memcpy(data_ptr, pData, size_in_byte); diff --git a/LibCmo/CK2/CKStateChunkWriter.cpp b/LibCmo/CK2/CKStateChunkWriter.cpp index b7e1a13..5b6714f 100644 --- a/LibCmo/CK2/CKStateChunkWriter.cpp +++ b/LibCmo/CK2/CKStateChunkWriter.cpp @@ -73,7 +73,7 @@ namespace LibCmo::CK2 { bool CKStateChunk::LockWriteBuffer(void** ppData, CKDWORD size_in_byte) { // same as LockReadBuffer with slight difference. if (this->m_Parser.m_Status != CKStateChunkStatus::WRITE) return false; - if (*ppData == nullptr) return false; + if (ppData == nullptr) return false; *ppData = nullptr; CKDWORD size_in_dword = this->GetCeilDwordSize(size_in_byte); @@ -102,7 +102,7 @@ namespace LibCmo::CK2 { CKStateChunk::LockedWriteBuffer_t CKStateChunk::LockWriteBufferWrapper(CKDWORD size_in_byte) { // same as LockReadBufferWrapper with slight difference. - void* pData; + void* pData = nullptr; bool ret = LockWriteBuffer(&pData, size_in_byte); if (ret) { return LockedWriteBuffer_t(pData, LockedWriteBufferDeleter(this, size_in_byte)); @@ -117,7 +117,7 @@ namespace LibCmo::CK2 { // same as ReadByteData with slight difference. if (data_ptr == nullptr) return false; - void* pData; + void* pData = nullptr; bool ret = LockWriteBuffer(&pData, size_in_byte); if (ret) { std::memcpy(pData, data_ptr, size_in_byte);