From 70ef9bc75c42ec00e9d4231a2e1f1dca84144748 Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Sun, 31 Oct 2021 21:45:32 -0700 Subject: [PATCH] Fix ensureTotalCapacity calls that should be ensureUnusedCapacity calls If these functions are called more than once, then the array list would no longer be guaranteed to have enough capacity during the appendAssumeCapacity calls. With ensureUnusedCapacity, they will always be guaranteed to have enough capacity regardless of how many times the function is called. --- src/codegen/spirv.zig | 2 +- src/link/MachO/Dylib.zig | 2 +- src/link/MachO/Object.zig | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig index da2fa66feed941364ca2efc0900c0e28cd84abf1..67faf32471d7bbf879ab789edde9d01ea2c1f22f 100644 --- a/src/codegen/spirv.zig +++ b/src/codegen/spirv.zig @@ -629,7 +629,7 @@ pub const DeclGen = struct { const params = decl.ty.fnParamLen(); var i: usize = 0; - try self.args.ensureTotalCapacity(params); + try self.args.ensureUnusedCapacity(params); while (i < params) : (i += 1) { const param_type_id = self.spv.types.get(decl.ty.fnParamType(i)).?; const arg_result_id = self.spv.allocResultId(); diff --git a/src/link/MachO/Dylib.zig b/src/link/MachO/Dylib.zig index e3998a8548e03344167e50ce8d713ac4fa0d61f7..5b4ab6aa180289099340d6f427a68407737d7241 100644 --- a/src/link/MachO/Dylib.zig +++ b/src/link/MachO/Dylib.zig @@ -180,7 +180,7 @@ pub fn parse(self: *Dylib, allocator: *Allocator, target: std.Target) !void { fn readLoadCommands(self: *Dylib, allocator: *Allocator, reader: anytype) !void { const should_lookup_reexports = self.header.?.flags & macho.MH_NO_REEXPORTED_DYLIBS == 0; - try self.load_commands.ensureTotalCapacity(allocator, self.header.?.ncmds); + try self.load_commands.ensureUnusedCapacity(allocator, self.header.?.ncmds); var i: u16 = 0; while (i < self.header.?.ncmds) : (i += 1) { diff --git a/src/link/MachO/Object.zig b/src/link/MachO/Object.zig index f0a299182c6e89c87ffe8b8825f3fa65b160130f..21a0686fef6a7a57fdf30737b3cd82e6398cd71e 100644 --- a/src/link/MachO/Object.zig +++ b/src/link/MachO/Object.zig @@ -267,7 +267,7 @@ pub fn readLoadCommands(self: *Object, allocator: *Allocator, reader: anytype) ! const header = self.header orelse unreachable; // Unreachable here signifies a fatal unexplored condition. const offset = self.file_offset orelse 0; - try self.load_commands.ensureTotalCapacity(allocator, header.ncmds); + try self.load_commands.ensureUnusedCapacity(allocator, header.ncmds); var i: u16 = 0; while (i < header.ncmds) : (i += 1) { -- 2.54.0