diff options
author | Rubidium <rubidium@openttd.org> | 2021-05-10 23:43:52 +0200 |
---|---|---|
committer | rubidium42 <rubidium42@users.noreply.github.com> | 2021-05-15 10:16:10 +0200 |
commit | bb9121dbd4690405b54e7e6ed6e711ead16435ac (patch) | |
tree | efb930ab320c6be74d4ca8e4d5d674e3d1e7812d /src/network | |
parent | 031e91de6e06e6b0d12603d78170f92f5def1d00 (diff) | |
download | openttd-bb9121dbd4690405b54e7e6ed6e711ead16435ac.tar.xz |
Fix: comparison of narrow type to wide type in loop (potential for infinite loops)
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/core/packet.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/network/core/packet.cpp b/src/network/core/packet.cpp index 883097dea..738afec4e 100644 --- a/src/network/core/packet.cpp +++ b/src/network/core/packet.cpp @@ -374,14 +374,13 @@ uint64 Packet::Recv_uint64() */ void Packet::Recv_string(char *buffer, size_t size, StringValidationSettings settings) { - PacketSize pos; char *bufp = buffer; const char *last = buffer + size - 1; /* Don't allow reading from a closed socket */ if (cs->HasClientQuit()) return; - pos = this->pos; + size_t pos = this->pos; while (--size > 0 && pos < this->Size() && (*buffer++ = this->buffer[pos++]) != '\0') {} if (size == 0 || pos == this->Size()) { @@ -391,7 +390,9 @@ void Packet::Recv_string(char *buffer, size_t size, StringValidationSettings set while (pos < this->Size() && this->buffer[pos] != '\0') pos++; pos++; } - this->pos = pos; + + assert(pos <= std::numeric_limits<PacketSize>::max()); + this->pos = static_cast<PacketSize>(pos); str_validate(bufp, last, settings); } |