mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-20 21:35:19 +00:00
Calculate the size needed before allocating
This commit is contained in:
@@ -65,7 +65,19 @@ _environ :: proc(allocator: runtime.Allocator) -> []string {
|
||||
}
|
||||
defer win32.FreeEnvironmentStringsW(envs)
|
||||
|
||||
r := make([dynamic]string, 0, 50, allocator)
|
||||
n := 0
|
||||
for from, i, p := 0, 0, envs; true; i += 1 {
|
||||
c := ([^]u16)(p)[i]
|
||||
if c == 0 {
|
||||
if i <= from {
|
||||
break
|
||||
}
|
||||
n += 1
|
||||
from = i + 1
|
||||
}
|
||||
}
|
||||
|
||||
r := make([dynamic]string, 0, n, allocator)
|
||||
for from, i, p := 0, 0, envs; true; i += 1 {
|
||||
c := ([^]u16)(p)[i]
|
||||
if c == 0 {
|
||||
|
||||
Reference in New Issue
Block a user