mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-05-20 16:27:15 +02:00
remove infinite loop in writeVarInt()
This commit is contained in:
parent
26f50f9b81
commit
873232ebe3
@ -7,6 +7,7 @@
|
|||||||
#include "McClient.h"
|
#include "McClient.h"
|
||||||
#include <qtconcurrentrun.h>
|
#include <qtconcurrentrun.h>
|
||||||
|
|
||||||
|
// 7 first bits
|
||||||
#define SEGMENT_BITS 0x7F
|
#define SEGMENT_BITS 0x7F
|
||||||
#define CONTINUE_BIT 0x80
|
#define CONTINUE_BIT 0x80
|
||||||
|
|
||||||
@ -99,17 +100,15 @@ QJsonObject McClient::readResponse() {
|
|||||||
|
|
||||||
// From https://wiki.vg/Protocol#VarInt_and_VarLong
|
// From https://wiki.vg/Protocol#VarInt_and_VarLong
|
||||||
void McClient::writeVarInt(QByteArray &data, int value) {
|
void McClient::writeVarInt(QByteArray &data, int value) {
|
||||||
while (true) {
|
while ((value & ~SEGMENT_BITS)) { // check if the value is too big to fit in 7 bits
|
||||||
if ((value & ~SEGMENT_BITS) == 0) {
|
// Write 7 bits
|
||||||
data.append(value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
data.append((value & SEGMENT_BITS) | CONTINUE_BIT);
|
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
|
// Note: >>> means that the sign bit is shifted with the rest of the number rather than being left alone
|
||||||
value >>= 7;
|
value >>= 7;
|
||||||
}
|
}
|
||||||
|
data.append(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// From https://wiki.vg/Protocol#VarInt_and_VarLong
|
// From https://wiki.vg/Protocol#VarInt_and_VarLong
|
||||||
|
Loading…
x
Reference in New Issue
Block a user