From 9ab8e7f783af2946e535964ba1fc83ee8d1decef Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 13 Jan 2017 12:03:29 +1000 Subject: [PATCH] util: make all property parsing helpers ignore NULL strings Signed-off-by: Peter Hutterer --- src/libinput-util.c | 12 ++++++++++++ test/test-misc.c | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/libinput-util.c b/src/libinput-util.c index 7f0701e5..40e1e6e5 100644 --- a/src/libinput-util.c +++ b/src/libinput-util.c @@ -144,6 +144,9 @@ parse_mouse_dpi_property(const char *prop) bool is_default = false; int nread, dpi = 0, rate; + if (!prop) + return 0; + while (*prop != 0) { if (*prop == ' ') { prop++; @@ -190,6 +193,9 @@ parse_mouse_wheel_click_count_property(const char *prop) { int count = 0; + if (!prop) + return 0; + if (!safe_atoi(prop, &count) || abs(count) > 360) return 0; @@ -211,6 +217,9 @@ parse_mouse_wheel_click_angle_property(const char *prop) { int angle = 0; + if (!prop) + return 0; + if (!safe_atoi(prop, &angle) || abs(angle) > 360) return 0; @@ -230,6 +239,9 @@ parse_trackpoint_accel_property(const char *prop) { double accel; + if (!prop) + return 0.0; + if (!safe_atod(prop, &accel)) accel = 0.0; diff --git a/test/test-misc.c b/test/test-misc.c index 00399d4d..ed5471db 100644 --- a/test/test-misc.c +++ b/test/test-misc.c @@ -718,6 +718,9 @@ START_TEST(dpi_parser) dpi = parse_mouse_dpi_property(tests[i].tag); ck_assert_int_eq(dpi, tests[i].expected_value); } + + dpi = parse_mouse_dpi_property(NULL); + ck_assert_int_eq(dpi, 0); } END_TEST @@ -772,6 +775,9 @@ START_TEST(wheel_click_count_parser) angle = parse_mouse_wheel_click_count_property(tests[i].tag); ck_assert_int_eq(angle, tests[i].expected_value); } + + angle = parse_mouse_wheel_click_count_property(NULL); + ck_assert_int_eq(angle, 0); } END_TEST @@ -798,6 +804,9 @@ START_TEST(trackpoint_accel_parser) accel = parse_trackpoint_accel_property(tests[i].tag); ck_assert(accel == tests[i].expected_value); } + + accel = parse_trackpoint_accel_property(NULL); + ck_assert_double_eq(accel, 0.0); } END_TEST @@ -844,6 +853,9 @@ START_TEST(dimension_prop_parser) ck_assert_int_eq(y, 0xad); } } + + success = parse_dimension_property(NULL, &x, &y); + ck_assert(success == false); } END_TEST