1
0
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:
Delyan Angelov
2021-03-14 18:21:45 +02:00
parent b6d089b605
commit d65ad68e77
4 changed files with 17 additions and 14 deletions

View File

@ -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`.