From bf985c68acb1244f51ec91414532a2347fbc1c4c Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 13 Jul 2024 15:09:58 -0700 Subject: WriteXKMIndicators: dereference pointer after checking for NULL, not before MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found by gcc 14.1: xkmout.c: In function ‘WriteXKMIndicators’: xkmout.c:728:8: warning: check of ‘**result.xkb.indicators’ for NULL after already dereferencing it [-Wanalyzer-deref-before-check] 728 | if (xkb->indicators != NULL) { | ^ [...] ‘WriteXKMIndicators’: events 22-23 | | 727 | size += xkmPutCARD32(file, xkb->indicators->phys_indicators); | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | | (22) pointer ‘**result.xkb.indicators’ is dereferenced here | 728 | if (xkb->indicators != NULL) { | | ~ | | | | | (23) pointer ‘**result.xkb.indicators’ is checked for NULL here but it was already dereferenced at (22) Signed-off-by: Alan Coopersmith Part-of: --- src/xkmout.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/xkmout.c b/src/xkmout.c index 39655be..399f4cc 100644 --- a/src/xkmout.c +++ b/src/xkmout.c @@ -724,8 +724,8 @@ WriteXKMIndicators(FILE *file, XkbFileInfo *result, XkmInfo *info) dpy = xkb->dpy; size += xkmPutCARD8(file, info->num_leds); size += xkmPutPadding(file, 3); - size += xkmPutCARD32(file, xkb->indicators->phys_indicators); if (xkb->indicators != NULL) { + size += xkmPutCARD32(file, xkb->indicators->phys_indicators); for (i = 0; i < XkbNumIndicators; i++) { XkbIndicatorMapPtr map = &xkb->indicators->maps[i]; @@ -755,6 +755,9 @@ WriteXKMIndicators(FILE *file, XkbFileInfo *result, XkmInfo *info) } } } + else { + size += xkmPutCARD32(file, 0); + } return size; } -- cgit v1.2.3