[PATCH 05/18] int_array: Only iterate existing elements in equality check
Benjamin Berg
benjamin at sipsolutions.net
Thu Oct 30 01:24:36 PDT 2025
From: Benjamin Berg <benjamin.berg at intel.com>
Fix the upper bound of the for loop to terminate before the final
element is reached. Without this fix, the loop would try to find the
trailing zero in the second array, resulting in the comparison to be
always false.
Fixes: 56f7d76d745a ("int_array: Add a function to check for equality")
CC: Rohan Dutta <quic_drohan at quicinc.com>
Signed-off-by: Benjamin Berg <benjamin.berg at intel.com>
---
As-is, this function is more weird beyond the fact that it always
returned false. It uses an O(n^2) algorithm for comparison and in
addition iterates both arrays twice just to find their length. It also
doesn't care about the order of elements, which is fine in a way, but
then the term "equal" seems odd as the data structure is called "array"
and not "set". Finally, it does assume uniqueness of all elements, which
is somewhat reasonable (there is only int_array_add_unique), but it
doesn't seem quite safe considering you can build arrays with duplicate
entries using e.g. int_array_concat.
Benjamin
Signed-off-by: Benjamin Berg <benjamin.berg at intel.com>
---
src/utils/common.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/utils/common.c b/src/utils/common.c
index d90bdb989b..1f34adf0af 100644
--- a/src/utils/common.c
+++ b/src/utils/common.c
@@ -1016,7 +1016,7 @@ bool int_array_equal(const int *a, const int *b)
if (alen != blen)
return false;
- for (i = 0; i <= alen; i++) {
+ for (i = 0; i < alen; i++) {
if (!int_array_includes(b, a[i]))
return false;
}
--
2.51.0
More information about the Hostap
mailing list