zig objcopy: Fix corrupted hex output

Do not return stack local data for hex record payload data.
This commit is contained in:
Eckhart Köppen 2023-01-11 15:36:54 +02:00 committed by Veikka Tuominen
parent 0e66df2094
commit c2d37224c8

View File

@ -432,7 +432,7 @@ const HexWriter = struct {
}
}
fn getPayloadBytes(self: Record) []const u8 {
fn getPayloadBytes(self: *const Record) []const u8 {
return switch (self.payload) {
.Data => |d| d,
.EOF => @as([]const u8, &.{}),
@ -518,6 +518,16 @@ fn padFile(f: File, opt_size: ?u64) !void {
try f.setEndPos(size);
}
test "HexWriter.Record.Address has correct payload and checksum" {
const record = HexWriter.Record.Address(0x0800_0000);
const payload = record.getPayloadBytes();
const sum = record.checksum();
try std.testing.expect(sum == 0xF2);
try std.testing.expect(payload.len == 2);
try std.testing.expect(payload[0] == 8);
try std.testing.expect(payload[1] == 0);
}
test "containsValidAddressRange" {
var segment = BinaryElfSegment{
.physicalAddress = 0,