strconv: fix memory corruption (#10250)

pull/10261/head
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
1 changed files with 7 additions and 4 deletions

View File

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