selectionString: realloc so free gets the correct length

This commit is contained in:
Mitchell Hashimoto
2022-08-06 15:50:25 -07:00
parent 9d26ab2dc8
commit 109e2a67ab

View File

@ -469,7 +469,10 @@ pub fn selectionString(self: Screen, alloc: Allocator, sel: Selection) ![:0]cons
// Add null termination
buf[i] = 0;
return buf[0..i :0];
// Realloc so our free length is exactly correct
const result = try alloc.realloc(buf, i + 1);
return result[0..i :0];
}
/// Returns the slices that make up the selection, in order. There are at most