bc: invalid expression is allowed by parser #892
Labels
Priority: low
get to this whenever
Program: bc
The bc program
Status: needs help
needs outside expertise or capacity
Type: bug
an existing feature does not work
After converting the c() function from the bc maths library to a "builtin" perl sub, I noticed the following illegal expression is accepted:
c(0.1, 0.2) + c()
The c() function requires one argument, but the functions are written to simply take the required arguments off an operand stack without much validation. I added trace statements to help debug this.
So the 0.1 argument is passed to neither instance of c(); instead it is taken last as an argument to the addition operator. The result of the 1st c() is taken as the argument to the 2nd c(). The result of the 2nd c() is added to 0.1, which is equivalent to:
To solve this, I think bc would need to be aware of the number of arguments a function is actually passed as per argument-list (a,b,c). Flattening all argument lists into a single operand stack results in loss of the argument count per function. I have no current solution at this time.
The text was updated successfully, but these errors were encountered: