diff --git a/src/lib/nbt.cpp b/src/lib/nbt.cpp index 2046b19..6b1e540 100644 --- a/src/lib/nbt.cpp +++ b/src/lib/nbt.cpp @@ -1307,8 +1307,8 @@ namespace NBT { // - BodgeMaster } + bool returnValue; uint64_t currentPosition = initialPosition; - #define return if (processedDataSize!=nullptr) *processedDataSize = currentPosition-initialPosition; return while (currentPosition nextTagSize = Helper::totalTagSize(data, dataSize, currentPosition); if (nextTagSize.isError) { @@ -1316,7 +1316,8 @@ namespace NBT { // attempt parsing the name ErrorOr tagName = Helper::readString(data, dataSize, currentPosition+1); if (tagName.isError) { - return false; + returnValue = false; + goto returnNow; } // used seek to the start of the list's/compound’s contents @@ -1332,7 +1333,8 @@ namespace NBT { // type byte + two name size bytes = 3 if (!validateRawListContents(data, dataSize, currentPosition + (uint64_t) nameSize + 3, processedTagSize)) { delete processedTagSize; - return false; + returnValue = false; + goto returnNow; } *processedTagSize += (uint64_t) nameSize + 3; } @@ -1340,7 +1342,8 @@ namespace NBT { // type byte + two name size bytes = 3 if (!validateRawNBTData(data, dataSize, currentPosition + (uint64_t) nameSize + 3, processedTagSize)) { delete processedTagSize; - return false; + returnValue = false; + goto returnNow; } *processedTagSize += (uint64_t) nameSize + 3; } @@ -1349,17 +1352,20 @@ namespace NBT { delete processedTagSize; continue; } - return false; + returnValue = false; + goto returnNow; } if (currentPosition + nextTagSize.value > dataSize) { - return false; + returnValue = false; + goto returnNow; } // recursion abort condition if (data[currentPosition]==TagType::END) { currentPosition++; - return true; + returnValue = true; + goto returnNow; } // nameSize cannot be an error here bc it got checked in @@ -1371,11 +1377,15 @@ namespace NBT { // This shouldn't matter too much here as the only error condition // the parser function deals with rn is an overrun which is already // being guarded against with - // if (currentPosition + nextTagSize.value > dataSize) return false; + // if (currentPosition + nextTagSize.value > dataSize) { + // returnValue = false; + // goto returnNow; + // } // It might, however, turn out to be a useful check in the future. ErrorOr name = Helper::readString(data, dataSize, currentPosition+1); if (name.isError) { - return false; + returnValue = false; + goto returnNow; } switch (data[currentPosition]) { @@ -1393,14 +1403,18 @@ namespace NBT { // This shouldn't matter too much here as the only // error condition the parser function deals with rn is // an overrun which is already being guarded against with - // if (currentPosition + nextTagSize.value > dataSize) return false; + // if (currentPosition + nextTagSize.value > dataSize) { + // returnValue = false; + // goto returnNow; + // } // It might, however, turn out to be a useful check // in the future. // // type byte + two name size bytes = 3 ErrorOr content = Helper::readString(data, dataSize, currentPosition+nameSize+3); if (content.isError) { - return false; + returnValue = false; + goto returnNow; } break; } @@ -1408,12 +1422,19 @@ namespace NBT { case TagType::INT64_ARRAY: break; default: - return false; + returnValue = false; + goto returnNow; } currentPosition += nextTagSize.value; } - return true; - #undef return + returnValue = true; + goto returnNow; + + returnNow: + if (processedDataSize!=nullptr) { + *processedDataSize = currentPosition-initialPosition; + } + return returnValue; } }