# HG changeset patch # User Teemu Piippo # Date 1611743880 -7200 # Node ID 248fba6d1e7640882d4fc1a7f0f0409f1ae8367e # Parent 96ffd13c08a261717e860126d33ac5eb4826b71d added protocol5 branch's string reading function which seems to be more reliable diff -r 96ffd13c08a2 -r 248fba6d1e76 sources/network/bytestream.cpp --- a/sources/network/bytestream.cpp Sat Jul 23 12:32:23 2016 +0300 +++ b/sources/network/bytestream.cpp Wed Jan 27 12:38:00 2021 +0200 @@ -129,28 +129,15 @@ */ String Bytestream::readString() { - ByteArray::Iterator stringEndIterator; + String result; - // Where's the end of the string? - for (stringEndIterator = getCurrentIterator(); *stringEndIterator != '\0'; ++stringEndIterator) + for (char byte; (byte = readByte()) != '\0';) { - if (stringEndIterator == m_data.end()) - { - // Past the end of the buffer - throw IOError("unterminated or too long string in packet"); - } + if (result.length() < MAX_NETWORK_STRING) + result += byte; } - // Skip past the null terminator. - if (*stringEndIterator == '\0') - stringEndIterator += 1; - - // Build and return the string, and advance the position. - int stringStart = m_position; - unsigned int length = stringEndIterator - getCurrentIterator(); - length = min(length, MAX_NETWORK_STRING); - m_position += length; - return String::fromBytes(m_data.splice(stringStart, stringStart + length)); + return result; } /*!