builtin: remove unsafe{} blocks from data_to_hex_string/2

This commit is contained in:
Delyan Angelov 2024-10-16 12:35:06 +03:00
parent c5e8ad19df
commit a64dfc776b
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED

View file

@ -2868,20 +2868,16 @@ pub fn (s string) hex() string {
@[unsafe]
fn data_to_hex_string(data &u8, len int) string {
mut hex := unsafe { malloc_noscan(u64(len) * 2 + 1) }
mut hex := malloc_noscan(u64(len) * 2 + 1)
mut dst := 0
for c in 0 .. len {
b := data[c]
n0 := b >> 4
n1 := b & 0xF
unsafe {
hex[dst] = if n0 < 10 { n0 + `0` } else { n0 + `W` }
hex[dst + 1] = if n1 < 10 { n1 + `0` } else { n1 + `W` }
}
dst += 2
}
unsafe {
hex[dst] = 0
return tos(hex, dst)
}
}