1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00

Fixed possible crash when the cache wouldn't accept the new item

This commit is contained in:
Martin Tůma 2019-05-12 01:23:18 +02:00
parent 5cd0a3a8b0
commit 8f799e1bcf
3 changed files with 11 additions and 14 deletions

View File

@ -230,20 +230,18 @@ template<class T> bool IMG::readValue(T &val)
return true; return true;
} }
QByteArray IMG::readBlock(int blockNum) bool IMG::readBlock(int blockNum, QByteArray &data)
{ {
QByteArray *block = _blockCache[blockNum]; QByteArray *block = _blockCache[blockNum];
if (!block) { if (!block) {
if (!_file.seek((qint64)blockNum * (qint64)_blockSize)) if (!_file.seek((qint64)blockNum * (qint64)_blockSize))
return QByteArray(); return false;
QByteArray *ba = new QByteArray(); data.resize(_blockSize);
ba->resize(_blockSize); if (read(data.data(), _blockSize) < _blockSize)
if (read(ba->data(), _blockSize) < _blockSize) { return false;
delete ba; _blockCache.insert(blockNum, new QByteArray(data));
return QByteArray();
}
_blockCache.insert(blockNum, ba);
return *ba;
} else } else
return *block; data = *block;
return true;
} }

View File

@ -65,7 +65,7 @@ private:
typedef RTree<VectorTile*, double, 2> TileTree; typedef RTree<VectorTile*, double, 2> TileTree;
int blockSize() const {return _blockSize;} int blockSize() const {return _blockSize;}
QByteArray readBlock(int blockNum); bool readBlock(int blockNum, QByteArray &data);
qint64 read(char *data, qint64 maxSize); qint64 read(char *data, qint64 maxSize);
template<class T> bool readValue(T &val); template<class T> bool readValue(T &val);

View File

@ -33,8 +33,7 @@ bool SubFile::seek(Handle &handle, quint32 pos) const
if (handle.blockNum != blockNum) { if (handle.blockNum != blockNum) {
if (blockNum >= _blocks.size()) if (blockNum >= _blocks.size())
return false; return false;
handle.data = _img->readBlock(_blocks.at(blockNum)); if (!_img->readBlock(_blocks.at(blockNum), handle.data))
if (handle.data.isNull())
return false; return false;
handle.blockNum = blockNum; handle.blockNum = blockNum;
} }