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

builtin : fix buffer overflow and i64 issue with hex()

This commit is contained in:
lemoncmd 2019-07-02 17:13:18 +09:00 committed by Alexander Medvednikov
parent b57d227aa0
commit b9586a4017

View File

@ -123,17 +123,25 @@ pub fn (b bool) str() string {
} }
pub fn (n int) hex() string { pub fn (n int) hex() string {
s := n.str() len := if n >= 0 {
hex := malloc(s.len + 3) // 0x + \n n.str().len + 3
} else {
11
}
hex := malloc(len) // 0x + \n
count := int(C.sprintf(hex, '0x%x', n)) count := int(C.sprintf(hex, '0x%x', n))
return tos(hex, count) return tos(hex, count)
} }
pub fn (n i64) hex() string { pub fn (n i64) hex() string {
s := n.str() len := if n >= i64(0) {
hex := malloc(s.len + 3) n.str().len + 3
C.sprintf(hex, '0x%x', n) } else {
return tos(hex, s.len + 3) 19
}
hex := malloc(len)
count := int(C.sprintf(hex, '0x%x', n))
return tos(hex, count)
} }
pub fn (a []byte) contains(val byte) bool { pub fn (a []byte) contains(val byte) bool {