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

Some more error checking improvements/fixes

This commit is contained in:
Martin Tůma 2021-10-02 12:57:16 +02:00
parent 288aa195c0
commit b14dd23224
3 changed files with 14 additions and 12 deletions

View File

@ -1,6 +1,5 @@
#include "deltastream.h"
using namespace IMG;
static int bitSize(quint8 baseSize, bool variableSign, bool extraBit)
@ -19,21 +18,21 @@ static int bitSize(quint8 baseSize, bool variableSign, bool extraBit)
return bits;
}
DeltaStream::DeltaStream(const SubFile &file, SubFile::Handle &hdl,
quint32 length, quint8 info, bool extraBit, bool extended)
: BitStream1(file, hdl, length), _readBits(0xFFFFFFFF)
bool DeltaStream::init(quint8 info, bool extraBit, bool extended)
{
_extraBit = extraBit ? 1 : 0;
if (!(sign(_lonSign) && sign(_latSign)))
return;
return false;
if (extended) {
quint32 b;
if (!read(1, b))
return;
return false;
}
_lonBits = bitSize(info & 0x0F, !_lonSign, extraBit);
_latBits = bitSize(info >> 4, !_latSign, false);
_readBits = _lonBits + _latBits;
return true;
}
bool DeltaStream::readDelta(int bits, int sign, int extraBit,

View File

@ -7,9 +7,10 @@ namespace IMG {
class DeltaStream : public BitStream1 {
public:
DeltaStream(const SubFile &file, SubFile::Handle &hdl, quint32 length,
quint8 info, bool extraBit, bool extended);
DeltaStream(const SubFile &file, SubFile::Handle &hdl, quint32 length)
: BitStream1(file, hdl, length), _readBits(0xFFFFFFFF) {}
bool init(quint8 info, bool extraBit, bool extended);
bool readNext(qint32 &lonDelta, qint32 &latDelta)
{
return hasNext()

View File

@ -218,8 +218,9 @@ bool RGNFile::polyObjects(Handle &hdl, const SubDiv *subdiv,
poly.points.append(QPointF(c.lon(), c.lat()));
qint32 lonDelta, latDelta;
DeltaStream stream(*this, hdl, len, bitstreamInfo, labelPtr & 0x400000,
false);
DeltaStream stream(*this, hdl, len);
if (!stream.init(bitstreamInfo, labelPtr & 0x400000, false))
return false;
while (stream.readNext(lonDelta, latDelta)) {
pos.rx() += LS(lonDelta, (24-subdiv->bits()));
if (pos.rx() >= 0x800000 && subdiv->lon() >= 0)
@ -325,8 +326,9 @@ bool RGNFile::extPolyObjects(Handle &hdl, const SubDiv *subdiv, quint32 shift,
return false;
qint32 lonDelta, latDelta;
DeltaStream stream(*this, hdl, len - 1, bitstreamInfo, false, true);
DeltaStream stream(*this, hdl, len - 1);
if (!stream.init(bitstreamInfo, false, true))
return false;
while (stream.readNext(lonDelta, latDelta)) {
pos.rx() += LS(lonDelta, 24-subdiv->bits());
if (pos.rx() >= 0x800000 && subdiv->lon() >= 0)