Skip to content

Commit 2ebb88e

Browse files
committed
utils: fix str(CDADA_E_FULL) overflow
Fix bug and make sure there is coverage for CDADA_E_COUNT in test/utils.c. Reported-by: CodexGPT-5.3 <noreply@openai.com>
1 parent b3ed1f7 commit 2ebb88e

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Legend:
99
- [O] Other
1010
```
1111

12+
### v0.6.4 ()
13+
14+
- [B] utils: fix `cdada_strerr()` bounds handling for invalid and negative error codes
15+
- [B] utils: add missing human-readable message for `CDADA_E_FULL`
16+
- [O] tests: add coverage for `cdada_strerr()` valid, boundary and high invalid values
17+
1218
### v0.6.3 (28th January 2026)
1319

1420
- [O] tests/CI: fixed compilation with GCC 16 (thanks A. Stieger). Added CI coverage for GCC 15.

src/utils.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ static const char* cdada_err_str[CDADA_E_COUNT] = {
1010
"Out of memory",
1111
"Feature unsupported",
1212
"Empty",
13-
"Incomplete"
13+
"Incomplete",
14+
"Full"
1415
};
1516

1617
const char* cdada_strerr(int err){
17-
return err >= CDADA_E_COUNT? "Invalid code" : cdada_err_str[err];
18+
return (err < 0 || err >= CDADA_E_COUNT)? "Invalid code" : cdada_err_str[err];
1819
}
1920

2021
const char* cdada_get_ver(){

test/combined_test.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ int main(int args, char** argv){
4747
rv = cdada_stack_destroy(stack);
4848
TEST_ASSERT(rv == CDADA_SUCCESS);
4949

50+
TEST_ASSERT(strcmp(cdada_strerr(CDADA_SUCCESS), "Success") == 0);
51+
TEST_ASSERT(strcmp(cdada_strerr(CDADA_E_FULL), "Full") == 0);
52+
TEST_ASSERT(strcmp(cdada_strerr(-1), "Invalid code") == 0);
53+
TEST_ASSERT(strcmp(cdada_strerr(CDADA_E_COUNT), "Invalid code") == 0);
54+
TEST_ASSERT(strcmp(cdada_strerr(CDADA_E_COUNT + 1000), "Invalid code") == 0);
55+
5056
//Add your test here, and return a code appropriately...
5157
return rv == 0? EXIT_SUCCESS : EXIT_FAILURE;
5258
}

0 commit comments

Comments
 (0)