2018-01-27 13:22:09 (UTC-02:00)
Marcel Rodrigues <marcelgmr@gmail.com>
Write partial byte iif offset % 8 != 0. The function end_key() flushes the last non-empty sub-block in a block. The length of this sub-block depends on whether there are bits waiting to fill up a temporary byte. If gif->offset is a multiple of 8, then all bits were already packed into bytes and written to gif->buffer. Otherwise, there are 8 - gif->offset % 8 bits that need to be written in the buffer, adding one byte to the sub-block.
diff --git a/gif.c b/gif.c index 5e79495..5e1f3c4 100644 --- a/gif.c +++ b/gif.c @@ -107,7 +107,8 @@ end_key(GIF *gif) { int byte_offset; byte_offset = gif->offset / 8; - gif->buffer[byte_offset] = gif->partial & 0xFF; + if (gif->offset % 8) + gif->buffer[byte_offset++] = gif->partial & 0xFF; write(gif->fd, (uint8_t []) {byte_offset}, 1); write(gif->fd, gif->buffer, byte_offset); write(gif->fd, "\0", 1);