fix an issue in example program

This commit is contained in:
falsycat 2024-02-12 23:18:38 +09:00
parent f0ae9692fc
commit a1cefa690d

View File

@ -13,6 +13,7 @@ static inline bool acg_flush(struct acg_stream* s) {
if (s->cursor_bits < 8U) { if (s->cursor_bits < 8U) {
return false; return false;
} }
FILE** fp = (void*) &s->udata; FILE** fp = (void*) &s->udata;
if (NULL == *fp) { if (NULL == *fp) {
*fp = fopen("log.acg", "wb"); *fp = fopen("log.acg", "wb");
@ -23,6 +24,9 @@ static inline bool acg_flush(struct acg_stream* s) {
if (1U != fwrite(s->buffer, s->cursor_bits/8U, 1U, *fp)) { if (1U != fwrite(s->buffer, s->cursor_bits/8U, 1U, *fp)) {
return false; return false;
} }
memset(s->buffer, 0U, (s->cursor_bits+7U)/8U);
s->cursor_bits = 0;
if (0U != fflush(*fp)) { if (0U != fflush(*fp)) {
return false; return false;
} }