diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 5c3d740a32..5e8fb71cd4 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2020-03-11 Andrew Burgess + + * buildsyms.c (buildsym_compunit::record_line): Avoid accessing + previous item in the list, when the list has no items. + 2020-03-11 Tom de Vries * dwarf2/loc.c (dwarf2_evaluate_property): Handle NULL frame in diff --git a/gdb/buildsym.c b/gdb/buildsym.c index 24aeba8e25..7155db34b0 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -681,15 +681,18 @@ buildsym_compunit::record_line (struct subfile *subfile, int line, m_have_line_numbers = true; } - /* If we have a duplicate for the previous entry then ignore the new - entry, except, if the new entry is setting the is_stmt flag, then - ensure the previous entry respects the new setting. */ - e = subfile->line_vector->item + subfile->line_vector->nitems - 1; - if (e->line == line && e->pc == pc) + if (subfile->line_vector->nitems > 0) { - if (is_stmt && !e->is_stmt) - e->is_stmt = 1; - return; + /* If we have a duplicate for the previous entry then ignore the new + entry, except, if the new entry is setting the is_stmt flag, then + ensure the previous entry respects the new setting. */ + e = subfile->line_vector->item + subfile->line_vector->nitems - 1; + if (e->line == line && e->pc == pc) + { + if (is_stmt && !e->is_stmt) + e->is_stmt = 1; + return; + } } if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length)