Skip to content

Commit 9401cf2

Browse files
committed
str: align invalid cdada_str() contract
- return NULL for invalid/corrupted str handles - update regression to assert cdada_str(NULL) == NULL - update changelog v0.6.4 entries Reported-by: CodexGPT-5.3 <noreply@openai.com>
1 parent 4254001 commit 9401cf2

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ Legend:
1616
- [B] list/map/queue/set/stack: return `NULL` when constructor `malloc()` fails (avoid null dereference)
1717
- [B] str: fix `cdada_str_replace*()` to reject empty match and self-replacement issues
1818
- [B] str: return `NULL` in `cdada_str_create()` when input C string is `NULL`
19+
- [B] str: align `cdada_str()` invalid-handle behavior with API docs (return `NULL`, not empty string)
1920
- [O] tests: add coverage for `cdada_strerr()` valid, boundary and high invalid values
2021
- [O] tests: add `oom_create_test` coverage for create paths (`list`, `map`, `queue`, `set`, `stack`, `str`, `bbitmap`)
2122
- [O] tests: add coverage for `cdada_str_replace_all()` empty-match invalid input and self-overlap replacement
2223
- [O] tests: add `cdada_str_create(NULL)` regression coverage
24+
- [O] tests: align invalid `cdada_str()` assertion with documented `NULL` return
2325

2426
### v0.6.3 (28th January 2026)
2527

src/str.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,15 @@ const char* cdada_str(const cdada_str_t* str){
143143
__cdada_str_int_t* m = (__cdada_str_int_t*)str;
144144

145145
if(!m || m->magic_num != CDADA_MAGIC)
146-
return "";
146+
return NULL;
147147

148148
try{
149149
return m->str->c_str();
150150
}catch(...){
151151
CDADA_ASSERT(0);
152152
}
153153

154-
return "";
154+
return NULL;
155155
}
156156

157157
int __cdada_str_find(const cdada_str_t* str, const char* substr, uint32_t* pos,

test/str_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ int test_basics(){
139139
TEST_ASSERT(cdada_str_length(NULL) == 0);
140140

141141
ptr = cdada_str(NULL);
142-
TEST_ASSERT(strlen(ptr) == 0);
142+
TEST_ASSERT(ptr == NULL);
143143

144144
rv = cdada_str_find_first(NULL, (const char*)ptr_not_null,
145145
(uint32_t*)ptr_not_null);

0 commit comments

Comments
 (0)