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

This commit is contained in:
hryx 2019-06-28 17:40:20 -07:00
parent cc74bf5136
commit 102bf5200c
No known key found for this signature in database
GPG Key ID: 6A2784E15D7D95D6

View File

@ -687,17 +687,17 @@ fn transStringLiteral(
const kind = ZigClangStringLiteral_getKind(stmt);
switch (kind) {
.Ascii, .UTF8 => {
var clen: usize = undefined;
const cstr = ZigClangStringLiteral_getString_bytes_begin_size(stmt, &clen);
const zstr = try rp.c.str(cstr);
var len: usize = undefined;
const bytes_ptr = ZigClangStringLiteral_getString_bytes_begin_size(stmt, &len);
const str = bytes_ptr[0..len];
var len: usize = 0;
for (zstr) |c| len += escapeChar(c).len;
len = 0;
for (str) |c| len += escapeChar(c).len;
const buf = try rp.c.a().alloc(u8, len + "c\"\"".len);
buf[0] = 'c';
buf[1] = '"';
writeEscapedString(buf[2..], zstr);
writeEscapedString(buf[2..], str);
buf[buf.len - 1] = '"';
const token = try appendToken(rp.c, .StringLiteral, buf);