Drop NUL terminator from diagnostic messages

main
copygirl 1 year ago
parent 1fb269d846
commit acb6b4b0a5
  1. 8
      src/diagnostics.zig

@ -48,8 +48,10 @@ pub const Diagnostics = struct {
if (diag) |d| {
var msg = e.getMessage();
defer msg.deinit();
// If the message ends with NUL byte, don't include it.
const size = if (msg.data[msg.size - 1] == 0) msg.size - 1 else msg.size;
d.data = .{ .err = e.getExitStatus() };
d.message = try d.allocator.alloc(u8, msg.size);
d.message = try d.allocator.alloc(u8, size);
@memcpy(@constCast(d.message.?), msg.data);
if (d.debug_print) std.debug.print("{s}\n", .{d.message.?});
}
@ -71,8 +73,10 @@ pub const Diagnostics = struct {
if (diag) |d| {
var msg = t.getMessage();
defer msg.deinit();
// If the message ends with NUL byte, don't include it.
const size = if (msg.data[msg.size - 1] == 0) msg.size - 1 else msg.size;
d.data = .{ .trap = code };
d.message = try d.allocator.alloc(u8, msg.size);
d.message = try d.allocator.alloc(u8, size);
@memcpy(@constCast(d.message.?), msg.data);
if (d.debug_print) std.debug.print("{s}\n", .{d.message.?});
}

Loading…
Cancel
Save