From 06cf86abeb3a062c6c3e21f4379c7fea9e6d71b6 Mon Sep 17 00:00:00 2001 From: just_some_entity Date: Tue, 27 Jan 2026 23:09:51 +0100 Subject: [PATCH] Fix BootServices.locateHandleLen() (#30877) Fixes https://codeberg.org/ziglang/zig/issues/30876 Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30877 Reviewed-by: linus Co-authored-by: just_some_entity Co-committed-by: just_some_entity --- lib/std/os/uefi/tables/boot_services.zig | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/std/os/uefi/tables/boot_services.zig b/lib/std/os/uefi/tables/boot_services.zig index f2a8b73b83..506961315d 100644 --- a/lib/std/os/uefi/tables/boot_services.zig +++ b/lib/std/os/uefi/tables/boot_services.zig @@ -235,9 +235,7 @@ pub const BootServices = extern struct { InvalidParameter, }; - pub const NumHandlesError = uefi.UnexpectedError || error{ - OutOfResources, - }; + pub const NumHandlesError = uefi.UnexpectedError; pub const LocateHandleError = uefi.UnexpectedError || error{ BufferTooSmall, @@ -702,8 +700,17 @@ pub const BootServices = extern struct { &len, null, )) { - .success => return @divExact(len, @sizeOf(Handle)), - .out_of_resources => return error.OutOfResources, + // If len is zero, it should return not_found, otherwise buffer_too_small. + // This is because it can/should only return success when a valid buffer is + // passed with a non zero size, which is not the case. + // Thus this status is considered unreachable and will return error.Unexpected + // .success => unreachable, + .buffer_too_small => return @divExact(len, @sizeOf(uefi.Handle)), + .not_found => return 0, + // This function accounts for all possible causes of this error code + // as per the most recent UEFI spec 2.10A, therefore this branch is + // considered unreachable and will return error.Unexpected instead + // .invalid_parameter => unreachable else => |status| return uefi.unexpectedStatus(status), } }