[PATCH app/xrandr] init the name to 0

Peter Hutterer peter.hutterer at who-t.net
Wed Sep 12 23:50:23 UTC 2018


There are a few conditions where coverity finds a use of an uninitialized
field of the name_t struct. These are rather messy combinations of conditions,
so let's go with the simple solution here and just init everything to 0.
This may still have side-effects but at least they'll be more obvious than the
previous "use whatever memory is leftover from breakfast".

This patch also adds a missing init_name(), much for the same reason.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 xrandr.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/xrandr.c b/xrandr.c
index 7f1e867..ce3cd91 100644
--- a/xrandr.c
+++ b/xrandr.c
@@ -637,6 +637,7 @@ print_verbose_mode (const XRRModeInfo *mode, Bool current, Bool preferred)
 static void
 init_name (name_t *name)
 {
+    memset(name, 0, sizeof(*name));
     name->kind = name_none;
 }
 
@@ -1822,6 +1823,7 @@ get_outputs (void)
 	output_t	*output;
 	name_t		output_name;
 	if (!output_info) fatal ("could not get output 0x%lx information\n", res->outputs[o]);
+	init_name(&output_name);
 	set_name_xid (&output_name, res->outputs[o]);
 	set_name_index (&output_name, o);
 	set_name_string (&output_name, output_info->name);
-- 
2.17.1



More information about the xorg-devel mailing list