cgen: fix null termination bug gen tests to fail

pull/4027/head
Joe Conigliaro 2020-03-15 11:39:29 +11:00
parent 28fc9d332c
commit cfeafb9ab4
1 changed files with 4 additions and 3 deletions

View File

@ -1159,13 +1159,14 @@ fn (g mut Gen) const_decl(node ast.ConstDecl) {
g.write('//') g.write('//')
pos := g.out.len pos := g.out.len
g.expr(expr) g.expr(expr)
g.writeln('') mut b := g.out.buf[pos..g.out.buf.len].clone()
b := g.out.buf[pos..g.out.buf.len].clone() b << `\0`
val := string(b) val := string(b)
// val += '\0' // val += '\0'
// g.out.go_back(val.len) // g.out.go_back(val.len)
// println('pos=$pos buf.len=$g.out.buf.len len=$g.out.len val.len=$val.len val="$val"\n') // println('pos=$pos buf.len=$g.out.buf.len len=$g.out.len val.len=$val.len val="$val"\n')
g.definitions.write(val) g.writeln('')
g.definitions.writeln(val)
} }
else { else {
styp := g.typ(field.typ) styp := g.typ(field.typ)