diff --git a/src/core/flameshot.cpp b/src/core/flameshot.cpp index ae68cb5a01..196e878932 100644 --- a/src/core/flameshot.cpp +++ b/src/core/flameshot.cpp @@ -132,6 +132,7 @@ CaptureWidget* Flameshot::gui(const CaptureRequest& req) return m_captureWindow; } else { emit captureFailed(); + return nullptr; } } @@ -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]; } diff --git a/src/main.cpp b/src/main.cpp index 500cf38c5d..1d4ddd1b03 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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()) { @@ -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