From c12c2b44975ea0bbfe962eff22a64f855f3d8790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Mon, 6 Jan 2025 10:04:41 +0100 Subject: [PATCH] Fixed zigzag decode --- src/data.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/data.cpp b/src/data.cpp index 737b818..0003b2e 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -13,6 +13,12 @@ struct CTX quint64 tag; }; +static inline qint64 zigzag64decode(quint64 value) +{ + return static_cast((value >> 1u) ^ static_cast( + -static_cast(value & 1u))); +} + template static bool varint(CTX &ctx, T &val) { @@ -155,7 +161,7 @@ static bool value(CTX &ctx, QVariant &val) case 4: if (!varint(ctx, num)) return false; - val = QVariant((qint64)num); + val = QVariant(static_cast(num)); break; case 5: if (!varint(ctx, num)) @@ -165,7 +171,7 @@ static bool value(CTX &ctx, QVariant &val) case 6: if (!varint(ctx, num)) return false; - val = QVariant((qint64)((num >> 1) ^ -(num & 1))); + val = QVariant(zigzag64decode(num)); break; case 7: if (!varint(ctx, num))