xref: /freebsd/contrib/bc/project/issue10.md (revision fdc4a7c8012b214986cfa2e2fb6d99731f004b1b)
1# "scale" not set correctly with -l when first command is a syntax error
2
3## `mathieu`
4
5I just hit a (small and unlikely to be triggered) problem when using the `-l` flag:
6
7```
8$ bc -l
9>>> 2+; # or any other syntax error it seems
10
11Parse error: bad expression
12    <stdin>:1
13
14>>> l(1000)
156
16>>> scale
170
18```
19
20The math library still gets loaded but `scale` doesn't get set (or gets reset)?
21
22The syntax error has to be on the first command and other kinds of errors (like say a divide by zero) don't seem to cause the problem.
23
24## `gavin`
25
26Hmm...let me investigate this and get back to you. This does seem like a bug.
27
28## `gavin`
29
30I'm not seeing the behavior. Can you send me the output of `bc -v`?
31
32## `gavin`
33
34I should also ask: what OS are you on? What version? What compiler did you use? Did you install from a package?
35
36Basically, send me as much info as you can. I would appreciate it.
37
38## `mathieu`
39
40Oh sorry yeah I should've given more details.
41
42That's on FreeBSD with the base system's bc, built with the default base compiler.
43
44On recent 12.2-STABLE:
45
46```
47$ bc -v
48bc 4.0.1
49Copyright (c) 2018-2021 Gavin D. Howard and contributors
50Report bugs at: https://git.yzena.com/gavin/bc
51
52This is free software with ABSOLUTELY NO WARRANTY.
53```
54
55Your bc is not default on 12.X yet but I enabled it with WITH_GH_BC=yes in /etc/src.conf to try it out.
56
57And on somewhat less recent 14-CURRENT:
58
59```
60$ bc -v
61bc 4.0.0
62Copyright (c) 2018-2021 Gavin D. Howard and contributors
63Report bugs at: https://git.yzena.com/gavin/bc
64
65This is free software with ABSOLUTELY NO WARRANTY.
66```
67
68Both amd64. Happens every time on both.
69
70I could give it a try on 13-STABLE too if that helps but I'd need to reboot something.
71
72The syntax error really has to be the FIRST input, even entering an empty line before it makes the problem not happen.
73
74I thought it could be an editline(3) problem since some programs end up using that pretty much only on the BSDs it seems, but that's not it.
75
76## `gavin`
77
78Yeah, my `bc` uses a custom history implementation, so it could be mine, but not `editline(3)`.
79
80I will pull up a FreeBSD VM and check it out. Sorry for the wait.
81
82## `gavin`
83
84I have confirmed the bug on FreeBSD with the port at version `4.0.1`. Since it is the port, and not the system one, I think the problem may lie with some incompatibility between my history implementation and what FreeBSD provides.
85
86This one may take me a long time to debug because I have to do it manually in the VM. Thank you for your patience.
87
88## `gavin`
89
90I found the problem!
91
92It is fixed in `299a4fd353`, but if you can pull that down and test, I would appreciate it.
93
94I will put out a release as soon as I can, and my FreeBSD contact will probably update 14-CURRENT soon thereafter. He will also update the port, but the version in 12.2 may not be updated for a bit.
95
96Feel free to reopen if the fix does not work for you.
97
98## `mathieu`
99
100Oof... yeah makes sense that an rc file could interfere with this.
101
102Yes, that fixes it here too. With that diff applied on both 12.2-STABLE and 14-CURRENT's versions. And everything else seems to still work fine too.
103
104Thanks for fixing this! You'd think it's really hard to trigger but I do enough typos and I start bc (with an alias with -l) often enough to make a quick calculation that I hit it twice and had decimals mysteriously missing before I started trying to reproduce it.
105