From f93a551aa9487f19ddd4e87cb3cbaa952402996b Mon Sep 17 00:00:00 2001 From: NRK Date: Thu, 25 May 2023 20:10:10 +0600 Subject: [PATCH] scrotGrabMousePointer: error in case of failure if the user asks us to grab the pointer, we should either do that otherwise fail rather than continuing on. also remove a redundant comment, it should be clear that a function named XFixesGetCursorImage is indeed returning back a cursor image. ref: https://github.com/resurrecting-open-source-projects/scrot/issues/272 --- src/scrot.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/scrot.c b/src/scrot.c index b6798fa..ccf0d48 100644 --- a/src/scrot.c +++ b/src/scrot.c @@ -448,12 +448,9 @@ Window scrotGetWindow(Display *display, Window window, int x, int y) void scrotGrabMousePointer(const Imlib_Image image, const int xOffset, const int yOffset) { - XFixesCursorImage *xcim = NULL; - /* Get the X cursor and the information we want. */ - if ((xcim = XFixesGetCursorImage(disp)) == NULL) { - warnx("Can't get the cursor from X"); - goto end; - } + XFixesCursorImage *xcim = XFixesGetCursorImage(disp); + if (!xcim) + errx(EXIT_FAILURE, "Can't get the cursor from X"); const unsigned short width = xcim->width; const unsigned short height = xcim->height; const size_t pixcnt = (size_t)width*height; @@ -467,10 +464,8 @@ void scrotGrabMousePointer(const Imlib_Image image, const int xOffset, } Imlib_Image imcursor = imlib_create_image_using_data(width, height, pixels); - if (!imcursor) { - warnx("Can't create cursor image"); - goto end; - } + if (!imcursor) + errx(EXIT_FAILURE, "Can't create cursor image"); /* Overlay the cursor into `image`. */ const int x = (xcim->x - xcim->xhot) - xOffset; @@ -482,8 +477,6 @@ void scrotGrabMousePointer(const Imlib_Image image, const int xOffset, height); imlib_context_set_image(imcursor); imlib_free_image(); - -end: XFree(xcim); }