Fix index-of-out-bounds when no versions are found in the sdk lib dir

The current code wrongly assumes that versions[0] will always exist after the iterateAndFilterByVersion call.
This commit is contained in:
Ryan Liptak 2024-06-07 00:24:29 -07:00 committed by Andrew Kelley
parent 45b62c4529
commit 65cad8ab13

View File

@ -476,6 +476,7 @@ pub const Installation = struct {
var iterator = sdk_lib_dir.iterate();
const versions = try iterateAndFilterByVersion(&iterator, allocator, prefix);
if (versions.len == 0) return error.InstallationNotFound;
defer {
for (versions[1..]) |version| allocator.free(version);
allocator.free(versions);