fix: crash while rendering chunks longer than 4096 bytes (long lines)
Proof that I was a Zig noob not too long ago. The defer of course runs immediately.
This commit is contained in:
parent
e236f3f3c6
commit
2fafceab83
1 changed files with 8 additions and 7 deletions
|
@ -593,13 +593,14 @@ pub const Editor = struct {
|
||||||
const bufsize = 4095;
|
const bufsize = 4095;
|
||||||
var bufstatic: [bufsize:0]u8 = undefined;
|
var bufstatic: [bufsize:0]u8 = undefined;
|
||||||
const len = leaf.buf.len;
|
const len = leaf.buf.len;
|
||||||
var chunk: [:0]u8 = if (len > bufsize)
|
var chunk_alloc: ?[:0]u8 = null;
|
||||||
std.heap.c_allocator.allocSentinel(u8, len, 0) catch |e| return Buffer.Walker{ .err = e }
|
var chunk: [:0]u8 = if (len > bufsize) ret: {
|
||||||
else
|
const ptr = self_.a.allocSentinel(u8, len, 0) catch |e| return Buffer.Walker{ .err = e };
|
||||||
&bufstatic;
|
chunk_alloc = ptr;
|
||||||
if (len > bufsize) {
|
break :ret ptr;
|
||||||
defer std.heap.c_allocator.free(chunk);
|
} else &bufstatic;
|
||||||
}
|
defer if (chunk_alloc) |p| self_.a.free(p);
|
||||||
|
|
||||||
@memcpy(chunk[0..leaf.buf.len], leaf.buf);
|
@memcpy(chunk[0..leaf.buf.len], leaf.buf);
|
||||||
chunk[leaf.buf.len] = 0;
|
chunk[leaf.buf.len] = 0;
|
||||||
chunk.len = leaf.buf.len;
|
chunk.len = leaf.buf.len;
|
||||||
|
|
Loading…
Add table
Reference in a new issue