From 49b77895e6aa86dc9d1aa5cac7caad7474ea4fb9 Mon Sep 17 00:00:00 2001 From: dingfei Date: Fri, 24 May 2024 11:02:33 +0800 Subject: [PATCH 1/2] fix potential null deref reported by static analyzer Calling 'xdo_translate_window_with_sizehint' from 'xdo_set_window_size' shows both 'width_ret' and 'height_ret' could be null. Storing values into these pointers could be a null deref. If these two pointers couldn't be null, then the condition in the following if (width_ret != NULL) { *width_ret = width; } if (height_ret != NULL) { *height_ret = height; } is redundant, this is a reversed null checking. --- xdo.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/xdo.c b/xdo.c index ffb0333..96dbe67 100644 --- a/xdo.c +++ b/xdo.c @@ -287,8 +287,12 @@ int xdo_translate_window_with_sizehint(const xdo_t *xdo, Window window, height *= hints.height_inc; } else { fprintf(stderr, "No size hints found for window %ld\n", window); - *width_ret = width; - *height_ret = width; + if (width_ret != NULL) { + *width_ret = width; + } + if (height_ret != NULL) { + *height_ret = width; + } } if (supplied_return & PBaseSize) { From c3d014cded1b896698c8bdb86e77ce24e4c729be Mon Sep 17 00:00:00 2001 From: dingfei Date: Fri, 24 May 2024 11:32:54 +0800 Subject: [PATCH 2/2] remove these redundant assignments --- xdo.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/xdo.c b/xdo.c index 96dbe67..df79d29 100644 --- a/xdo.c +++ b/xdo.c @@ -287,12 +287,6 @@ int xdo_translate_window_with_sizehint(const xdo_t *xdo, Window window, height *= hints.height_inc; } else { fprintf(stderr, "No size hints found for window %ld\n", window); - if (width_ret != NULL) { - *width_ret = width; - } - if (height_ret != NULL) { - *height_ret = width; - } } if (supplied_return & PBaseSize) {