Fix a bug

This bug was that bc did not properly check the return value of a
function.

Signed-off-by: Gavin Howard <[email protected]>
This commit is contained in:
Gavin Howard 2022-05-18 23:08:28 -06:00
parent c96de7c0f6
commit 04ef32e888
Signed by: gavin
GPG Key ID: C08038BDF280D33E
1 changed files with 21 additions and 1 deletions

View File

@ -195,7 +195,27 @@ void bc_file_write(BcFile *restrict f, BcFlushType type,
// If the output is large enough to flush by itself, just output it.
// Otherwise, put it into the buffer.
if (BC_UNLIKELY(n > f->cap - f->len)) bc_file_output(f->fd, buf, n);
if (BC_UNLIKELY(n > f->cap - f->len)) {
BcStatus s = bc_file_output(f->fd, buf, n);
if (BC_ERR(s)) {
// For EOF, set it and jump.
if (s == BC_STATUS_EOF) {
vm.status = (sig_atomic_t) s;
BC_SIG_TRYUNLOCK(lock);
BC_JMP;
}
// Blow up on fatal error. Okay, not blow up, just quit.
else {
if (f->f == stderr) exit(BC_STATUS_ERROR_FATAL);
bc_vm_fatalError(BC_ERR_FATAL_IO_ERR);
}
}
}
else {
memcpy(f->buf + f->len, buf, n);
f->len += n;