Skip to content

Commit 2fdc0dc

Browse files
committed
str: fix underflow in rtraverse() on empty strings
Fix possible str underflow with empty strings. Reported-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2d167b6 commit 2fdc0dc

2 files changed

Lines changed: 3 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Legend:
1919
- [B] str: align `cdada_str()` invalid-handle behavior with API docs (return `NULL`, not empty string)
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`
22+
- [B] str: fix uint32_t underflow in `cdada_str_rtraverse()` on empty strings
2223
- [O] tests: add coverage for `cdada_strerr()` valid, boundary and high invalid values
2324
- [O] tests: add `oom_create_test` coverage for create paths (`list`, `map`, `queue`, `set`, `stack`, `str`, `bbitmap`)
2425
- [O] tests: add coverage for `cdada_str_replace_all()` empty-match invalid input and self-overlap replacement

src/str.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ int cdada_str_rtraverse(const cdada_str_t* str, cdada_str_it func,
9393

9494
try{
9595
std::string::const_reverse_iterator it;
96+
if(s.empty())
97+
return CDADA_SUCCESS;
9698
uint32_t pos = s.length()-1;
9799
for(it = s.rbegin(); it != s.rend(); ++it){
98100
(*func)(str, *it, pos, opaque);

0 commit comments

Comments
 (0)