aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-06-27 05:30:16 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-06-27 05:30:16 -0700
commite93bdc79c727c543e08078fa7373b2bfb734f989 (patch)
tree9c2d8da9ff11f074c1cbbf38947790d144746be5
parent3059d0fbb32fe9e8bed470d4fd3436a95b1dbd29 (diff)
downloadbun-e93bdc79c727c543e08078fa7373b2bfb734f989.tar.gz
bun-e93bdc79c727c543e08078fa7373b2bfb734f989.tar.zst
bun-e93bdc79c727c543e08078fa7373b2bfb734f989.zip
Use less undefined
-rw-r--r--src/string_immutable.zig10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig
index 1dcaea9fa..d2691a804 100644
--- a/src/string_immutable.zig
+++ b/src/string_immutable.zig
@@ -1472,7 +1472,11 @@ pub fn escapeHTMLForLatin1Input(allocator: std.mem.Allocator, latin1: []const u8
};
var any_needs_escape = false;
- var buf: std.ArrayList(u8) = undefined;
+ var buf: std.ArrayList(u8) = std.ArrayList(u8){
+ .items = &.{},
+ .capacity = 0,
+ .allocator = allocator,
+ };
if (comptime Environment.isAarch64 or Environment.isX64) {
// pass #1: scan for any characters that need escaping
@@ -1488,6 +1492,8 @@ pub fn escapeHTMLForLatin1Input(allocator: std.mem.Allocator, latin1: []const u8
@bitCast(AsciiVectorU1, (vec == vecs[3])) |
@bitCast(AsciiVectorU1, (vec == vecs[4]))) == 1)
{
+ std.debug.assert(buf.capacity == 0);
+
buf = try std.ArrayList(u8).initCapacity(allocator, latin1.len + 6);
const copy_len = @ptrToInt(remaining.ptr) - @ptrToInt(latin1.ptr);
@memcpy(buf.items.ptr, latin1.ptr, copy_len);
@@ -1599,6 +1605,8 @@ pub fn escapeHTMLForLatin1Input(allocator: std.mem.Allocator, latin1: []const u8
scan_and_allocate_lazily: while (ptr != end) : (ptr += 1) {
switch (ptr[0]) {
'"', '&', '\'', '<', '>' => |c| {
+ std.debug.assert(buf.capacity == 0);
+
buf = try std.ArrayList(u8).initCapacity(allocator, latin1.len + @as(usize, Scalar.lengths[c]));
const copy_len = @ptrToInt(ptr) - @ptrToInt(latin1.ptr);
@memcpy(buf.items.ptr, latin1.ptr, copy_len - 1);