1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00

Fixed error handling

This commit is contained in:
Martin Tůma 2021-03-19 20:09:11 +01:00
parent a4648020d9
commit 8196b96f65
4 changed files with 29 additions and 34 deletions

View File

@ -26,4 +26,16 @@ inline quint8 bs(const quint8 val)
return (val + 7) >> 3; return (val + 7) >> 3;
} }
inline quint8 byteSize(quint32 val)
{
quint8 ret = 0;
do {
ret++;
val = val >> 8;
} while (val != 0);
return ret;
}
#endif // GARMIN_H #endif // GARMIN_H

View File

@ -55,18 +55,6 @@ static QString capitalized(const QString &str)
return ret; return ret;
} }
static quint8 byteSize(quint32 val)
{
quint8 ret = 0;
do {
ret++;
val = val >> 8;
} while (val != 0);
return ret;
}
LBLFile::~LBLFile() LBLFile::~LBLFile()
{ {

View File

@ -381,7 +381,7 @@ bool NETFile::load(Handle &hdl, const RGNFile *rgn, Handle &rgnHdl)
&& readUInt32(hdl, _size) && readByte(hdl, &_shift))) && readUInt32(hdl, _size) && readByte(hdl, &_shift)))
return false; return false;
if (hdrLen >= 0x47) { if (hdrLen >= 0x4C) {
quint32 info; quint32 info;
if (!(seek(hdl, _gmpOffset + 0x37) && readUInt32(hdl, info))) if (!(seek(hdl, _gmpOffset + 0x37) && readUInt32(hdl, info)))
return false; return false;
@ -389,7 +389,7 @@ bool NETFile::load(Handle &hdl, const RGNFile *rgn, Handle &rgnHdl)
&& readUInt32(hdl, _linksSize) && readByte(hdl, &_linksShift))) && readUInt32(hdl, _linksSize) && readByte(hdl, &_linksShift)))
return false; return false;
quint8 tableId = ((info >> 2) & 0xF); quint8 tableId = ((info >> 2) & 0x0F);
if (_linksSize && (!rgn->huffmanTable() || rgn->huffmanTable()->id() if (_linksSize && (!rgn->huffmanTable() || rgn->huffmanTable()->id()
!= tableId)) { != tableId)) {
_huffmanTable = new HuffmanTable(tableId); _huffmanTable = new HuffmanTable(tableId);

View File

@ -88,30 +88,25 @@ bool NODFile::load(Handle &hdl)
if (!(seek(hdl, _gmpOffset) && readUInt16(hdl, hdrLen))) if (!(seek(hdl, _gmpOffset) && readUInt16(hdl, hdrLen)))
return false; return false;
if (hdrLen < 0x7b)
return true;
if (!(seek(hdl, _gmpOffset + 0x1d) && readUInt32(hdl, _flags) if (hdrLen >= 0x7F) {
&& readByte(hdl, &_blockShift) && readByte(hdl, &_nodeShift))) if (!(seek(hdl, _gmpOffset + 0x1d) && readUInt32(hdl, _flags)
return false; && readByte(hdl, &_blockShift) && readByte(hdl, &_nodeShift)))
return false;
if (!(seek(hdl, _gmpOffset + 0x67) && readUInt32(hdl, _blockOffset) if (!(seek(hdl, _gmpOffset + 0x67) && readUInt32(hdl, _blockOffset)
&& readUInt32(hdl, _blockSize) && readUInt16(hdl, _blockRecordSize) && readUInt32(hdl, _blockSize) && readUInt16(hdl, _blockRecordSize)
&& readUInt32(hdl, _indexOffset) && readUInt32(hdl, _indexSize) && readUInt32(hdl, _indexOffset) && readUInt32(hdl, _indexSize)
&& readUInt16(hdl, _indexRecordSize) && readUInt32(hdl, _indexFlags))) && readUInt16(hdl, _indexRecordSize) && readUInt32(hdl, _indexFlags)))
return false; return false;
if (!_indexRecordSize) if (!_indexRecordSize || _indexSize < _indexRecordSize)
return false; return false;
quint32 indexCount = _indexSize / _indexRecordSize; quint32 indexCount = _indexSize / _indexRecordSize;
if (indexCount <= 0x100) _indexIdSize = byteSize(indexCount - 1);
_indexIdSize = 1; }
else if (indexCount <= 0x1000)
_indexIdSize = 2;
else if (indexCount <= 0x1000000)
_indexIdSize = 3;
return (_indexIdSize > 0); return true;
} }
bool NODFile::readBlock(Handle &hdl, quint32 blockOffset, bool NODFile::readBlock(Handle &hdl, quint32 blockOffset,