Bug fixes
This commit is contained in:
parent
629a8fdf55
commit
75d2efbe4c
@ -5,7 +5,7 @@
|
|||||||
#include<stddef.h>
|
#include<stddef.h>
|
||||||
#include<assert.h>
|
#include<assert.h>
|
||||||
|
|
||||||
static uint64_t VARINT_MASKS[] = {0, 0x80L, 0xC000L, 0xE00000L, 0xF0000000L, 0xF800000000L, 0xFC0000000000L, 0xFE000000000000L, 0L};
|
static uint64_t VARINT_MASKS[] = {0x0UL, 0x80UL, 0x4000UL, 0x200000UL, 0x10000000UL, 0x0800000000UL, 0x040000000000UL, 0x02000000000000UL, 0x0100000000000000UL};
|
||||||
|
|
||||||
static int byte_length(uint64_t i) {
|
static int byte_length(uint64_t i) {
|
||||||
if(i == 0) return 1;
|
if(i == 0) return 1;
|
||||||
@ -15,6 +15,7 @@ static int byte_length(uint64_t i) {
|
|||||||
i >>= 8;
|
i >>= 8;
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +43,7 @@ static void advance(EBMLWriter *this, uint64_t amount) {
|
|||||||
|
|
||||||
static void add(EBMLWriter *this, const void *data, size_t length) {
|
static void add(EBMLWriter *this, const void *data, size_t length) {
|
||||||
if(this->bufferLen + length > this->bufferCapacity) {
|
if(this->bufferLen + length > this->bufferCapacity) {
|
||||||
this->buffer = this->eventAlloc(this, this->buffer, (this->bufferLen + length + 1023) & ~1023);
|
this->buffer = this->eventAlloc(this, this->buffer, this->bufferCapacity = ((this->bufferLen + length + 1023) & ~1023));
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(this->buffer + this->bufferLen, data, length);
|
memcpy(this->buffer + this->bufferLen, data, length);
|
||||||
@ -71,7 +72,7 @@ void ebml_writer_free(EBMLWriter *this) {
|
|||||||
void ebml_writer_push_ind(EBMLWriter *this, uint64_t id) {
|
void ebml_writer_push_ind(EBMLWriter *this, uint64_t id) {
|
||||||
add_varint(this, id);
|
add_varint(this, id);
|
||||||
|
|
||||||
add(this, &(uint64_t) {htobe64(0x01FFFFFFFFFFFFFFL)}, sizeof(uint64_t)); // UNKNOWN-SIZED ELEMENT
|
add(this, &(uint64_t) {htobe64(0x01FFFFFFFFFFFFFFUL)}, sizeof(uint64_t)); // UNKNOWN-SIZED ELEMENT
|
||||||
|
|
||||||
while(!ebml_writer_flush(this));
|
while(!ebml_writer_flush(this));
|
||||||
}
|
}
|
||||||
@ -79,7 +80,7 @@ void ebml_writer_push_ind(EBMLWriter *this, uint64_t id) {
|
|||||||
void ebml_writer_push(EBMLWriter *this, uint64_t id) {
|
void ebml_writer_push(EBMLWriter *this, uint64_t id) {
|
||||||
add_varint(this, id);
|
add_varint(this, id);
|
||||||
|
|
||||||
add(this, &(uint64_t) {htobe64(0x0100000000000000L)}, sizeof(uint64_t)); // LENGTH OF MAX SIZE (BECAUSE UNKNOWN)
|
add(this, &(uint64_t) {htobe64(0x0100000000000000UL)}, sizeof(uint64_t)); // LENGTH OF MAX SIZE (BECAUSE UNKNOWN)
|
||||||
|
|
||||||
this->stack[this->currentDepth++] = 0;
|
this->stack[this->currentDepth++] = 0;
|
||||||
}
|
}
|
||||||
@ -89,7 +90,7 @@ void ebml_writer_pop(EBMLWriter *this) {
|
|||||||
|
|
||||||
uint64_t newSize = this->stack[this->currentDepth];
|
uint64_t newSize = this->stack[this->currentDepth];
|
||||||
uint64_t *s = (uint64_t*) &this->buffer[this->bufferLen - newSize - 8];
|
uint64_t *s = (uint64_t*) &this->buffer[this->bufferLen - newSize - 8];
|
||||||
*s = htobe64(0x0100000000000000L | newSize);
|
*s = htobe64(0x0100000000000000UL | newSize);
|
||||||
|
|
||||||
if(this->currentDepth == 0) {
|
if(this->currentDepth == 0) {
|
||||||
while(!ebml_writer_flush(this));
|
while(!ebml_writer_flush(this));
|
||||||
|
Loading…
Reference in New Issue
Block a user