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

sscanf number on hyphen #63

Closed nyankers closed 2 years ago

nyankers commented 2 years ago

Hi, I'm not sure if this is a bug or if it's in fact an intended nuance of sscanf().

Should sscanf("-", "%d", x) treat it as a match (return 1) and store 0 in x?

I also see similar behavior with "%f".

Easily tested in cloud server via code ({ sscanf("-", "%d", a), a }).

dworkin commented 2 years ago

Definitely a bug.

dworkin commented 2 years ago

Should be fixed by 8acd15f96c60812b897b64a7464e025e96fa33b0.

nyankers commented 2 years ago

That fixes the int-related issues, but I noticed the float issues are a bit more extensive, e.g. even after the fix, it'll accept (float) "." as 0.0. This fix also breaks (float) "-.50" whereas (float) ".50" works.

(The same code is used for both sscanf() and (float).)

I'll submit a push request with a possible solution, unless (float) ".50" and (float) "-.50" are unintentional behavior too, in which case it'll need further adjustments (though they're accepted as LPC, so I assume they should be accepted here too).

dworkin commented 2 years ago

I used a different fix, 4aa22ce24d1666e7f44264deb36cd36d1ed66a43.

nyankers commented 2 years ago

Ah, I didn't realize 5. was also an acceptable LPC float literal, but it apparently is (and so my suggestion would have broken otherwise valid LPC code). Thanks!

I don't see anything this version breaks. If I find out later, I'll of course let you know. ^^