1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

strconv: fix memory corruption (#10250)

This commit is contained in:
Uwe Krüger 2021-05-29 15:24:09 +02:00 committed by GitHub
parent 7287ecd6c7
commit 0ff2d9ef78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -445,7 +445,7 @@ pub fn remove_tail_zeros(s string) string {
mut i_s := 0
// skip spaces
for i_s < s.len && s[i_s] !in [`-`,`+`] && s[i_s] >= `9` && s[i_s] <= `0`{
for i_s < s.len && s[i_s] !in [`-`,`+`] && (s[i_s] > `9` || s[i_s] < `0`) {
buf[i_d] = s[i_s]
i_s++
i_d++
@ -482,16 +482,19 @@ pub fn remove_tail_zeros(s string) string {
i_s = i_s1
}
if s[i_s] != `.` {
if i_s < s.len && s[i_s] != `.` {
// check exponent
for i_s < s.len {
for {
buf[i_d] = s[i_s]
i_s++
i_d++
if i_s >= s.len {
break
}
}
}
buf[i_d] = 0
return tos(buf, i_d+1)
return tos(buf, i_d)
}
}