diff --git a/gdb/dwarf2/line-header.c b/gdb/dwarf2/line-header.c index 9597f0930e3..3d2563eeb39 100644 --- a/gdb/dwarf2/line-header.c +++ b/gdb/dwarf2/line-header.c @@ -351,13 +351,20 @@ dwarf_decode_line_header (sect_offset sect_off, bool is_dwz, line_ptr += 1; lh->opcode_base = read_1_byte (abfd, line_ptr); line_ptr += 1; - lh->standard_opcode_lengths.reset (new unsigned char[lh->opcode_base]); - - lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ - for (i = 1; i < lh->opcode_base; ++i) + if (lh->opcode_base > 0) { - lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); - line_ptr += 1; + lh->standard_opcode_lengths.reset (new unsigned char[lh->opcode_base]); + + /* The first element should never be used, because there's no standard + opcode encoded as 0. Give it some defined value. */ + lh->standard_opcode_lengths[0] = 1; + + /* Read the standard_opcode_lengths array. */ + for (i = 1; i < lh->opcode_base; ++i) + { + lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); + line_ptr += 1; + } } if (lh->version >= 5)