From 166fd5acadcca451a270b38e69433c8db21e3575 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Wed, 20 Feb 2019 14:01:32 +0100 Subject: [PATCH] interim fix for the "const QByteArray&" casts Did not dive much into the address logic here, but I think we would be better of with index counting instead of addresses. --- src/msgpack.cpp | 4 ++-- src/private/unpack_p.cpp | 9 +++++---- src/private/unpack_p.h | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/msgpack.cpp b/src/msgpack.cpp index 3bc8e8e..6a12997 100644 --- a/src/msgpack.cpp +++ b/src/msgpack.cpp @@ -9,8 +9,8 @@ QVariant MsgPack::unpack(const QByteArray &data) { - quint8 *p = (quint8 *)data.data(); - quint8 *end = p + data.size() - 1; + const quint8 *p = reinterpret_cast(data.data()); + const quint8 *end = p + data.size() - 1; return MsgPackPrivate::unpack(p, end); } diff --git a/src/private/unpack_p.cpp b/src/private/unpack_p.cpp index d224a53..067309d 100644 --- a/src/private/unpack_p.cpp +++ b/src/private/unpack_p.cpp @@ -47,17 +47,18 @@ MsgPackPrivate::type_parser_f MsgPackPrivate::unpackers[32] = { QHash MsgPackPrivate::user_unpackers; QReadWriteLock MsgPackPrivate::unpackers_lock; -QVariant MsgPackPrivate::unpack(quint8 *p, quint8 *end) +QVariant MsgPackPrivate::unpack(const quint8 *p, const quint8 *end) { QVariantList d; QVariant v; - while (p <= end) { - p = unpack_type(v, p); + quint8* pos = const_cast(p); // FIXME + while (pos <= end) { + pos = unpack_type(v, pos); d.append(v); } - if (p - end > 1) + if (pos - end > 1) return QVariant(); if (d.length() == 1) diff --git a/src/private/unpack_p.h b/src/private/unpack_p.h index cce8fe4..b44151a 100644 --- a/src/private/unpack_p.h +++ b/src/private/unpack_p.h @@ -23,7 +23,7 @@ extern QHash user_unpackers; extern QReadWriteLock unpackers_lock; // goes from p to end unpacking types with unpack_type function below -QVariant unpack(quint8 *p, quint8 *end); +QVariant unpack(const quint8 *p, const quint8 *end); // unpack some type, can be called recursively from other unpack functions quint8 * unpack_type(QVariant &v, quint8 *p);