Skip to content

Commit

Permalink
remove infinite loop in writeVarInt()
Browse files Browse the repository at this point in the history
  • Loading branch information
iTrooz committed Nov 28, 2024
1 parent 26f50f9 commit 873232e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions launcher/ui/pages/instance/McClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "McClient.h"
#include <qtconcurrentrun.h>

// 7 first bits
#define SEGMENT_BITS 0x7F
#define CONTINUE_BIT 0x80

Expand Down Expand Up @@ -99,17 +100,15 @@ QJsonObject McClient::readResponse() {

// From https://wiki.vg/Protocol#VarInt_and_VarLong
void McClient::writeVarInt(QByteArray &data, int value) {
while (true) {
if ((value & ~SEGMENT_BITS) == 0) {
data.append(value);
return;
}

while ((value & ~SEGMENT_BITS)) { // check if the value is too big to fit in 7 bits
// Write 7 bits
data.append((value & SEGMENT_BITS) | CONTINUE_BIT);

// Erase theses 7 bits from the value to write
// Note: >>> means that the sign bit is shifted with the rest of the number rather than being left alone
value >>= 7;
}
data.append(value);
}

// From https://wiki.vg/Protocol#VarInt_and_VarLong
Expand Down

0 comments on commit 873232e

Please sign in to comment.