From 4fd5fe9d30cdd6d691d16510213b838ab268b125 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 4 Nov 2025 15:45:42 +1000 Subject: [PATCH] Fix clang-tidy false positives Array out of bounds complaints but it's a false positive where clang-tidy makes up some event flow that cannot happen. Part-of: --- src/libinput-versionsort.h | 3 ++- src/quirks.c | 4 +++- src/util-strings.c | 1 + src/util-strings.h | 2 +- test/litest-main.c | 20 +++++++++++++++----- test/litest.h | 2 +- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/libinput-versionsort.h b/src/libinput-versionsort.h index d9f4c74b..ad0190b3 100644 --- a/src/libinput-versionsort.h +++ b/src/libinput-versionsort.h @@ -39,7 +39,8 @@ libinput_strverscmp(const char *l0, const char *r0) /* Find maximal matching prefix and track its maximal digit * suffix and whether those digits are all zeros. */ - for (dp = i = 0; l[i] == r[i]; i++) { + for (dp = i = 0; l[i] == r[i]; /* NOLINT(clang-analyzer-security.ArrayBound) */ + i++) { int c = l[i]; if (!c) return 0; diff --git a/src/quirks.c b/src/quirks.c index 9ccb964a..6364549c 100644 --- a/src/quirks.c +++ b/src/quirks.c @@ -1568,7 +1568,9 @@ quirk_merge_event_codes(struct quirks_context *ctx, newprop->type = property->type; newprop->value.tuples = property->value.tuples; /* Caller responsible for pre-allocating space */ - q->properties[q->nproperties++] = property_ref(newprop); + q->properties[q->nproperties++] = /* NOLINT(clang-analyzer-security.ArrayBound) + */ + property_ref(newprop); list_append(&q->floating_properties, &newprop->link); } diff --git a/src/util-strings.c b/src/util-strings.c index 3d36c9b6..20cc0798 100644 --- a/src/util-strings.c +++ b/src/util-strings.c @@ -200,6 +200,7 @@ strv_from_string(const char *in, const char *separators, size_t *num_elements) return NULL; } + assert(idx < strv_len); strv[idx++] = copy; } diff --git a/src/util-strings.h b/src/util-strings.h index 291ae5df..94236c48 100644 --- a/src/util-strings.h +++ b/src/util-strings.h @@ -356,7 +356,7 @@ strv_free(char **strv) if (!strv) return; - while (*s != NULL) { + while (*s != NULL) { /* NOLINT(clang-analyzer-security.ArrayBound) */ free(*s); *s = (char *)0x1; /* detect use-after-free */ s++; diff --git a/test/litest-main.c b/test/litest-main.c index 6fc31dac..c5584ffa 100644 --- a/test/litest-main.c +++ b/test/litest-main.c @@ -141,8 +141,13 @@ static void litest_init_test_devices(void) { const struct test_device *t; - for (t = &__start_test_device_section; t < &__stop_test_device_section; t++) - litest_add_test_device(&t->device->node); + const struct test_device *start = &__start_test_device_section; + const struct test_device *stop = &__stop_test_device_section; + + for (t = start; t < stop; t++) + litest_add_test_device( + &t->device->node); /* NOLINT(clang-analyzer-security.ArrayBound) + */ } extern const struct test_collection __start_test_collection_section, @@ -151,13 +156,18 @@ extern const struct test_collection __start_test_collection_section, static void setup_tests(void) { + /* Iterate through linker-provided section boundaries. + * These symbols mark the start and end of the test_collection_section. */ + const struct test_collection *start = &__start_test_collection_section; + const struct test_collection *stop = &__stop_test_collection_section; const struct test_collection *c; - for (c = &__start_test_collection_section; c < &__stop_test_collection_section; - c++) { + for (c = start; c < stop; + c++) { /* NOLINT(clang-analyzer-security.ArrayBound) */ struct suite *s; s = zalloc(sizeof(*s)); - s->name = safe_strdup(c->name); + s->name = safe_strdup( + c->name); /* NOLINT(clang-analyzer-security.ArrayBound) */ list_init(&s->tests); list_append(&all_test_suites, &s->node); diff --git a/test/litest.h b/test/litest.h index 68512f65..9aa76f3c 100644 --- a/test/litest.h +++ b/test/litest.h @@ -631,7 +631,7 @@ struct axis_replacement { static inline void litest_axis_set_value_unchecked(struct axis_replacement *axes, int code, double value) { - while (axes->evcode != -1) { + while (axes->evcode != -1) { /* NOLINT(clang-analyzer-security.ArrayBound) */ if (axes->evcode == code) { axes->value = value; return;