# HG changeset patch # User Matti Hamalainen # Date 1530021327 -10800 # Node ID 2977baab68db689afc31a99be79394ef1bf95d63 # Parent 571109a14967e2cc9c3a50552d7c9396382e872c Fix certain corner case in IFF ByteRun1 encoder. diff -r 571109a14967 -r 2977baab68db tools/libgfx.c --- a/tools/libgfx.c Tue Jun 26 16:49:03 2018 +0300 +++ b/tools/libgfx.c Tue Jun 26 16:55:27 2018 +0300 @@ -1977,7 +1977,7 @@ if (l_count > *r_count || flush) { size_t count = l_count - *r_count; - Sint8 tmp = count - 1; + Uint8 tmp = count - 1; if (!dmf_write_byte(fp, tmp) || !dmf_write_str(fp, buf + *l_offs, count)) @@ -1987,14 +1987,16 @@ } else { - unsigned int count = *r_count; - Sint8 tmp = -(count - 1); + if (*r_count > 0) + { + unsigned int count = *r_count; + Uint8 tmp = ((Uint8) count - 2) ^ 0xff; - if (!dmf_write_byte(fp, tmp) || - !dmf_write_byte(fp, data)) - return FALSE; - - *r_count = 0; + if (!dmf_write_byte(fp, tmp) || + !dmf_write_byte(fp, data)) + return FALSE; + *r_count = 0; + } *l_offs = offs; }