Skip to content

Commit

Permalink
fixed segfault when screen number exceeds screen count (flameshot-org…
Browse files Browse the repository at this point in the history
  • Loading branch information
borgmanJeremy authored Apr 7, 2022
1 parent e1b55d3 commit 0c9a58f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
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

0 comments on commit 0c9a58f

Please sign in to comment.