mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-02-13 16:10:33 +01:00
util: make all property parsing helpers ignore NULL strings
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
7c6784dd81
commit
9ab8e7f783
2 changed files with 24 additions and 0 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue