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

Less crash-prone monitor config parser #9460

Merged
merged 2 commits into from
Feb 23, 2025
Merged

Less crash-prone monitor config parser #9460

merged 2 commits into from
Feb 23, 2025

Conversation

cyanbun96
Copy link
Contributor

monitor=HDMI-A-2, disabled 1680x1050, 1920x0, 1

The above config line crashes the entire app. stoi gets handed "disabled 1680" which is definitely not an integer. The check for "x" isn't enough to catch it. I'm unsure how (or if) this should be fixed so the band-aid try-catch hack is just a placeholder. Consider this a bug report.

@nnyyxxxx
Copy link
Contributor

i can repro this

@nnyyxxxx
Copy link
Contributor

I'm unsure how (or if) this should be fixed so the band-aid try-catch hack is just a placeholder. Consider this a bug report.

if thats the case then if i were you i would draft this

@nnyyxxxx
Copy link
Contributor

or this could just be moved to an issue lol

@cyanbun96
Copy link
Contributor Author

or this could just be moved to an issue lol

Weeeell... technically is does fix the issue it describes and doesn't seem to introduce any. It could be merged as-is. It just feels wrong to submit an earnest pull request that's a single try-catch statement where a more elegant solution could be better. Anyway, the acknowledgment and discussion of the issue are what I care about.

@nnyyxxxx
Copy link
Contributor

oh okay

@nnyyxxxx
Copy link
Contributor

image

we could do something like this

@gulafaran
Copy link
Contributor

you could use something like

auto is_numeric = [](const std::string& str) {
        return !str.empty() && std::all_of(str.begin(), str.end(), ::isdigit);
    };

to just make sure the string being passed to stoi is valid

@cyanbun96
Copy link
Contributor Author

you could use something like

auto is_numeric = [](const std::string& str) {
        return !str.empty() && std::all_of(str.begin(), str.end(), ::isdigit);
    };

to just make sure the string being passed to stoi is valid

That's good for this particular edge case and definitely better than a try-catch, though I wonder if there are other similar issues that it wouldn't catch. I mean, the "check for x" condition just above the problematic line was good enough too, until it wasn't.

@cyanbun96
Copy link
Contributor Author

image

we could do something like this

I struggle to come up with a good error message for this. I mean, the "disable/disabled" is supposed to be handled at the top of the function, but then it tries to interpret "disable 1680" as a single parameter in the resolution parser... Someone who understands that whole function and is good at error messages should chime in.

vaxerski
vaxerski previously approved these changes Feb 23, 2025
Copy link
Member

@vaxerski vaxerski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right. Every stoi should be in a try catch.

@vaxerski
Copy link
Member

vaxerski commented Feb 23, 2025

@gulafaran brother we have isNumber in hyprutils

anyways since we can't have a nothrow stoi from the stl just wrapping it in try catch is fine

@gulafaran
Copy link
Contributor

@gulafaran brother we have isNumber in hyprutils

anyways since we can't have a nothrow stoi from the stl just wrapping it in try catch is fine

oh so it seems, good to know :)

@vaxerski
Copy link
Member

missing clang-format

@cyanbun96
Copy link
Contributor Author

missing clang-format

sorry, fixed

@vaxerski vaxerski merged commit e594646 into hyprwm:main Feb 23, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants