Fix a bug found by mathieu, a FreeBSD user

This bug was reported in https://git.yzena.com/gavin/bc/issues/10. It
happens when the first thing a user enters at `stdin` causes a parse
error.

mathieu did not know what caused the error, and I could not reproduce it
on my machine. I tried on FreeBSD and could reproduce it under root, but
not my user.

After investigating, the reason I could not reproduce it was because my
user runs a file: /home/gavin/.bcrc. Because it runs the file, it would
execute the `scale = 20` statement in the math library. However, when I
would not have it execute that file, and enter a parse error first, that
statement would not be executed, and since bc resets after an error,
that statement would disappear and never happen.

The fix was simple: just call bc_program_exec() right after loading the
math libraries.

Fix #10
This commit is contained in:
Gavin Howard 2021-05-05 16:00:04 -06:00
parent 21ed9fa62b
commit 299a4fd353
Signed by: gavin
GPG Key ID: C08038BDF280D33E
1 changed files with 2 additions and 0 deletions

View File

@ -835,6 +835,8 @@ static void bc_vm_exec(void) {
#if BC_ENABLE_EXTRA_MATH
if (!BC_IS_POSIX) bc_vm_load(bc_lib2_name, bc_lib2);
#endif // BC_ENABLE_EXTRA_MATH
bc_program_exec(&vm.prog);
}
#endif // BC_ENABLED