From ba8cd2abe47e30344cbeb99dcc7cf22d9730f4d3 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sat, 25 Apr 2015 12:44:21 +0200 Subject: [PATCH] Handle NULL pointer as good as possible (Coverity #50099) As pointed by Coverity, in the "Configuration" panel of WPrefs there are some images loaded, but if the images cannot be loaded correctly then the returned NULL pointer can crash the application as it is dereferenced in further function calls. To solve this case, this patch is adding a NULL pointer check in the functions RScaleImage (wrlib) and WMCreatePixmapFromRImage (WINGs), so both can accept that NULL pointer to also return NULL, which means the existing check for "icon == NULL" in the WPrefs code will be useful. Signed-off-by: Christophe CURIS --- WINGs/wpixmap.c | 3 +++ wrlib/scale.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/WINGs/wpixmap.c b/WINGs/wpixmap.c index 272e56ac..5ad311cb 100644 --- a/WINGs/wpixmap.c +++ b/WINGs/wpixmap.c @@ -85,6 +85,9 @@ WMPixmap *WMCreatePixmapFromRImage(WMScreen * scrPtr, RImage * image, int thresh WMPixmap *pixPtr; Pixmap pixmap, mask; + if (image == NULL) + return NULL; + if (!RConvertImageMask(scrPtr->rcontext, image, &pixmap, &mask, threshold)) { return NULL; } diff --git a/wrlib/scale.c b/wrlib/scale.c index 0f5952c8..94612333 100644 --- a/wrlib/scale.c +++ b/wrlib/scale.c @@ -52,6 +52,9 @@ RImage *RScaleImage(RImage * image, unsigned new_width, unsigned new_height) unsigned char *d; RImage *img; + if (image == NULL) + return NULL; + if (new_width == image->width && new_height == image->height) return RCloneImage(image); -- 2.11.4.GIT