Skip to content

Commit b7d0ad2

Browse files
committed
list: fix first()/last() invalid input ret code
list_first()/last() were returning an invalid CDADA_SUCCESS (false) when input was invalid. Reported-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2fdc0dc commit b7d0ad2

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Legend:
2020
- [B] bbitmap: make `cdada_bbitmap_dump()` set `size_used` in buffered paths too
2121
- [B] bbitmap: fix corrupted BSD license header in `bbitmap.h`
2222
- [B] str: fix uint32_t underflow in `cdada_str_rtraverse()` on empty strings
23+
- [B] list: fix `cdada_list_first()`/`cdada_list_last()` returning `CDADA_SUCCESS` on invalid input
2324
- [O] tests: add coverage for `cdada_strerr()` valid, boundary and high invalid values
2425
- [O] tests: add `oom_create_test` coverage for create paths (`list`, `map`, `queue`, `set`, `stack`, `str`, `bbitmap`)
2526
- [O] tests: add coverage for `cdada_str_replace_all()` empty-match invalid input and self-overlap replacement

src/list.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ static int __cdada_list_first_last(const cdada_list_t* list, bool first,
403403
__cdada_list_int_t* m = (__cdada_list_int_t*)list;
404404

405405
if(unlikely(!m || m->magic_num != CDADA_MAGIC || !key))
406-
return false;
406+
return CDADA_E_INVALID;
407407

408408
try{
409409
int c = m->ops? 0 : m->val_len;
@@ -452,7 +452,7 @@ static int __cdada_list_first_last(const cdada_list_t* list, bool first,
452452
}catch(...){}
453453

454454
CDADA_ASSERT(0);
455-
return false;
455+
return CDADA_E_UNKNOWN;
456456
}
457457

458458
int cdada_list_first(const cdada_list_t* list, void* key){

test/list_test.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,14 @@ int test_basics(){
12321232
rv = cdada_list_remove(list, NULL);
12331233
TEST_ASSERT(rv == CDADA_E_INVALID);
12341234

1235+
rv = cdada_list_first(NULL, ptr_not_null);
1236+
TEST_ASSERT(rv == CDADA_E_INVALID);
1237+
rv = cdada_list_first(list, NULL);
1238+
TEST_ASSERT(rv == CDADA_E_INVALID);
1239+
rv = cdada_list_last(NULL, ptr_not_null);
1240+
TEST_ASSERT(rv == CDADA_E_INVALID);
1241+
rv = cdada_list_last(list, NULL);
1242+
TEST_ASSERT(rv == CDADA_E_INVALID);
12351243

12361244
//Now destroy
12371245
rv = cdada_list_destroy(list);

0 commit comments

Comments
 (0)