[PATCH libinput] test: fix Coverity complaints

Peter Hutterer peter.hutterer at who-t.net
Wed Feb 18 13:28:44 PST 2015


seat_button_count
seat_key_count ... uninitialized variable

t = zalloc
s = zalloc ... dereferencing potential NULL-pointer

d->ntouches_down... side-effect in assertion

Coverity run against the 0.10.0 tag, see
https://scan.coverity.com/projects/4298

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 test/keyboard.c | 2 +-
 test/litest.c   | 9 +++++++--
 test/pointer.c  | 2 +-
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/test/keyboard.c b/test/keyboard.c
index 4563ce6..cb7ad52 100644
--- a/test/keyboard.c
+++ b/test/keyboard.c
@@ -36,7 +36,7 @@ START_TEST(keyboard_seat_key_count)
 	struct libinput_event *ev;
 	struct libinput_event_keyboard *kev;
 	int i;
-	int seat_key_count;
+	int seat_key_count = 0;
 	int expected_key_button_count = 0;
 	char device_name[255];
 
diff --git a/test/litest.c b/test/litest.c
index b220b2f..16d9239 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -184,6 +184,7 @@ litest_add_tcase_for_device(struct suite *suite,
 	}
 
 	t = zalloc(sizeof(*t));
+	assert(t != NULL);
 	t->name = strdup(test_name);
 	t->tc = tcase_create(test_name);
 	list_insert(&suite->tests, &t->node);
@@ -215,6 +216,7 @@ litest_add_tcase_no_device(struct suite *suite, void *func)
 	}
 
 	t = zalloc(sizeof(*t));
+	assert(t != NULL);
 	t->name = strdup(test_name);
 	t->tc = tcase_create(test_name);
 	list_insert(&suite->tests, &t->node);
@@ -270,6 +272,7 @@ get_suite(const char *name)
 	}
 
 	s = zalloc(sizeof(*s));
+	assert(s != NULL);
 	s->name = strdup(name);
 	s->suite = suite_create(s->name);
 
@@ -808,7 +811,8 @@ litest_touch_down(struct litest_device *d, unsigned int slot,
 {
 	struct input_event *ev;
 
-	assert(++d->ntouches_down > 0);
+	assert(d->ntouches_down >= 0);
+	d->ntouches_down++;
 
 	send_btntool(d);
 
@@ -836,7 +840,8 @@ litest_touch_up(struct litest_device *d, unsigned int slot)
 		{ .type = -1, .code = -1 }
 	};
 
-	assert(--d->ntouches_down >= 0);
+	assert(d->ntouches_down > 0);
+	d->ntouches_down--;
 
 	send_btntool(d);
 
diff --git a/test/pointer.c b/test/pointer.c
index 2e52a20..24ea726 100644
--- a/test/pointer.c
+++ b/test/pointer.c
@@ -470,7 +470,7 @@ START_TEST(pointer_seat_button_count)
 	struct libinput_event *ev;
 	struct libinput_event_pointer *tev;
 	int i;
-	int seat_button_count;
+	int seat_button_count = 0;
 	int expected_seat_button_count = 0;
 	char device_name[255];
 
-- 
2.1.0



More information about the wayland-devel mailing list