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

fixed segfault when screen number exceeds screen count #2534

Merged
merged 1 commit into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/core/flameshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ CaptureWidget* Flameshot::gui(const CaptureRequest& req)
return m_captureWindow;
} else {
emit captureFailed();
return nullptr;
}
}

Expand All @@ -151,6 +152,11 @@ void Flameshot::screen(CaptureRequest req, const int screenNumber)
screen =
qApp->screens()[qApp->desktop()->screenNumber(globalCursorPos)];
#endif
} else if (screenNumber >= qApp->screens().count()) {
AbstractLogger() << QObject::tr(
"Requested screen exceeds screen count");
emit captureFailed();
return;
} else {
screen = qApp->screens()[screenNumber];
}
Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ int main(int argc, char* argv[])

QString numberStr = parser.value(screenNumberOption);
// Option values
int number =
int screenNumber =
numberStr.startsWith(QLatin1String("-")) ? -1 : numberStr.toInt();
QString path = parser.value(pathOption);
if (!path.isEmpty()) {
Expand All @@ -455,7 +455,7 @@ int main(int argc, char* argv[])
bool pin = parser.isSet(pinOption);
bool upload = parser.isSet(uploadOption);

CaptureRequest req(CaptureRequest::SCREEN_MODE, delay, number);
CaptureRequest req(CaptureRequest::SCREEN_MODE, delay, screenNumber);
if (!region.isEmpty()) {
if (region.startsWith("screen")) {
// TODO use abstract logger
Expand Down