From aea23e8a408b74eda930f3dd0c4a2cbeeba0b29e Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 19 Jun 2021 07:48:46 +0300 Subject: [PATCH] strconv: fix fxx_to_str_l_parse/fxx_to_str_l_parse_no_dot returning s without cloning --- vlib/builtin/array_test.v | 2 -- vlib/builtin/string_int_test.v | 4 ++-- vlib/strconv/utilities.v | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/vlib/builtin/array_test.v b/vlib/builtin/array_test.v index 1f9983dfbd..9b723b3c37 100644 --- a/vlib/builtin/array_test.v +++ b/vlib/builtin/array_test.v @@ -1092,8 +1092,6 @@ fn test_array_int_pop() { assert z == 4 x1 := a.pop() x2 := a.pop() - dump(x1) - dump(x2) final := a.pop() assert final == 1 } diff --git a/vlib/builtin/string_int_test.v b/vlib/builtin/string_int_test.v index 80b3a340d1..a17563d2b7 100644 --- a/vlib/builtin/string_int_test.v +++ b/vlib/builtin/string_int_test.v @@ -186,7 +186,7 @@ fn test_signed_cast() { } // test g format - { + unsafe { mut u := strconv.Float64u{ u: strconv.double_plus_zero } @@ -202,7 +202,7 @@ fn test_signed_cast() { assert '${u.f:g}' == '-inf' assert '${u.f:G}' == '-INF' } - { + unsafe { mut u := strconv.Float32u{ u: strconv.single_plus_zero } diff --git a/vlib/strconv/utilities.v b/vlib/strconv/utilities.v index ef9a692dfb..dc1c1a621f 100644 --- a/vlib/strconv/utilities.v +++ b/vlib/strconv/utilities.v @@ -272,7 +272,7 @@ pub fn f64_to_str_l_no_dot(f f64) string { pub fn fxx_to_str_l_parse(s string) string { // check for +inf -inf Nan if s.len > 2 && (s[0] == `n` || s[1] == `i`) { - return s + return s.clone() } m_sgn_flag := false @@ -395,7 +395,7 @@ pub fn fxx_to_str_l_parse(s string) string { pub fn fxx_to_str_l_parse_no_dot(s string) string { // check for +inf -inf Nan if s.len > 2 && (s[0] == `n` || s[1] == `i`) { - return s + return s.clone() } m_sgn_flag := false