fix int.str() memory bug

pull/3024/head
Alexander Medvednikov 2019-12-09 16:41:07 +03:00
parent f68d9d1a16
commit 75280bb54c
1 changed files with 2 additions and 1 deletions

View File

@ -19,7 +19,7 @@ pub fn (nn int) str() string {
return '0' return '0'
} }
max := 16 max := 16
mut buf := calloc(max) mut buf := calloc(max+1)
mut len := 0 mut len := 0
mut is_neg := false mut is_neg := false
if n < 0 { if n < 0 {
@ -38,6 +38,7 @@ pub fn (nn int) str() string {
buf[max - len - 1] = `-` buf[max - len - 1] = `-`
len++ len++
} }
buf[max] = `\0`
return tos(buf + max - len, len) return tos(buf + max - len, len)
} }