intel / webapps-scientific-calculator

Apache License 2.0
27 stars 33 forks source link

Invalid formula triggers infinite loop (unresponsive script) #15

Closed michaelpradel closed 10 years ago

michaelpradel commented 10 years ago

Entering an invalid formula and pressing the "=" button can lead to an infinite loop that makes the app unresponsive. For example, enter 1+cos-15 or 1*cos-15. The problem is is in peg-code.txt, which fails to check whether the right-hand side of an additive or multiplicative is NaN. To fix the problem, you can insert the following check at lines 21 and 59 of peg-code.txt:

  if (isNaN(num)) 
      return num;

Thanks, Michael

davidmaxwaterman commented 10 years ago

Hi, I'm looking at this, but I don't seem to be able to enter the two examples you give - they both seem to result in 'Malformed expression'. Can you explain what I am missing? Thanks!

michaelpradel commented 10 years ago

Interesting. I was working with an older version of the app and it seems the problem is fixed in the current version.

Thanks, Michael

davidmaxwaterman commented 10 years ago

Yes, interesting...I'm not aware of any changes that would fix the infinite loop. Might it be due to a newer version of peg?

It'd be nice to know what the cause was, and the fix; but otherwise I suppose we could just close this. since.

davidmaxwaterman commented 10 years ago

no response, so closing.