1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +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;
}
QByteArray IMG::readBlock(int blockNum)
bool IMG::readBlock(int blockNum, QByteArray &data)
{
QByteArray *block = _blockCache[blockNum];
if (!block) {
if (!_file.seek((qint64)blockNum * (qint64)_blockSize))
return QByteArray();
QByteArray *ba = new QByteArray();
ba->resize(_blockSize);
if (read(ba->data(), _blockSize) < _blockSize) {
delete ba;
return QByteArray();
}
_blockCache.insert(blockNum, ba);
return *ba;
return false;
data.resize(_blockSize);
if (read(data.data(), _blockSize) < _blockSize)
return false;
_blockCache.insert(blockNum, new QByteArray(data));
} else
return *block;
data = *block;
return true;
}

View File

@ -65,7 +65,7 @@ private:
typedef RTree<VectorTile*, double, 2> TileTree;
int blockSize() const {return _blockSize;}
QByteArray readBlock(int blockNum);
bool readBlock(int blockNum, QByteArray &data);
qint64 read(char *data, qint64 maxSize);
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 (blockNum >= _blocks.size())
return false;
handle.data = _img->readBlock(_blocks.at(blockNum));
if (handle.data.isNull())
if (!_img->readBlock(_blocks.at(blockNum), handle.data))
return false;
handle.blockNum = blockNum;
}