Skip to content

Commit

Permalink
[c] Optimise error handling for empty datatable rows
Browse files Browse the repository at this point in the history
  • Loading branch information
obligaron committed Jan 15, 2025
1 parent 2756157 commit e57d6e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
- [.NET] Improved parsing time
- [.NET] Use string-ordinal comparison consistently and remove old Mono workaround
- [.NET] Improved startup time
- [c] Optimise error handling for empty datatable rows

### Changed
- [cpp] add generic support for ABI versioning with VERSION ([#328](https://github.com/cucumber/gherkin/pull/328))
Expand Down
13 changes: 9 additions & 4 deletions c/src/gherkin_line.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,22 @@ wchar_t* GherkinLine_copy_line_text(const GherkinLine* line, int indent_to_remov

const Items* GherkinLine_table_cells(const GherkinLine* line) {
int item_count = calculate_cell_count(line->trimmed_line);
if (item_count == 0)
return (Items*)0;
Items* item_array = (Items*)malloc(sizeof(Items));
item_array->count = item_count;

if (item_count == 0) {
item_array->items = 0;
return item_array;
}

Span* items = (Span*)malloc(item_count * sizeof(Span));
int i;
for (i = 0; i < item_count; ++i) {
items[i].column = 0;
items[i].text = 0;
}
Items* item_array = (Items*)malloc(sizeof(Items));
item_array->count = item_count;
item_array->items = items;

const wchar_t* current_pos = line->trimmed_line;
for (i = 0; i < item_count; ++i) {
current_pos = populate_cell_data(&items[i], current_pos, current_pos - line->line_text);
Expand Down

0 comments on commit e57d6e0

Please sign in to comment.