Skip to content

Commit

Permalink
cfg-source: fix off-by-one when extracting source line from CFGI_BUFFER
Browse files Browse the repository at this point in the history
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
  • Loading branch information
bazsi committed Jun 1, 2024
1 parent 7aa87cf commit d282374
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/cfg-source.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ _extract_source_from_buffer_location(GString *result, const gchar *buffer_conten
if (num_lines <= yylloc->first_line)
goto exit;

if (yylloc->first_column < 1)
goto exit;

for (gint lineno = yylloc->first_line; lineno <= yylloc->last_line; lineno++)
{
gchar *line = lines[lineno - 1];
Expand All @@ -242,9 +245,9 @@ _extract_source_from_buffer_location(GString *result, const gchar *buffer_conten
if (lineno == yylloc->first_line)
{
if (yylloc->first_line == yylloc->last_line)
g_string_append_len(result, &line[MIN(linelen, yylloc->first_column)], yylloc->last_column - yylloc->first_column);
g_string_append_len(result, &line[MIN(linelen, yylloc->first_column-1)], yylloc->last_column - yylloc->first_column);
else
g_string_append(result, &line[MIN(linelen, yylloc->first_column)]);
g_string_append(result, &line[MIN(linelen, yylloc->first_column-1)]);
}
else if (lineno < yylloc->last_line)
{
Expand Down

0 comments on commit d282374

Please sign in to comment.