Skip to content

Commit 4254001

Browse files
committed
str: handle NULL input in create()
* Check for NULL in cdada_str_create() * Add regression and CHANGELOG Reported-by: CodexGPT-5.3 <noreply@openai.com>
1 parent b0ac36a commit 4254001

3 files changed

Lines changed: 8 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ Legend:
1515
- [B] utils: add missing human-readable message for `CDADA_E_FULL`
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
18+
- [B] str: return `NULL` in `cdada_str_create()` when input C string is `NULL`
1819
- [O] tests: add coverage for `cdada_strerr()` valid, boundary and high invalid values
1920
- [O] tests: add `oom_create_test` coverage for create paths (`list`, `map`, `queue`, `set`, `stack`, `str`, `bbitmap`)
2021
- [O] tests: add coverage for `cdada_str_replace_all()` empty-match invalid input and self-overlap replacement
22+
- [O] tests: add `cdada_str_create(NULL)` regression coverage
2123

2224
### v0.6.3 (28th January 2026)
2325

src/str.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ cdada_str_t* cdada_str_create(const char* str){
1212

1313
__cdada_str_int_t* m = NULL;
1414

15+
if(!str)
16+
return NULL;
17+
1518
m = (__cdada_str_int_t*)malloc(sizeof(__cdada_str_int_t));
1619
if(!m)
1720
return NULL;

test/str_test.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ int test_basics(){
114114
void* ptr_not_null = (void*)0x123;
115115

116116
//Create
117+
s = cdada_str_create(NULL);
118+
TEST_ASSERT(s == NULL);
119+
117120
s = cdada_str_create("HELLO");
118121
TEST_ASSERT(s != NULL);
119122

0 commit comments

Comments
 (0)