lorid

convert chordpro to pdf
git clone git://git.relim.de/lorid.git
Log | Files | Refs | README | LICENSE

commit 9328d2599cff8eb4a1dc7e0967fd60c003a96a31
parent f35b1b0b49feff931973da9ae2c81e98573bb3cb
Author: nibo <nibo@relim.de>
Date:   Sat, 26 Jul 2025 19:17:24 +0200

Add more test files

Diffstat:
Msrc/chordpro.c | 28++++++++++++++++++----------
Atest/memory/020.cho | 16++++++++++++++++
Atest/memory/021.cho | 16++++++++++++++++
Atest/memory/022.cho | 17+++++++++++++++++
Atest/memory/023.cho | 16++++++++++++++++
Atest/memory/024.cho | 14++++++++++++++
Atest/memory/025.cho | 15+++++++++++++++
Atest/memory/026.cho | 14++++++++++++++
Atest/memory/027.cho | 16++++++++++++++++
Atest/memory/028.cho | 14++++++++++++++
Atest/memory/029.cho | 12++++++++++++
11 files changed, 168 insertions(+), 10 deletions(-)

diff --git a/src/chordpro.c b/src/chordpro.c @@ -4719,11 +4719,13 @@ cho_grid_token_parse(struct ChoContext *ctx, const char *token, bool *err) } else if (!strcmp(token, "|2>")) { return GRID_TOKEN_BAR_LINE_SYMBOL; - } else - if ((chord = cho_chord_parse(ctx, token)) && chord->is_canonical) { + } + chord = cho_chord_parse(ctx, token); + if (chord->is_canonical) { cho_chord_free(chord); return GRID_TOKEN_CHORD; } + cho_chord_free(chord); *err = true; return GRID_TOKEN_CHORD; // unused } @@ -4732,10 +4734,20 @@ static void cho_songs_close(struct ChoContext *ctx, struct ChoLine ***lines) { if (!(*lines)[ctx->li]->items[ctx->lii]->u.text->text && !(*lines)[ctx->li]->text_above) { - cho_line_item_free((*lines)[ctx->li]->items[ctx->lii]); - free((*lines)[ctx->li]->items); - free((*lines)[ctx->li]); - (*lines)[ctx->li] = NULL; + if (ctx->lii == 0) { + cho_line_item_free((*lines)[ctx->li]->items[ctx->lii]); + free((*lines)[ctx->li]->items); + free((*lines)[ctx->li]); + (*lines)[ctx->li] = NULL; + } else { + cho_line_item_free((*lines)[ctx->li]->items[ctx->lii]); + (*lines)[ctx->li]->items[ctx->lii] = NULL; + (*lines)[ctx->li]->text_above = erealloc((*lines)[ctx->li]->text_above, (ctx->lia+1) * sizeof(struct ChoLineItemAbove *)); + (*lines)[ctx->li]->text_above[ctx->lia] = NULL; + ctx->li++; + *lines = erealloc(*lines, (ctx->li+1) * sizeof(struct ChoLine *)); + (*lines)[ctx->li] = NULL; + } } else { (*lines)[ctx->li]->items[ctx->lii]->u.text->text = erealloc((*lines)[ctx->li]->items[ctx->lii]->u.text->text, (ctx->te+1) * sizeof(char)); (*lines)[ctx->li]->items[ctx->lii]->u.text->text[ctx->te] = 0; @@ -5931,10 +5943,6 @@ cho_songs_parse(const char *str, const char *chordpro_filepath, struct Config *c ctx.te--; break; } - if (ctx.ta > -1 && !ctx.tags[ctx.ta]->is_closed && strcmp(ctx.tags[ctx.ta]->name, "img")) { - cho_log(&ctx, LOG_ERR, "Tag has to be closed on same line."); - goto ERR; - } if ((*lines)[ctx.li]->items[ctx.lii]->is_text) { (*lines)[ctx.li]->items[ctx.lii]->u.text->text = erealloc((*lines)[ctx.li]->items[ctx.lii]->u.text->text, (ctx.te+1) * sizeof(char)); (*lines)[ctx.li]->items[ctx.lii]->u.text->text[ctx.te] = 0; diff --git a/test/memory/020.cho b/test/memory/020.cho @@ -0,0 +1,16 @@ +# cho_log(&ctx, LOG_ERR, "Invalid token '%s' in grid section.", grid_token); +{t: 20} + +{textfont: Open Sans} + +{sov: Verse 1} +Make [A]sure the parser has [E]something +That it saved in memory +Only this way we may trigger +A memory leak +{eov} + +# Now trigger the specific error +{start_of_grid} +This +{end_of_grid} diff --git a/test/memory/021.cho b/test/memory/021.cho @@ -0,0 +1,16 @@ +# cho_log( &ctx, LOG_ERR, "Grid cell no. %d has %d tokens but should have %d tokens.", ctx.grid.bar_line_symbol_in_line_count - 1, ctx.grid.tokens_per_cell, ctx.grid.expected_tokens_per_cell); +{t: 21} + +{textfont: Open Sans} + +{sov: Verse 1} +Make [A]sure the parser has [E]something +That it saved in memory +Only this way we may trigger +A memory leak +{eov} + +# Now trigger the specific error +{start_of_grid} +| G . D . | G . D . | A . | +{end_of_grid} diff --git a/test/memory/022.cho b/test/memory/022.cho @@ -0,0 +1,17 @@ +# cho_log(&ctx, LOG_ERR, "Invalid token '%s' in grid section.", grid_token); +{t: 22} + +{textfont: Open Sans} + +{sov: Verse 1} +Make [A]sure the parser has [E]something +That it saved in memory +Only this way we may trigger +A memory leak +{eov} + +# Now trigger the specific error +{start_of_grid} +T D +{end_of_grid} + diff --git a/test/memory/023.cho b/test/memory/023.cho @@ -0,0 +1,16 @@ +# cho_log( &ctx, LOG_ERR, "Grid cell no. %d has %d tokens but should have %d tokens.", ctx.grid.bar_line_symbol_in_line_count - 1, ctx.grid.tokens_per_cell, ctx.grid.expected_tokens_per_cell); +{t: 23} + +{textfont: Open Sans} + +{sov: Verse 1} +Make [A]sure the parser has [E]something +That it saved in memory +Only this way we may trigger +A memory leak +{eov} + +# Now trigger the specific error +{sog} +:|: G . | D . . | | +{eog} diff --git a/test/memory/024.cho b/test/memory/024.cho @@ -0,0 +1,14 @@ +# cho_log(&ctx, LOG_ERR, "'img' tag has to have at least the 'src' attribute."); +{t: 24} + +{textfont: Open Sans} + +{sov: Verse 1} +Make [A]sure the parser has [E]something +That it saved in memory +Only this way we may trigger +A memory leak +{eov} + +# Now trigger the specific error +<img> diff --git a/test/memory/025.cho b/test/memory/025.cho @@ -0,0 +1,15 @@ +# cho_log(&ctx, LOG_ERR, "Newline character inside a tag name is invalid."); +{t: 25} + +{textfont: Open Sans} + +{sov: Verse 1} +Make [A]sure the parser has [E]something +That it saved in memory +Only this way we may trigger +A memory leak +{eov} + +# Now trigger the specific error +<te +> diff --git a/test/memory/026.cho b/test/memory/026.cho @@ -0,0 +1,14 @@ +# cho_log(&ctx, LOG_ERR, "Start tag name is too long."); +{t: 26} + +{textfont: Open Sans} + +{sov: Verse 1} +Make [A]sure the parser has [E]something +That it saved in memory +Only this way we may trigger +A memory leak +{eov} + +# Now trigger the specific error +<thisistoolong diff --git a/test/memory/027.cho b/test/memory/027.cho @@ -0,0 +1,16 @@ +# cho_log(&ctx, LOG_ERR, "Newline character inside a tag name is invalid."); +{t: 27} + +{textfont: Open Sans} + +{sov: Verse 1} +Make [A]sure the parser has [E]something +That it saved in memory +Only this way we may trigger +A memory leak +{eov} + +# Now trigger the specific error +<span></span +> + diff --git a/test/memory/028.cho b/test/memory/028.cho @@ -0,0 +1,14 @@ +# cho_log(&ctx, LOG_ERR, "End tag name is too long."); +{t: 28} + +{textfont: Open Sans} + +{sov: Verse 1} +Make [A]sure the parser has [E]something +That it saved in memory +Only this way we may trigger +A memory leak +{eov} + +# Now trigger the specific error +<span></thisistoolong> diff --git a/test/memory/029.cho b/test/memory/029.cho @@ -0,0 +1,12 @@ +{t: 29} + +{textfont: Open Sans} + +{sov: Verse 1} +Make [A]sure the parser has [E]something +That it saved in memory +Only this way we may trigger +A memory leak +{eov} + +# Now trigger the specific error