mirror of
https://github.com/tumic0/QtPBFImagePlugin.git
synced 2025-04-20 04:29:11 +02:00
Compare commits
No commits in common. "0c63b665448af0955cdcca008e6a45bee1569bfb" and "252ca8542a1a5746ae01784870d94f8891505e44" have entirely different histories.
0c63b66544
...
252ca8542a
48
src/data.cpp
48
src/data.cpp
@ -40,22 +40,13 @@ static bool varint(CTX &ctx, T &val)
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool length(CTX &ctx, qint32 &val)
|
||||
{
|
||||
if (TYPE(ctx.tag) != LEN)
|
||||
return false;
|
||||
|
||||
if (!varint(ctx, val))
|
||||
return false;
|
||||
|
||||
return (val >= 0);
|
||||
}
|
||||
|
||||
static bool str(CTX &ctx, QByteArray &val)
|
||||
{
|
||||
qint32 len;
|
||||
|
||||
if (!length(ctx, len))
|
||||
if (TYPE(ctx.tag) != LEN)
|
||||
return false;
|
||||
if (!varint(ctx, len))
|
||||
return false;
|
||||
if (ctx.bp + len > ctx.be)
|
||||
return false;
|
||||
@ -98,7 +89,7 @@ static bool packed(CTX &ctx, QVector<quint32> &vals)
|
||||
|
||||
if (TYPE(ctx.tag) == LEN) {
|
||||
qint32 len;
|
||||
if (!varint(ctx, len) || len < 0)
|
||||
if (!varint(ctx, len))
|
||||
return false;
|
||||
const char *ee = ctx.bp + len;
|
||||
if (ee > ctx.be)
|
||||
@ -129,7 +120,7 @@ static bool skip(CTX &ctx)
|
||||
len = 8;
|
||||
break;
|
||||
case LEN:
|
||||
if (!varint(ctx, len) || len < 0)
|
||||
if (!varint(ctx, len))
|
||||
return false;
|
||||
break;
|
||||
case I32:
|
||||
@ -148,13 +139,16 @@ static bool skip(CTX &ctx)
|
||||
|
||||
static bool value(CTX &ctx, QVariant &val)
|
||||
{
|
||||
if (TYPE(ctx.tag) != LEN)
|
||||
return false;
|
||||
|
||||
qint32 len;
|
||||
QByteArray ba;
|
||||
quint64 num;
|
||||
double dnum;
|
||||
float fnum;
|
||||
|
||||
if (!length(ctx, len))
|
||||
if (!varint(ctx, len))
|
||||
return false;
|
||||
|
||||
const char *ee = ctx.bp + len;
|
||||
@ -220,10 +214,13 @@ static bool value(CTX &ctx, QVariant &val)
|
||||
|
||||
static bool feature(CTX &ctx, Data::Feature &f)
|
||||
{
|
||||
qint32 len;
|
||||
quint32 e;
|
||||
|
||||
if (!length(ctx, len))
|
||||
if (TYPE(ctx.tag) != LEN)
|
||||
return false;
|
||||
|
||||
qint32 len;
|
||||
if (!varint(ctx, len))
|
||||
return false;
|
||||
|
||||
const char *ee = ctx.bp + len;
|
||||
@ -269,9 +266,12 @@ static bool feature(CTX &ctx, Data::Feature &f)
|
||||
|
||||
static bool layer(CTX &ctx, Data::Layer &l)
|
||||
{
|
||||
qint32 len;
|
||||
if (FIELD(ctx.tag) == 3) {
|
||||
if (TYPE(ctx.tag) != LEN)
|
||||
return false;
|
||||
|
||||
if (!length(ctx, len))
|
||||
qint32 len;
|
||||
if (!varint(ctx, len))
|
||||
return false;
|
||||
|
||||
const char *ee = ctx.bp + len;
|
||||
@ -321,6 +321,8 @@ static bool layer(CTX &ctx, Data::Layer &l)
|
||||
}
|
||||
|
||||
return (ctx.bp == ee);
|
||||
} else
|
||||
return skip(ctx);
|
||||
}
|
||||
|
||||
bool Data::load(const QByteArray &ba)
|
||||
@ -330,17 +332,9 @@ bool Data::load(const QByteArray &ba)
|
||||
while (ctx.bp < ctx.be) {
|
||||
if (!varint(ctx, ctx.tag))
|
||||
return false;
|
||||
|
||||
switch (FIELD(ctx.tag)) {
|
||||
case 3:
|
||||
_layers.append(Layer());
|
||||
if (!layer(ctx, _layers.last()))
|
||||
return false;
|
||||
break;
|
||||
default:
|
||||
if (!skip(ctx))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return (ctx.bp == ctx.be);
|
||||
|
@ -17,8 +17,6 @@ public:
|
||||
|
||||
struct Feature
|
||||
{
|
||||
Feature() : id(0), type(UNKNOWN) {}
|
||||
|
||||
quint64 id;
|
||||
QVector<quint32> tags;
|
||||
GeomType type;
|
||||
@ -27,8 +25,6 @@ public:
|
||||
|
||||
struct Layer
|
||||
{
|
||||
Layer() : version(1), extent(4096) {}
|
||||
|
||||
quint32 version;
|
||||
QByteArray name;
|
||||
QVector<Feature> features;
|
||||
|
Loading…
x
Reference in New Issue
Block a user