xref: /freebsd/contrib/bc/project/issue10.md (revision fdc4a7c8012b214986cfa2e2fb6d99731f004b1b)
1*fdc4a7c8SStefan Eßer# "scale" not set correctly with -l when first command is a syntax error
2*fdc4a7c8SStefan Eßer
3*fdc4a7c8SStefan Eßer## `mathieu`
4*fdc4a7c8SStefan Eßer
5*fdc4a7c8SStefan EßerI just hit a (small and unlikely to be triggered) problem when using the `-l` flag:
6*fdc4a7c8SStefan Eßer
7*fdc4a7c8SStefan Eßer```
8*fdc4a7c8SStefan Eßer$ bc -l
9*fdc4a7c8SStefan Eßer>>> 2+; # or any other syntax error it seems
10*fdc4a7c8SStefan Eßer
11*fdc4a7c8SStefan EßerParse error: bad expression
12*fdc4a7c8SStefan Eßer    <stdin>:1
13*fdc4a7c8SStefan Eßer
14*fdc4a7c8SStefan Eßer>>> l(1000)
15*fdc4a7c8SStefan Eßer6
16*fdc4a7c8SStefan Eßer>>> scale
17*fdc4a7c8SStefan Eßer0
18*fdc4a7c8SStefan Eßer```
19*fdc4a7c8SStefan Eßer
20*fdc4a7c8SStefan EßerThe math library still gets loaded but `scale` doesn't get set (or gets reset)?
21*fdc4a7c8SStefan Eßer
22*fdc4a7c8SStefan EßerThe 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*fdc4a7c8SStefan Eßer
24*fdc4a7c8SStefan Eßer## `gavin`
25*fdc4a7c8SStefan Eßer
26*fdc4a7c8SStefan EßerHmm...let me investigate this and get back to you. This does seem like a bug.
27*fdc4a7c8SStefan Eßer
28*fdc4a7c8SStefan Eßer## `gavin`
29*fdc4a7c8SStefan Eßer
30*fdc4a7c8SStefan EßerI'm not seeing the behavior. Can you send me the output of `bc -v`?
31*fdc4a7c8SStefan Eßer
32*fdc4a7c8SStefan Eßer## `gavin`
33*fdc4a7c8SStefan Eßer
34*fdc4a7c8SStefan EßerI should also ask: what OS are you on? What version? What compiler did you use? Did you install from a package?
35*fdc4a7c8SStefan Eßer
36*fdc4a7c8SStefan EßerBasically, send me as much info as you can. I would appreciate it.
37*fdc4a7c8SStefan Eßer
38*fdc4a7c8SStefan Eßer## `mathieu`
39*fdc4a7c8SStefan Eßer
40*fdc4a7c8SStefan EßerOh sorry yeah I should've given more details.
41*fdc4a7c8SStefan Eßer
42*fdc4a7c8SStefan EßerThat's on FreeBSD with the base system's bc, built with the default base compiler.
43*fdc4a7c8SStefan Eßer
44*fdc4a7c8SStefan EßerOn recent 12.2-STABLE:
45*fdc4a7c8SStefan Eßer
46*fdc4a7c8SStefan Eßer```
47*fdc4a7c8SStefan Eßer$ bc -v
48*fdc4a7c8SStefan Eßerbc 4.0.1
49*fdc4a7c8SStefan EßerCopyright (c) 2018-2021 Gavin D. Howard and contributors
50*fdc4a7c8SStefan EßerReport bugs at: https://git.yzena.com/gavin/bc
51*fdc4a7c8SStefan Eßer
52*fdc4a7c8SStefan EßerThis is free software with ABSOLUTELY NO WARRANTY.
53*fdc4a7c8SStefan Eßer```
54*fdc4a7c8SStefan Eßer
55*fdc4a7c8SStefan EßerYour 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*fdc4a7c8SStefan Eßer
57*fdc4a7c8SStefan EßerAnd on somewhat less recent 14-CURRENT:
58*fdc4a7c8SStefan Eßer
59*fdc4a7c8SStefan Eßer```
60*fdc4a7c8SStefan Eßer$ bc -v
61*fdc4a7c8SStefan Eßerbc 4.0.0
62*fdc4a7c8SStefan EßerCopyright (c) 2018-2021 Gavin D. Howard and contributors
63*fdc4a7c8SStefan EßerReport bugs at: https://git.yzena.com/gavin/bc
64*fdc4a7c8SStefan Eßer
65*fdc4a7c8SStefan EßerThis is free software with ABSOLUTELY NO WARRANTY.
66*fdc4a7c8SStefan Eßer```
67*fdc4a7c8SStefan Eßer
68*fdc4a7c8SStefan EßerBoth amd64. Happens every time on both.
69*fdc4a7c8SStefan Eßer
70*fdc4a7c8SStefan EßerI could give it a try on 13-STABLE too if that helps but I'd need to reboot something.
71*fdc4a7c8SStefan Eßer
72*fdc4a7c8SStefan EßerThe syntax error really has to be the FIRST input, even entering an empty line before it makes the problem not happen.
73*fdc4a7c8SStefan Eßer
74*fdc4a7c8SStefan EßerI 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*fdc4a7c8SStefan Eßer
76*fdc4a7c8SStefan Eßer## `gavin`
77*fdc4a7c8SStefan Eßer
78*fdc4a7c8SStefan EßerYeah, my `bc` uses a custom history implementation, so it could be mine, but not `editline(3)`.
79*fdc4a7c8SStefan Eßer
80*fdc4a7c8SStefan EßerI will pull up a FreeBSD VM and check it out. Sorry for the wait.
81*fdc4a7c8SStefan Eßer
82*fdc4a7c8SStefan Eßer## `gavin`
83*fdc4a7c8SStefan Eßer
84*fdc4a7c8SStefan EßerI 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*fdc4a7c8SStefan Eßer
86*fdc4a7c8SStefan EßerThis 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*fdc4a7c8SStefan Eßer
88*fdc4a7c8SStefan Eßer## `gavin`
89*fdc4a7c8SStefan Eßer
90*fdc4a7c8SStefan EßerI found the problem!
91*fdc4a7c8SStefan Eßer
92*fdc4a7c8SStefan EßerIt is fixed in `299a4fd353`, but if you can pull that down and test, I would appreciate it.
93*fdc4a7c8SStefan Eßer
94*fdc4a7c8SStefan EßerI 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*fdc4a7c8SStefan Eßer
96*fdc4a7c8SStefan EßerFeel free to reopen if the fix does not work for you.
97*fdc4a7c8SStefan Eßer
98*fdc4a7c8SStefan Eßer## `mathieu`
99*fdc4a7c8SStefan Eßer
100*fdc4a7c8SStefan EßerOof... yeah makes sense that an rc file could interfere with this.
101*fdc4a7c8SStefan Eßer
102*fdc4a7c8SStefan EßerYes, 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*fdc4a7c8SStefan Eßer
104*fdc4a7c8SStefan EßerThanks 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