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

main: Give error message on invalid integer or float argument #1716

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mstoeckl
Copy link

This replaces the calls atoi/atof in main.cpp with a function that detects and prints an error when the value being parsed is invalid.

This change has the typical costs and benefits of a tightened specification: new users may get quick feedback that commands like gamescope --sharpness 1.5 aren't meaningful, but this change could (until someone fixes them) break badly written scripts which invoke gamescope with invalid arguments that happened to work.

@misyltoad
Copy link
Collaborator

misyltoad commented Jan 22, 2025

We already haveParse<float> and Parse<int> that does those functions but better.

@mstoeckl
Copy link
Author

mstoeckl commented Jan 22, 2025

We already have Parse<float> and Parse<int> that does those functions but better.

Good point, better to stick to one set of string parsing routines (and avoid C's locale complications). I've updated the PR to use them, and have slightly adjusted the code style to match recent updates to the code.

(Note: like atoi/atof, gamescope::Parse<T> currently parses the prefix of the input string, and does not check that the entire string is consumed; it thus parses "1x2" as "1" instead of rejecting the value. Since Parse is used in many places, changing it to check that result.ptr == chars.end() would be risky---I think it breaks GetKernelVersion(), and it's used by too many ConVar's for me to review them all today---so I have not changed the way Parse works.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants