authorgravatar for codroid@gmail.comhryx <codroid@gmail.com> 2019-06-28 17:40:20-07:00
committergravatar for codroid@gmail.comhryx <codroid@gmail.com> 2019-06-28 17:40:20-07:00
log102bf5200cfd82c1df6d503059e70c37b4925361
tree0a05bfcb5dae073ea17cfee283a4123daedc1039
parentcc74bf51366c71ba997eb3015f2b687a3a18fd57
signaturelock-open Commit is signed but in an unrecognized format.

Fix string literal: not null-terminated (thanks @mikdusan)


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

src-self-hosted/translate_c.zig+6-6
...@@ -687,17 +687,17 @@ fn transStringLiteral(...@@ -687,17 +687,17 @@ fn transStringLiteral(
687 const kind = ZigClangStringLiteral_getKind(stmt);687 const kind = ZigClangStringLiteral_getKind(stmt);
688 switch (kind) {688 switch (kind) {
689 .Ascii, .UTF8 => {689 .Ascii, .UTF8 => {
690 var clen: usize = undefined;690 var len: usize = undefined;
691 const cstr = ZigClangStringLiteral_getString_bytes_begin_size(stmt, &clen);691 const bytes_ptr = ZigClangStringLiteral_getString_bytes_begin_size(stmt, &len);
692 const zstr = try rp.c.str(cstr);692 const str = bytes_ptr[0..len];
693693
694 var len: usize = 0;694 len = 0;
695 for (zstr) |c| len += escapeChar(c).len;695 for (str) |c| len += escapeChar(c).len;
696696
697 const buf = try rp.c.a().alloc(u8, len + "c\"\"".len);697 const buf = try rp.c.a().alloc(u8, len + "c\"\"".len);
698 buf[0] = 'c';698 buf[0] = 'c';
699 buf[1] = '"';699 buf[1] = '"';
700 writeEscapedString(buf[2..], zstr);700 writeEscapedString(buf[2..], str);
701 buf[buf.len - 1] = '"';701 buf[buf.len - 1] = '"';
702702
703 const token = try appendToken(rp.c, .StringLiteral, buf);703 const token = try appendToken(rp.c, .StringLiteral, buf);