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

pull/926/head
lemoncmd 2019-07-02 17:13:18 +09:00 committed by Alexander Medvednikov
parent b57d227aa0
commit b9586a4017
1 changed files with 14 additions and 6 deletions

View File

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