Fix a few potential NULL dereferences

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1052>
This commit is contained in:
Peter Hutterer 2024-09-20 21:33:38 +10:00 committed by Marge Bot
parent 1790171c76
commit 54dccd66d1
3 changed files with 6 additions and 4 deletions

View file

@ -419,7 +419,7 @@ strstrip(const char *input, const char *what)
last = str;
for (char *c = str; *c != '\0'; c++) {
for (char *c = str; c && *c != '\0'; c++) {
if (!strchr(what, *c))
last = c + 1;
}

View file

@ -1218,8 +1218,10 @@ START_TEST(double_array_from_string_test)
&len);
ck_assert_int_eq(len, t->len);
for (size_t idx = 0; idx < len; idx++)
for (size_t idx = 0; idx < len; idx++) {
ck_assert_ptr_nonnull(array);
ck_assert_double_eq(array[idx], t->array[idx]);
}
free(array);
t++;

View file

@ -360,7 +360,7 @@ tools_parse_option(int option,
size_t npoints = 0;
double *range = double_array_from_string(optarg, ":", &npoints);
if (npoints != 2 || range[0] < 0.0 || range[1] > 1.0 || range[0] >= range[1]) {
if (npoints != 2 || !range || range[0] < 0.0 || range[1] > 1.0 || range[0] >= range[1]) {
free(range);
fprintf(stderr, "Invalid pressure range, must be in format \"min:max\"\n");
return 1;
@ -376,7 +376,7 @@ tools_parse_option(int option,
size_t npoints = 0;
double *matrix = double_array_from_string(optarg, " ", &npoints);
if (npoints != 6) {
if (!matrix || npoints != 6) {
free(matrix);
fprintf(stderr, "Invalid calibration matrix, must be 6 space-separated values\n");
return 1;