mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
map nullptr check
This commit is contained in:
parent
fa72de7b17
commit
2f3af9d7d3
|
@ -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(
|
||||
[ & ] {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue