Skip to content

Commit

Permalink
chore: remove unsafe malloc in hostname (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
mengzhuo authored Sep 26, 2024
1 parent b28511e commit 1e499bf
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions src/hostname/set_hostname_nix.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,7 @@ fn set_hostname(hostname string) int {
if hostname.len > 256 {
return -1
}

hostname_arr := unsafe { malloc(hostname.len) + 1 }

unsafe {
for i in 0 .. hostname.len {
hostname_arr[i] = hostname[i]
}
hostname_arr[hostname.len] = 0
}
return C.sethostname(hostname_arr, hostname.len)
return C.sethostname(&char(hostname.str), hostname.len)
}

// Fancy wrapper for error codes if set_hostname returns -1
Expand Down

0 comments on commit 1e499bf

Please sign in to comment.