From 75d2efbe4cd9a1384b8624b6f702009c54b85c22 Mon Sep 17 00:00:00 2001 From: Mid <> Date: Sun, 30 Mar 2025 23:20:47 +0300 Subject: [PATCH] Bug fixes --- eebie/writer.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/eebie/writer.c b/eebie/writer.c index 17a5a28..092b4ae 100644 --- a/eebie/writer.c +++ b/eebie/writer.c @@ -5,7 +5,7 @@ #include #include -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) { if(i == 0) return 1; @@ -15,6 +15,7 @@ static int byte_length(uint64_t i) { i >>= 8; 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) { 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); @@ -71,7 +72,7 @@ void ebml_writer_free(EBMLWriter *this) { void ebml_writer_push_ind(EBMLWriter *this, uint64_t 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)); } @@ -79,7 +80,7 @@ void ebml_writer_push_ind(EBMLWriter *this, uint64_t id) { void ebml_writer_push(EBMLWriter *this, uint64_t 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; } @@ -89,7 +90,7 @@ void ebml_writer_pop(EBMLWriter *this) { uint64_t newSize = this->stack[this->currentDepth]; uint64_t *s = (uint64_t*) &this->buffer[this->bufferLen - newSize - 8]; - *s = htobe64(0x0100000000000000L | newSize); + *s = htobe64(0x0100000000000000UL | newSize); if(this->currentDepth == 0) { while(!ebml_writer_flush(this));