mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
builtin: add 0 terminators for strings returned by .to_lower, .to_upper, utf32_to_str_no_malloc/2
This commit is contained in:
@ -266,6 +266,7 @@ pub fn (n int) hex1() string {
|
||||
len := if n >= 0 { n.str().len + 3 } else { 11 }
|
||||
hex := malloc(len) // 0x + \n
|
||||
count := C.sprintf((hex), '0x%x', n)
|
||||
hex[count] = 0
|
||||
return tos(hex, count)
|
||||
}
|
||||
*/
|
||||
@ -282,10 +283,7 @@ fn u64_to_hex(nn u64, len byte) string {
|
||||
buf[i] = x
|
||||
n = n >> 4
|
||||
}
|
||||
return string{
|
||||
str: unsafe { memdup(buf, len + 1) }
|
||||
len: len
|
||||
}
|
||||
return unsafe { tos(memdup(buf, len + 1), len) }
|
||||
}
|
||||
|
||||
// u64_to_hex_no_leading_zeros converts the number `nn` to hexadecimal `string`.
|
||||
@ -305,10 +303,7 @@ fn u64_to_hex_no_leading_zeros(nn u64, len byte) string {
|
||||
}
|
||||
}
|
||||
res_len := len - i
|
||||
return string{
|
||||
str: unsafe { memdup(&buf[i], res_len + 1) }
|
||||
len: res_len
|
||||
}
|
||||
return unsafe { tos(memdup(&buf[i], res_len + 1), res_len) }
|
||||
}
|
||||
|
||||
// hex returns the value of the `byte` as a hexadecimal `string`.
|
||||
|
Reference in New Issue
Block a user