map nullptr check

This commit is contained in:
Xiao YiFang 2022-06-17 20:37:59 +08:00
parent fa72de7b17
commit 2f3af9d7d3
2 changed files with 5 additions and 1 deletions

View file

@ -139,6 +139,8 @@ char * Reader::getBlock( uint32_t address, vector< char > & chunk )
// file.seek( offsets[ chunkIdx ] );
Mutex::Lock _( file.lock );
auto bytes = file.map( offsets[ chunkIdx ], 8 );
if( bytes == nullptr )
throw mapFailed();
auto qBytes = QByteArray::fromRawData( reinterpret_cast< char * >(bytes), 8 );
QDataStream in( qBytes );
in.setByteOrder( QDataStream::LittleEndian );
@ -153,7 +155,8 @@ char * Reader::getBlock( uint32_t address, vector< char > & chunk )
// vector< unsigned char > compressedData( compressedSize );
auto chunkDataBytes = file.map( offsets[ chunkIdx ] + 8, compressedSize );
if( chunkDataBytes == nullptr )
throw mapFailed();
// file.read( &compressedData.front(), compressedData.size() );
auto autoUnmap = qScopeGuard(
[ & ] {

View file

@ -25,6 +25,7 @@ DEF_EX( Ex, "Chunked storage exception", std::exception )
DEF_EX( exFailedToCompressChunk, "Failed to compress a chunk", Ex )
DEF_EX( exAddressOutOfRange, "The given chunked address is out of range", Ex )
DEF_EX( exFailedToDecompressChunk, "Failed to decompress a chunk", Ex )
DEF_EX( mapFailed, "Failed to map/unmap the file", Ex )
/// This class writes data blocks in chunks.
class Writer