From acc19ae1008399d50f5e49e74587d1e6cf15eea4 Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Sat, 13 Aug 2022 16:49:01 +0200 Subject: [PATCH] lib/nbt: Change behavior of totalTagSize to treat encounters of compounds and lists as errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I stumbled over this when writing the unit test. Previously, it would return an error code but explicitly mark it as not being an error. This was intended behavior but I decided to change it because I didn’t anticipate it when writing the test. Technically `ErrorOr` can be used to pass any message alongside `T`, but practically, it is reasonable to assume that the error code is `ErrorCodes::SUCCESS` when `isError` is false. Therefore, this feature should be really only used in the weirdest edge cases - if at all. Even then, it is most likely still preferable to flag it as an error and just hand the resulting `T` back using the long constructor `ErrorOr(bool, uint8_t, T)`. --- src/lib/nbt.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/nbt.cpp b/src/lib/nbt.cpp index 26ad964..c83afa4 100644 --- a/src/lib/nbt.cpp +++ b/src/lib/nbt.cpp @@ -395,8 +395,8 @@ namespace NBT { } else { nextTag = data[currentPosition]; } - // deal with compound tags separately - if (nextTag == TagType::COMPOUND || nextTag == TagType::LIST) return ErrorOr(false, ErrorCodes::NOT_YET_KNOWN); + // deal with compound tags and lists separately + if (nextTag == TagType::COMPOUND || nextTag == TagType::LIST) return ErrorOr(true, ErrorCodes::NOT_YET_KNOWN); // deal with end tag before trying to access the name if (nextTag == TagType::END) return ErrorOr(1);