From 75280bb54ced1a1f01d91a29827637096a6262a9 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Mon, 9 Dec 2019 16:41:07 +0300 Subject: [PATCH] fix int.str() memory bug --- vlib/builtin/int.v | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vlib/builtin/int.v b/vlib/builtin/int.v index 30a3aa50cc..c01b543e11 100644 --- a/vlib/builtin/int.v +++ b/vlib/builtin/int.v @@ -19,7 +19,7 @@ pub fn (nn int) str() string { return '0' } max := 16 - mut buf := calloc(max) + mut buf := calloc(max+1) mut len := 0 mut is_neg := false if n < 0 { @@ -38,6 +38,7 @@ pub fn (nn int) str() string { buf[max - len - 1] = `-` len++ } + buf[max] = `\0` return tos(buf + max - len, len) }