From f2ae84c062b83d32dae2b3a17e8526fa2018efb7 Mon Sep 17 00:00:00 2001 From: BodgeMaster <> Date: Thu, 11 Aug 2022 06:57:42 +0200 Subject: [PATCH] lib/nbt: Various minor fixes to get the program to compile properly --- src/lib/nbt.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/lib/nbt.cpp b/src/lib/nbt.cpp index ad5d404..41c1e02 100644 --- a/src/lib/nbt.cpp +++ b/src/lib/nbt.cpp @@ -463,7 +463,7 @@ namespace NBT { case TagType::DOUBLE: // type byte + name size + 8 data bytes -> 11 bytes return ErrorOr((uint64_t) nameSize.value+11); - case TagType::INT8_ARRAY: + case TagType::INT8_ARRAY: { // type byte + name size + 4 size bytes -> 7 bytes uint64_t totalSize = (uint64_t) nameSize.value+7; @@ -475,7 +475,8 @@ namespace NBT { totalSize += (uint64_t) arraySize.value; return ErrorOr(totalSize); - case TagType::STRING: + } + case TagType::STRING: { // type byte + name size + 2 size bytes -> 5 bytes uint64_t totalSize = (uint64_t) nameSize.value+5; @@ -487,7 +488,8 @@ namespace NBT { totalSize += (uint64_t) stringSize.value; return ErrorOr(totalSize); - case TagType::LIST: + } + case TagType::LIST: { // type byte + name size + type prefix + 4 size bytes -> 8 bytes uint64_t totalSize = (uint64_t) nameSize.value+8; @@ -506,23 +508,30 @@ namespace NBT { switch (containedType.value) { case TagType::END: factor = 1; + break; case TagType::INT8: factor = 1; + break; case TagType::INT16: factor = 2; + break; case TagType::INT32: factor = 4; + break; case TagType::INT64: factor = 8; + break; case TagType::FLOAT: factor = 4; + break; case TagType::DOUBLE: factor = 8; + break; default: // How would you even get here? return ErrorOr(true, ErrorCodes::UNKNOWN); } - totalSize += listSize*factor; + totalSize += listSize.value*factor; return ErrorOr(totalSize); } else { if (containedType.value == TagType::COMPOUND || containedType.value == TagType::LIST) return ErrorOr(false, ErrorCodes::NOT_YET_KNOWN); @@ -530,7 +539,8 @@ namespace NBT { } return ErrorOr(true, ErrorCodes::UNKNOWN); - case TagType::INT32_ARRAY: + } + case TagType::INT32_ARRAY: { // type byte + name size + 4 size bytes -> 7 bytes uint64_t totalSize = (uint64_t) nameSize.value+7; @@ -542,7 +552,8 @@ namespace NBT { totalSize += (uint64_t) arraySize.value*4; return ErrorOr(totalSize); - case TagType::INT64_ARRAY: + } + case TagType::INT64_ARRAY: { // type byte + name size + 4 size bytes -> 7 bytes uint64_t totalSize = (uint64_t) nameSize.value+7; @@ -554,6 +565,7 @@ namespace NBT { totalSize += (uint64_t) arraySize.value*8; return ErrorOr(totalSize); + } // fall-through in case of unknown tag or parsing error default: return ErrorOr(true, ErrorCodes::UNKNOWN);