diff --git a/chunkedstorage.cc b/chunkedstorage.cc index 69b155fe..26e32cde 100644 --- a/chunkedstorage.cc +++ b/chunkedstorage.cc @@ -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( [ & ] { diff --git a/chunkedstorage.hh b/chunkedstorage.hh index b92c6aed..4132e30b 100644 --- a/chunkedstorage.hh +++ b/chunkedstorage.hh @@ -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