From e0589e4d74e738a1f6aca3ee97e445d5cea295e0 Mon Sep 17 00:00:00 2001 From: NRK <nrk@disroot.org> 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 90baafc..4b3e8b7 100644 --- a/src/scrot.c +++ b/src/scrot.c @@ -480,12 +480,9 @@ Window scrotGetWindow(Display *display, Window window, int x, int y) void scrotGrabMousePointer(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; @@ -499,10 +496,8 @@ void scrotGrabMousePointer(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; @@ -514,8 +509,6 @@ void scrotGrabMousePointer(Imlib_Image image, const int xOffset, height); imlib_context_set_image(imcursor); imlib_free_image(); - -end: XFree(xcim); }