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

strconv: fix atoi returning 0 on large strings (#10635)

This commit is contained in:
Flinner
2021-07-02 10:39:57 +03:00
committed by GitHub
parent abbf71c794
commit 1486258591
6 changed files with 62 additions and 52 deletions

View File

@@ -465,22 +465,22 @@ pub fn (s string) bool() bool {
// int returns the value of the string as an integer `'1'.int() == 1`.
pub fn (s string) int() int {
return int(strconv.common_parse_int(s, 0, 32, false, false))
return int(strconv.common_parse_int(s, 0, 32, false, false) or { 0 })
}
// i64 returns the value of the string as i64 `'1'.i64() == i64(1)`.
pub fn (s string) i64() i64 {
return strconv.common_parse_int(s, 0, 64, false, false)
return strconv.common_parse_int(s, 0, 64, false, false) or { 0 }
}
// i8 returns the value of the string as i8 `'1'.i8() == i8(1)`.
pub fn (s string) i8() i8 {
return i8(strconv.common_parse_int(s, 0, 8, false, false))
return i8(strconv.common_parse_int(s, 0, 8, false, false) or { 0 })
}
// i16 returns the value of the string as i16 `'1'.i16() == i16(1)`.
pub fn (s string) i16() i16 {
return i16(strconv.common_parse_int(s, 0, 16, false, false))
return i16(strconv.common_parse_int(s, 0, 16, false, false) or { 0 })
}
// f32 returns the value of the string as f32 `'1.0'.f32() == f32(1)`.
@@ -497,17 +497,17 @@ pub fn (s string) f64() f64 {
// u16 returns the value of the string as u16 `'1'.u16() == u16(1)`.
pub fn (s string) u16() u16 {
return u16(strconv.common_parse_uint(s, 0, 16, false, false))
return u16(strconv.common_parse_uint(s, 0, 16, false, false) or { 0 })
}
// u32 returns the value of the string as u32 `'1'.u32() == u32(1)`.
pub fn (s string) u32() u32 {
return u32(strconv.common_parse_uint(s, 0, 32, false, false))
return u32(strconv.common_parse_uint(s, 0, 32, false, false) or { 0 })
}
// u64 returns the value of the string as u64 `'1'.u64() == u64(1)`.
pub fn (s string) u64() u64 {
return strconv.common_parse_uint(s, 0, 64, false, false)
return strconv.common_parse_uint(s, 0, 64, false, false) or { 0 }
}
[direct_array_access]