Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser truncates values #95

Open
PMeira opened this issue Apr 6, 2021 · 1 comment
Open

Parser truncates values #95

PMeira opened this issue Apr 6, 2021 · 1 comment
Milestone

Comments

@PMeira
Copy link
Member

PMeira commented Apr 6, 2021

The OpenDSS parser uses the Val function, e.g.

Val(TokenBuffer, Result, Code); // Try direct conversion to integer

Most integers in OpenDSS are 32-bit values. If the input is larger than the max value, the value is truncated (upper bits dropped).

The results in DSS C-API are the same as in the official binaries, but we could add optional error messages to warn of this behavior.

Since the values are truncated instead of clipped to max/min, this can be dangerous.

Low priority.

@PMeira PMeira added this to the 1.0 milestone May 15, 2021
@PMeira
Copy link
Member Author

PMeira commented Oct 26, 2021

TryStrToInt is an alternative but there's an issue in current FPC versions: https://gitlab.com/freepascal.org/fpc/source/-/issues/39406

Using the native range checking should be enough in Free Pascal, without affecting the whole thing:

Remark The standard functions val and Read will also check ranges when the call is compiled in {$R+} mode.
In Delphi, range checking is only switchable at the procedure level. In Free Pascal, the {$R } directive can be used at the expression level.

@PMeira PMeira modified the milestones: 1.0, 2.0 Mar 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant