| ... | @@ -568,7 +568,8 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void { | ... | @@ -568,7 +568,8 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void { |
| 568 | // Finalize missing address values | 568 | // Finalize missing address values |
| 569 | rec.rangeStart += text_sect.addr - seg.vmaddr; | 569 | rec.rangeStart += text_sect.addr - seg.vmaddr; |
| 570 | if (rec.personalityFunction > 0) { | 570 | if (rec.personalityFunction > 0) { |
| 571 | rec.personalityFunction = personalities[rec.personalityFunction - 1]; | 571 | const index = math.cast(usize, rec.personalityFunction - 1) orelse return error.Overflow; |
| | 572 | rec.personalityFunction = personalities[index]; |
| 572 | } | 573 | } |
| 573 | | 574 | |
| 574 | if (rec.compactUnwindEncoding > 0 and !UnwindEncoding.isDwarf(rec.compactUnwindEncoding, cpu_arch)) { | 575 | if (rec.compactUnwindEncoding > 0 and !UnwindEncoding.isDwarf(rec.compactUnwindEncoding, cpu_arch)) { |
| ... | @@ -653,13 +654,15 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void { | ... | @@ -653,13 +654,15 @@ pub fn write(info: *UnwindInfo, zld: *Zld) !void { |
| 653 | try page.write(info, writer); | 654 | try page.write(info, writer); |
| 654 | const nwritten = cwriter.bytes_written - start; | 655 | const nwritten = cwriter.bytes_written - start; |
| 655 | if (nwritten < second_level_page_bytes) { | 656 | if (nwritten < second_level_page_bytes) { |
| 656 | try writer.writeByteNTimes(0, second_level_page_bytes - nwritten); | 657 | const offset = math.cast(usize, second_level_page_bytes - nwritten) orelse return error.Overflow; |
| | 658 | try writer.writeByteNTimes(0, offset); |
| 657 | } | 659 | } |
| 658 | } | 660 | } |
| 659 | | 661 | |
| 660 | const padding = buffer.items.len - cwriter.bytes_written; | 662 | const padding = buffer.items.len - cwriter.bytes_written; |
| 661 | if (padding > 0) { | 663 | if (padding > 0) { |
| 662 | mem.set(u8, buffer.items[cwriter.bytes_written..], 0); | 664 | const offset = math.cast(usize, cwriter.bytes_written) orelse return error.Overflow; |
| | 665 | mem.set(u8, buffer.items[offset..], 0); |
| 663 | } | 666 | } |
| 664 | | 667 | |
| 665 | try zld.file.pwriteAll(buffer.items, sect.offset); | 668 | try zld.file.pwriteAll(buffer.items, sect.offset); |