mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
catch alloc error on wstring_to_utf8 convert
This commit is contained in:
@@ -63,13 +63,21 @@ enumerate_interfaces :: proc(allocator := context.allocator) -> (interfaces: []N
|
|||||||
}
|
}
|
||||||
|
|
||||||
_interfaces := make([dynamic]Network_Interface, 0, allocator)
|
_interfaces := make([dynamic]Network_Interface, 0, allocator)
|
||||||
|
|
||||||
for adapter := (^sys.IP_Adapter_Addresses)(raw_data(buf)); adapter != nil; adapter = adapter.Next {
|
for adapter := (^sys.IP_Adapter_Addresses)(raw_data(buf)); adapter != nil; adapter = adapter.Next {
|
||||||
|
friendly_name, err1 := sys.wstring_to_utf8(sys.wstring(adapter.FriendlyName), 256, allocator)
|
||||||
|
if err1 != nil { return {}, Platform_Error(err1) }
|
||||||
|
|
||||||
|
description, err2 := sys.wstring_to_utf8(sys.wstring(adapter.Description), 256, allocator)
|
||||||
|
if err2 != nil { return {}, Platform_Error(err2) }
|
||||||
|
|
||||||
|
dns_suffix, err3 := sys.wstring_to_utf8(sys.wstring(adapter.DnsSuffix), 256, allocator)
|
||||||
|
if err3 != nil { return {}, Platform_Error(err3) }
|
||||||
|
|
||||||
interface := Network_Interface{
|
interface := Network_Interface{
|
||||||
adapter_name = strings.clone(string(adapter.AdapterName)),
|
adapter_name = strings.clone(string(adapter.AdapterName)),
|
||||||
friendly_name = wstring_to_string(adapter.FriendlyName),
|
friendly_name = friendly_name,
|
||||||
description = wstring_to_string(adapter.Description),
|
description = description,
|
||||||
dns_suffix = wstring_to_string(adapter.DnsSuffix),
|
dns_suffix = dns_suffix,
|
||||||
|
|
||||||
mtu = adapter.MTU,
|
mtu = adapter.MTU,
|
||||||
|
|
||||||
@@ -139,14 +147,6 @@ enumerate_interfaces :: proc(allocator := context.allocator) -> (interfaces: []N
|
|||||||
return _interfaces[:], {}
|
return _interfaces[:], {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Takes a UTF-16 Wstring and clones it.
|
|
||||||
*/
|
|
||||||
wstring_to_string :: proc(s: ^u16, max_size := 256, allocator := context.allocator) -> (res: string) {
|
|
||||||
temp := sys.wstring_to_utf8((sys.Wstring)(s), max_size, context.temp_allocator)
|
|
||||||
return strings.clone(temp[:len(temp)], allocator)
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Interpret SOCKET_ADDRESS as an Address
|
Interpret SOCKET_ADDRESS as an Address
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user