fix fatal CKStateChunk read error. fix return statement in CKFile
This commit is contained in:
parent
0a168ac5cc
commit
42b9ddaec6
|
@ -17,7 +17,7 @@ namespace LibCmo::CK2 {
|
||||||
|
|
||||||
CKERROR CKFileReader::ShallowLoad(CKSTRING u8_filename) {
|
CKERROR CKFileReader::ShallowLoad(CKSTRING u8_filename) {
|
||||||
// check document status
|
// check document status
|
||||||
if (this->m_Done) CKERROR::CKERR_CANCELLED;
|
if (this->m_Done) return CKERROR::CKERR_CANCELLED;
|
||||||
|
|
||||||
// check file and open memory
|
// check file and open memory
|
||||||
if (u8_filename == nullptr) return CKERROR::CKERR_INVALIDPARAMETER;
|
if (u8_filename == nullptr) return CKERROR::CKERR_INVALIDPARAMETER;
|
||||||
|
@ -334,7 +334,7 @@ namespace LibCmo::CK2 {
|
||||||
|
|
||||||
CKERROR CKFileReader::DeepLoad(CKSTRING u8_filename) {
|
CKERROR CKFileReader::DeepLoad(CKSTRING u8_filename) {
|
||||||
// check document status
|
// check document status
|
||||||
if (this->m_Done) CKERROR::CKERR_CANCELLED;
|
if (this->m_Done) return CKERROR::CKERR_CANCELLED;
|
||||||
|
|
||||||
// ========== prepare work ==========
|
// ========== prepare work ==========
|
||||||
CKERROR err = CKERROR::CKERR_OK;
|
CKERROR err = CKERROR::CKERR_OK;
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace LibCmo::CK2 {
|
||||||
|
|
||||||
CKERROR CKFileWriter::Save(CKSTRING u8_filename) {
|
CKERROR CKFileWriter::Save(CKSTRING u8_filename) {
|
||||||
// check document status
|
// check document status
|
||||||
if (this->m_Done) CKERROR::CKERR_CANCELLED;
|
if (this->m_Done) return CKERROR::CKERR_CANCELLED;
|
||||||
|
|
||||||
// encoding conv helper
|
// encoding conv helper
|
||||||
XContainer::XString name_conv;
|
XContainer::XString name_conv;
|
||||||
|
|
|
@ -57,11 +57,11 @@ namespace LibCmo::CK2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CKStateChunk::LockReadBuffer(const void** ppData, CKDWORD size_in_byte) {
|
bool CKStateChunk::LockReadBuffer(const void** ppData, CKDWORD size_in_byte) {
|
||||||
// check arguments
|
|
||||||
if (*ppData == nullptr) return false;
|
|
||||||
*ppData = nullptr;
|
|
||||||
// check self status
|
// check self status
|
||||||
if (this->m_Parser.m_Status != CKStateChunkStatus::READ) return false;
|
if (this->m_Parser.m_Status != CKStateChunkStatus::READ) return false;
|
||||||
|
// check arguments
|
||||||
|
if (ppData == nullptr) return false;
|
||||||
|
*ppData = nullptr;
|
||||||
|
|
||||||
// get corresponding size
|
// get corresponding size
|
||||||
CKDWORD size_in_dword = this->GetCeilDwordSize(size_in_byte);
|
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) {
|
CKStateChunk::LockedReadBuffer_t CKStateChunk::LockReadBufferWrapper(CKDWORD size_in_byte) {
|
||||||
const void* pData;
|
const void* pData = nullptr;
|
||||||
bool ret = LockReadBuffer(&pData, size_in_byte);
|
bool ret = LockReadBuffer(&pData, size_in_byte);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return LockedReadBuffer_t(pData, LockedReadBufferDeleter(this, size_in_byte));
|
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) {
|
bool CKStateChunk::ReadByteData(void* data_ptr, CKDWORD size_in_byte) {
|
||||||
if (data_ptr == nullptr) return false;
|
if (data_ptr == nullptr) return false;
|
||||||
|
|
||||||
const void* pData;
|
const void* pData = nullptr;
|
||||||
bool ret = LockReadBuffer(&pData, size_in_byte);
|
bool ret = LockReadBuffer(&pData, size_in_byte);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
std::memcpy(data_ptr, pData, size_in_byte);
|
std::memcpy(data_ptr, pData, size_in_byte);
|
||||||
|
|
|
@ -73,7 +73,7 @@ namespace LibCmo::CK2 {
|
||||||
bool CKStateChunk::LockWriteBuffer(void** ppData, CKDWORD size_in_byte) {
|
bool CKStateChunk::LockWriteBuffer(void** ppData, CKDWORD size_in_byte) {
|
||||||
// same as LockReadBuffer with slight difference.
|
// same as LockReadBuffer with slight difference.
|
||||||
if (this->m_Parser.m_Status != CKStateChunkStatus::WRITE) return false;
|
if (this->m_Parser.m_Status != CKStateChunkStatus::WRITE) return false;
|
||||||
if (*ppData == nullptr) return false;
|
if (ppData == nullptr) return false;
|
||||||
*ppData = nullptr;
|
*ppData = nullptr;
|
||||||
|
|
||||||
CKDWORD size_in_dword = this->GetCeilDwordSize(size_in_byte);
|
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) {
|
CKStateChunk::LockedWriteBuffer_t CKStateChunk::LockWriteBufferWrapper(CKDWORD size_in_byte) {
|
||||||
// same as LockReadBufferWrapper with slight difference.
|
// same as LockReadBufferWrapper with slight difference.
|
||||||
void* pData;
|
void* pData = nullptr;
|
||||||
bool ret = LockWriteBuffer(&pData, size_in_byte);
|
bool ret = LockWriteBuffer(&pData, size_in_byte);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return LockedWriteBuffer_t(pData, LockedWriteBufferDeleter(this, size_in_byte));
|
return LockedWriteBuffer_t(pData, LockedWriteBufferDeleter(this, size_in_byte));
|
||||||
|
@ -117,7 +117,7 @@ namespace LibCmo::CK2 {
|
||||||
// same as ReadByteData with slight difference.
|
// same as ReadByteData with slight difference.
|
||||||
if (data_ptr == nullptr) return false;
|
if (data_ptr == nullptr) return false;
|
||||||
|
|
||||||
void* pData;
|
void* pData = nullptr;
|
||||||
bool ret = LockWriteBuffer(&pData, size_in_byte);
|
bool ret = LockWriteBuffer(&pData, size_in_byte);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
std::memcpy(pData, data_ptr, size_in_byte);
|
std::memcpy(pData, data_ptr, size_in_byte);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user