Skip to content

Commit e65cb87

Browse files
msuneclaude
andcommitted
all: report size_used on incomplete dump()
Report bytes written on incomplete dump(). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d805222 commit e65cb87

11 files changed

Lines changed: 21 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Legend:
2525
- [B] str: fix uint32_t overflow in `cdada_str_erase()` bounds check
2626
- [B] str: fix `cdada_str_find_count()`/`cdada_str_find_all()` not returning `CDADA_E_NOT_FOUND`
2727
- [B] str: reject empty `substr` in `cdada_str_find_count()`/`cdada_str_find_all()`
28+
- [B] list/map/queue/set/stack: report `size_used` as bytes written on incomplete `dump()`
2829
- [O] tests: add coverage for `cdada_strerr()` valid, boundary and high invalid values
2930
- [O] tests: add `oom_create_test` coverage for create paths (`list`, `map`, `queue`, `set`, `stack`, `str`, `bbitmap`)
3031
- [O] tests: add coverage for `cdada_str_replace_all()` empty-match invalid input and self-overlap replacement

src/list.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,8 +1106,10 @@ int cdada_list_dump(cdada_list_t* list, uint32_t size, char* buffer,
11061106
return CDADA_SUCCESS;
11071107

11081108
snprintf(buffer, size, "%s", ss.str().c_str());
1109-
if(ss.str().length()+1 > size)
1109+
if(*size_used > size){
1110+
*size_used = size;
11101111
return CDADA_E_INCOMPLETE;
1112+
}
11111113
}catch(bad_alloc& e){
11121114
return CDADA_E_MEM;
11131115
}catch(...){

src/map.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,8 +901,10 @@ int cdada_map_dump(cdada_map_t* map, uint32_t size, char* buffer,
901901
return CDADA_SUCCESS;
902902

903903
snprintf(buffer, size, "%s", ss.str().c_str());
904-
if(ss.str().length()+1 > size)
904+
if(*size_used > size){
905+
*size_used = size;
905906
return CDADA_E_INCOMPLETE;
907+
}
906908
}catch(bad_alloc& e){
907909
return CDADA_E_MEM;
908910
}catch(...){

src/queue.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,10 @@ int cdada_queue_dump(cdada_queue_t* queue, uint32_t size, char* buffer,
557557
return CDADA_SUCCESS;
558558

559559
snprintf(buffer, size, "%s", ss.str().c_str());
560-
if(ss.str().length()+1 > size)
560+
if(*size_used > size){
561+
*size_used = size;
561562
return CDADA_E_INCOMPLETE;
563+
}
562564
}catch(bad_alloc& e){
563565
return CDADA_E_MEM;
564566
}catch(...){

src/set.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,10 @@ int cdada_set_dump(cdada_set_t* set, uint32_t size, char* buffer,
820820
return CDADA_SUCCESS;
821821

822822
snprintf(buffer, size, "%s", ss.str().c_str());
823-
if(ss.str().length()+1 > size)
823+
if(*size_used > size){
824+
*size_used = size;
824825
return CDADA_E_INCOMPLETE;
826+
}
825827
}catch(bad_alloc& e){
826828
return CDADA_E_MEM;
827829
}catch(...){

src/stack.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,10 @@ int cdada_stack_dump(cdada_stack_t* stack, uint32_t size, char* buffer,
495495
return CDADA_SUCCESS;
496496

497497
snprintf(buffer, size, "%s", ss.str().c_str());
498-
if(ss.str().length()+1 > size)
498+
if(*size_used > size){
499+
*size_used = size;
499500
return CDADA_E_INCOMPLETE;
501+
}
500502
}catch(bad_alloc& e){
501503
return CDADA_E_MEM;
502504
}catch(...){

test/list_test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ int test_u8_insert_removal(){
220220
char buffer2[8];
221221
rv = cdada_list_dump(list, 8, buffer2, &used);
222222
TEST_ASSERT(rv == CDADA_E_INCOMPLETE);
223+
TEST_ASSERT(used == 8);
223224
fprintf(stdout, "%s\n", buffer2);
224225

225226
rv = cdada_list_first(list, &key);

test/map_test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ int _test_u552_insert_removal_traverse(){
772772
char buffer2[8];
773773
rv = cdada_map_dump(map, 8, buffer2, &used);
774774
TEST_ASSERT(rv == CDADA_E_INCOMPLETE);
775+
TEST_ASSERT(used == 8);
775776
fprintf(stdout, "%s\n", buffer2);
776777

777778
rv = cdada_map_first(map, &key, &tmp);

test/queue_test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ int test_u8_push_pop(){
173173
char buffer2[8];
174174
rv = cdada_queue_dump(queue, 8, buffer2, &used);
175175
TEST_ASSERT(rv == CDADA_E_INCOMPLETE);
176+
TEST_ASSERT(used == 8);
176177
fprintf(stdout, "%s\n", buffer2);
177178

178179
TEST_ASSERT(cdada_queue_size(queue) == 6);

test/set_test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ int test_u8_insert_removal(){
109109
char buffer2[8];
110110
rv = cdada_set_dump(set, 8, buffer2, &used);
111111
TEST_ASSERT(rv == CDADA_E_INCOMPLETE);
112+
TEST_ASSERT(used == 8);
112113
fprintf(stdout, "%s\n", buffer2);
113114

114115
rv = cdada_set_first(set, &key);

0 commit comments

Comments
 (0)