Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2026-06-28 Todd White <todd.white@thalion.global>
* Source/CFArray.c (CFArrayGetLastIndexOfValue): Start the backward
scan at range.location + range.length - 1 instead of one past the
end of the range.
* Tests/CFArray/create.m: Regression test.

2021-09-30 Frederik Seiffert <frederik@algoriddim.com>
* Source/CFDate.c: Fix logic in CFGregorianDateIsValid()

Expand Down
2 changes: 1 addition & 1 deletion Source/CFArray.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ CFArrayGetLastIndexOfValue (CFArrayRef array, CFRange range, const void *value)
equal = array->_callBacks->equal;

start = range.location;
idx = start + range.length;
idx = start + range.length - 1;

if (equal)
{
Expand Down
8 changes: 7 additions & 1 deletion Tests/CFArray/create.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ int main (void)

n = (CFIndex)CFArrayGetValueAtIndex (a, 1);
PASS_CF(n == 2, "Found value at index %d.", (int)n);


n = CFArrayGetLastIndexOfValue (a, CFRangeMake(0, ARRAY_SIZE), (const void*)4);
PASS_CF(n == 3, "Last index of value 4 is %d.", (int)n);
/* Searching the whole array must not read one past the end of the range. */
n = CFArrayGetLastIndexOfValue (a, CFRangeMake(0, ARRAY_SIZE), (const void*)99);
PASS_CF(n == -1, "Absent value is reported as not found (%d).", (int)n);

CFRelease (a);

a = CFArrayCreate (NULL, NULL, 0, NULL);
Expand Down
Loading