summaryrefslogtreecommitdiff
path: root/src/Mini.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Mini.zig')
-rw-r--r--src/Mini.zig6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/Mini.zig b/src/Mini.zig
index ac9a8e85..a6aef15a 100644
--- a/src/Mini.zig
+++ b/src/Mini.zig
@@ -49,6 +49,7 @@ const Row = struct {
const end = modal.nextGrapheme(row.text, row.at);
const grapheme = row.text[row.at..end];
row.left = File.graphemeDisplayWidth(grapheme);
+ // unreachable below: `generate` refuses a source that is no UTF-8
const n = std.unicode.utf8ByteSequenceLength(grapheme[0]) catch unreachable;
const cp = std.unicode.utf8Decode(grapheme[0..n]) catch unreachable;
const blank = switch (cp) {
@@ -108,6 +109,7 @@ fn render(output: ?Result, source: []const u8, styles: []const u8) !usize {
if (output) |out| {
@memset(out.content[offset..][0..spaces], ' ');
@memset(out.colors[offset..][0..spaces], 0);
+ // unreachable: U+2800 plus a u8 mask is a braille codepoint, always three bytes
_ = std.unicode.utf8Encode(@as(u21, 0x2800) + mask, out.content[offset + spaces ..][0..3]) catch unreachable;
@memset(out.colors[offset + spaces ..][0..3], color);
}
@@ -313,3 +315,7 @@ test "Mini publishes only complete snapshots and content replacement drops metad
const path = try std.fmt.bufPrint(&path_buf, "{s}/mini.txt", .{dir});
try std.testing.checkAllAllocationFailures(std.testing.allocator, Case.run, .{path});
}
+
+test "Mini refuses a file that is no UTF-8, before its decoding could panic" {
+ try std.testing.expectError(error.InvalidUtf8, generate(std.testing.allocator, "ok \xff\xfe bad\n\xc3", ""));
+}