Bugfix: While testing decoding some bugs appeared
This commit is contained in:
parent
a16d50b717
commit
616a8987cb
1 changed files with 8 additions and 6 deletions
14
src/packet.c
14
src/packet.c
|
@ -62,14 +62,15 @@ void free_MQTTPacket(MQTTPacket *packet) {
|
||||||
|
|
||||||
|
|
||||||
uint16_t variable_length_int_decode(Buffer *buffer) {
|
uint16_t variable_length_int_decode(Buffer *buffer) {
|
||||||
uint16_t result = 0;
|
uint16_t result = buffer->data[buffer->position++] & 0x7f;
|
||||||
while (buffer->data[buffer->position] & 0x80) {
|
uint16_t shift = 7;
|
||||||
result *= 128;
|
while (buffer->data[buffer->position - 1] & 0x80) {
|
||||||
result += buffer->data[buffer->position] & 0x7f;
|
result += (buffer->data[buffer->position] & 0x7f) << shift;
|
||||||
buffer->position++;
|
shift += 7;
|
||||||
if (buffer_eof(buffer)) {
|
if (buffer_eof(buffer)) {
|
||||||
break; // bail out, buffer exhausted
|
break; // bail out, buffer exhausted
|
||||||
}
|
}
|
||||||
|
buffer->position++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -87,8 +88,9 @@ char *utf8_string_decode(Buffer *buffer) {
|
||||||
}
|
}
|
||||||
buffer->position += 2;
|
buffer->position += 2;
|
||||||
|
|
||||||
result = malloc(sz);
|
result = malloc(sz + 1);
|
||||||
buffer_copy_out(buffer, result, sz);
|
buffer_copy_out(buffer, result, sz);
|
||||||
|
result[sz] = '\0';
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue