Skip to content

Commit 102bf52

Browse files
committed
Fix string literal: not null-terminated (thanks @mikdusan)
1 parent cc74bf5 commit 102bf52

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src-self-hosted/translate_c.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -687,17 +687,17 @@ fn transStringLiteral(
687687
const kind = ZigClangStringLiteral_getKind(stmt);
688688
switch (kind) {
689689
.Ascii, .UTF8 => {
690-
var clen: usize = undefined;
691-
const cstr = ZigClangStringLiteral_getString_bytes_begin_size(stmt, &clen);
692-
const zstr = try rp.c.str(cstr);
690+
var len: usize = undefined;
691+
const bytes_ptr = ZigClangStringLiteral_getString_bytes_begin_size(stmt, &len);
692+
const str = bytes_ptr[0..len];
693693

694-
var len: usize = 0;
695-
for (zstr) |c| len += escapeChar(c).len;
694+
len = 0;
695+
for (str) |c| len += escapeChar(c).len;
696696

697697
const buf = try rp.c.a().alloc(u8, len + "c\"\"".len);
698698
buf[0] = 'c';
699699
buf[1] = '"';
700-
writeEscapedString(buf[2..], zstr);
700+
writeEscapedString(buf[2..], str);
701701
buf[buf.len - 1] = '"';
702702

703703
const token = try appendToken(rp.c, .StringLiteral, buf);

0 commit comments

Comments
 (0)