Adding zero to a NULL pointer is undefined behaviour, which is getting
clarified with C23 (or just after) to match our current usage.
With clang 18, this triggers the undefined behaviour sanitizer so add a
check to stay compliant.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/180
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
int array_append_unique(struct array *array, const void *element)
{
void **itr = array->array;
- void **itr_end = itr + array->count;
- for (; itr < itr_end; itr++)
- if (*itr == element)
- return -EEXIST;
+
+ if (array->count != 0) {
+ void **itr_end = itr + array->count;
+
+ for (; itr < itr_end; itr++)
+ if (*itr == element)
+ return -EEXIST;
+ }
return array_append(array, element);
}
bucket = hash->buckets;
bucket_end = bucket + hash->n_buckets;
for (; bucket < bucket_end; bucket++) {
- if (hash->free_value) {
+ if (hash->free_value && bucket->used != 0) {
struct hash_entry *entry, *entry_end;
entry = bucket->entries;
entry_end = entry + bucket->used;
sorted[n_sorted] = src_idx;
n_sorted++;
+ if (src->deps.count == 0)
+ continue;
+
itr_dst = (const struct mod **)src->deps.array;
itr_dst_end = itr_dst + src->deps.count;
for (; itr_dst < itr_dst_end; itr_dst++) {