tests: chip: fix potential segfault
authorBartosz Golaszewski <bartekgola@gmail.com>
Wed, 14 Jun 2017 05:48:00 +0000 (07:48 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Wed, 14 Jun 2017 05:48:00 +0000 (07:48 +0200)
The automatically cleaned up string is not initialized, but if
asprintf() failed, its contents would be undefined which could lead
to a segmentation fault.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
tests/tests-chip.c

index ef905ca999ac6100716045ace52ea34433fcf7ac..09fe82ea5f79d754e0f0ed6738f74c0a05b7b865 100644 (file)
@@ -76,7 +76,7 @@ static void chip_open_lookup(void)
        TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip_by_name = NULL;
        TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip_by_path = NULL;
        TEST_CLEANUP(test_close_chip) struct gpiod_chip *chip_by_num = NULL;
-       TEST_CLEANUP(test_free_str) char *chip_num;
+       TEST_CLEANUP(test_free_str) char *chip_num = NULL;
 
        TEST_ASSERT(asprintf(&chip_num, "%u", test_chip_num(1)) > 0);