test: fix Coverity complaints
authorPeter Hutterer <peter.hutterer@who-t.net>
Wed, 18 Feb 2015 21:22:59 +0000 (07:22 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Fri, 20 Feb 2015 00:03:09 +0000 (10:03 +1000)
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@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Christian Hartmann <cornogle@googlemail.com>
test/keyboard.c
test/litest.c
test/pointer.c

index 4563ce6ff78af2541435eb22d1bb7b12051e7d9c..cb7ad52203124df57f2178a45429832d28a52d5f 100644 (file)
@@ -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];
 
index b220b2fe06879cb53b241600144b609becff47d5..16d92399c854a7c28df0e55fa69a2765d6b10231 100644 (file)
@@ -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);
 
index 2e52a2065d79d0f92aa9cc263a5293d1431206c1..24ea726666249637f5cb81580f59c003cd4cffbf 100644 (file)
@@ -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];