dworkin / dgd

Dworkin's Game Driver, an object-oriented database management system originally used to run MUDs.
https://www.dworkin.nl/dgd/
GNU Affero General Public License v3.0
103 stars 31 forks source link

Casting string to float with 'e' exponent component #41

Closed nyankers closed 3 years ago

nyankers commented 3 years ago

When converting a string to a float with an exponent E (eg. 42e+9), Float::atof() is very permissive of what the first character can be after that 'e'/'E'.

For example (float) "42ea" produces 4.2e+50, and ({ sscanf("42ea b", "%f%s", a, b), a, b }) returns ({ 2, 4.2e+50, " b"}) (note sscanf() internally uses the same Float::atof()).

The LPC compiler will treat 42ea as error (that is, it treats the "ea" portion as a separate token which then fails), so I'd expect casting strings to do the same. Likewise, I'd expect the latter expression to instead return ({ 2, 42.0, "ea b" }).

I've written a possible solution to this to help identify where the issue is.

(As usual, above was tested using latest dgd + cloud server, and can be tested through admin 'code' command.)

dworkin commented 3 years ago

Your analysis is correct and your fix is good, but incomplete (details in the pull request comments).

While looking into this, I found another issue with float parsing, which is now fixed in the master branch.