authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2021-10-31 21:45:32-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-01 15:08:41-04:00
log70ef9bc75c42ec00e9d4231a2e1f1dca84144748
treee172783da32798ca11c3b28c43cbcffb05fbf9d5
parent77eefebe65fc2baed08755bceb8e4df77fe8103c

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.

3 files changed, 3 insertions(+), 3 deletions(-)

src/codegen/spirv.zig+1-1
......@@ -629,7 +629,7 @@ pub const DeclGen = struct {
629629 const params = decl.ty.fnParamLen();
630630 var i: usize = 0;
631631
632 try self.args.ensureTotalCapacity(params);
632 try self.args.ensureUnusedCapacity(params);
633633 while (i < params) : (i += 1) {
634634 const param_type_id = self.spv.types.get(decl.ty.fnParamType(i)).?;
635635 const arg_result_id = self.spv.allocResultId();
src/link/MachO/Dylib.zig+1-1
......@@ -180,7 +180,7 @@ pub fn parse(self: *Dylib, allocator: *Allocator, target: std.Target) !void {
180180fn readLoadCommands(self: *Dylib, allocator: *Allocator, reader: anytype) !void {
181181 const should_lookup_reexports = self.header.?.flags & macho.MH_NO_REEXPORTED_DYLIBS == 0;
182182
183 try self.load_commands.ensureTotalCapacity(allocator, self.header.?.ncmds);
183 try self.load_commands.ensureUnusedCapacity(allocator, self.header.?.ncmds);
184184
185185 var i: u16 = 0;
186186 while (i < self.header.?.ncmds) : (i += 1) {
src/link/MachO/Object.zig+1-1
......@@ -267,7 +267,7 @@ pub fn readLoadCommands(self: *Object, allocator: *Allocator, reader: anytype) !
267267 const header = self.header orelse unreachable; // Unreachable here signifies a fatal unexplored condition.
268268 const offset = self.file_offset orelse 0;
269269
270 try self.load_commands.ensureTotalCapacity(allocator, header.ncmds);
270 try self.load_commands.ensureUnusedCapacity(allocator, header.ncmds);
271271
272272 var i: u16 = 0;
273273 while (i < header.ncmds) : (i += 1) {