authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-30 01:49:19 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-30 01:49:19 -07:00
log00e899bec815bc2b49c6e5a72a7cfeeda673e133
tree58eb0c7f8822eb707712af553af0cfb05435fb44
parentb1ebd056b9afaaa719cb55359c610455ffe04499
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

make returned string values nul-terminated


1 files changed, 8 insertions(+), 8 deletions(-)

yaml.zig+8-8
...@@ -37,7 +37,7 @@ pub const Item = union(enum) {...@@ -37,7 +37,7 @@ pub const Item = union(enum) {
37 kv: Key,37 kv: Key,
38 mapping: Mapping,38 mapping: Mapping,
39 sequence: Sequence,39 sequence: Sequence,
40 string: string,40 string: [:0]const u8,
41 stream: Stream,41 stream: Stream,
4242
43 pub fn deinit(self: *const Item, alloc: std.mem.Allocator) void {43 pub fn deinit(self: *const Item, alloc: std.mem.Allocator) void {
...@@ -97,7 +97,7 @@ pub const Key = struct {...@@ -97,7 +97,7 @@ pub const Key = struct {
97};97};
9898
99pub const Value = union(enum) {99pub const Value = union(enum) {
100 string: string,100 string: [:0]const u8,
101 mapping: Mapping,101 mapping: Mapping,
102 sequence: Sequence,102 sequence: Sequence,
103103
...@@ -367,7 +367,7 @@ fn parse_sequence(p: *Parser) Error!Sequence {...@@ -367,7 +367,7 @@ fn parse_sequence(p: *Parser) Error!Sequence {
367 }367 }
368}368}
369369
370fn get_event_string(event: Token, p: *const Parser) !string {370fn get_event_string(event: Token, p: *const Parser) ![:0]u8 {
371 const sm = event.start_mark;371 const sm = event.start_mark;
372 const em = event.end_mark;372 const em = event.end_mark;
373 const lines = p.lines;373 const lines = p.lines;
...@@ -383,16 +383,16 @@ fn get_event_string(event: Token, p: *const Parser) !string {...@@ -383,16 +383,16 @@ fn get_event_string(event: Token, p: *const Parser) !string {
383 try list.appendSlice(std.mem.trimLeft(u8, lines[i], " "));383 try list.appendSlice(std.mem.trimLeft(u8, lines[i], " "));
384 try list.append('\n');384 try list.append('\n');
385 }385 }
386 return try list.toOwnedSlice();386 return try list.toOwnedSliceSentinel(0);
387 },387 },
388 else => @panic("TODO"),388 else => @panic("TODO"),
389 }389 }
390 }390 }
391 const s = lines[sm.line][sm.column..em.column];391 const s = lines[sm.line][sm.column..em.column];
392 if (s.len < 2) return try p.alloc.dupe(u8, s);392 if (s.len < 2) return try p.alloc.dupeZ(u8, s);
393 if (s[0] == '"' and s[s.len - 1] == '"') return try p.alloc.dupe(u8, std.mem.trim(u8, s, "\""));393 if (s[0] == '"' and s[s.len - 1] == '"') return try p.alloc.dupeZ(u8, std.mem.trim(u8, s, "\""));
394 if (s[0] == '\'' and s[s.len - 1] == '\'') return try p.alloc.dupe(u8, std.mem.trim(u8, s, "'"));394 if (s[0] == '\'' and s[s.len - 1] == '\'') return try p.alloc.dupeZ(u8, std.mem.trim(u8, s, "'"));
395 return try p.alloc.dupe(u8, s);395 return try p.alloc.dupeZ(u8, s);
396}396}
397397
398//398//