set length before copy (#10498)

This commit is contained in:
Dylan Conway
2024-04-24 23:39:05 -07:00
committed by GitHub
parent e792bbdf5f
commit a6714904e4

View File

@@ -2672,8 +2672,9 @@ pub fn escapeHTMLForLatin1Input(allocator: std.mem.Allocator, latin1: []const u8
buf = try std.ArrayList(u8).initCapacity(allocator, latin1.len + @as(usize, Scalar.lengths[c]));
const copy_len = @intFromPtr(ptr) - @intFromPtr(latin1.ptr);
@memcpy(buf.items[0..copy_len], latin1[0..copy_len]);
if (comptime Environment.allow_assert) assert(copy_len <= buf.capacity);
buf.items.len = copy_len;
@memcpy(buf.items[0..copy_len], latin1[0..copy_len]);
any_needs_escape = true;
break :scan_and_allocate_lazily;
},