JoeStrout / miniscript

source code of both C# and C++ implementations of the MiniScript scripting language
MIT License
270 stars 62 forks source link

[C++] _dateStr overflow affects subsequent floating point numbers #164

Closed kseistrup closed 3 weeks ago

kseistrup commented 1 month ago

REPL

» miniscript
MiniScript 
Command-Line (Linux) v1.3; language v1.6.2 (Jul 15 2024)
> // # This is fine:
> sqrt(2)
1.414214
> 1.2345
1.2345
> _dateStr 77777777777777777
-1830285635-101-00 20:56:16
> // # But now everything is fscked up:
> sqrt(2)
1,414214
> 1.2345
1
> 1,2345
Compiler Error: got Comma where number, string, or identifier is required [line 1]

Scripting

» cat float.ms
#!/usr/bin/env miniscript

print sqrt(2)
print 1.2345
print _dateStr(77777777777777777)
print sqrt(2)
print 1.2345
print 1,2345

// eof
» chmod +x float.ms
» ./float.ms
1.414214
1.2345
-1830285635-101-00 20:56:16
1,414214
1,2345
12345<EOL>  # no line feed

Locale

LANG=en_DK.UTF-8
LC_ALL=en_DK.UTF-8
kseistrup commented 1 month ago

:paperclip: float.ms

kseistrup commented 1 month ago

Also, because _dateStr(77777777777777777) seems to wreak havoc:

MiniScript 
Command-Line (Linux) v1.3; language v1.6.2 (Jul 15 2024)
> _dateStr 77777777777777777
-1830285635-101-00 20:56:16
> _dateStr 77777777777777777
-1830285635--817198303-32767 20:56:16

edit: typo

marcgurevitx commented 1 month ago

@kseistrup Are those still reproduced after this patch is applied? https://github.com/JoeStrout/miniscript/pull/162

kseistrup commented 1 month ago

@marcgurevitx

No, then I just get an empty string for overflowing dates, and subsequent floating points are unaffected.

(I'm not on Windows, I only inserted the two new lines 35+36 since everything else seemed irrelevant.)

:+1:

JoeStrout commented 3 weeks ago

Closing thanks to PR#162.