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 {...@@ -629,7 +629,7 @@ pub const DeclGen = struct {
629 const params = decl.ty.fnParamLen();629 const params = decl.ty.fnParamLen();
630 var i: usize = 0;630 var i: usize = 0;
631631
632 try self.args.ensureTotalCapacity(params);632 try self.args.ensureUnusedCapacity(params);
633 while (i < params) : (i += 1) {633 while (i < params) : (i += 1) {
634 const param_type_id = self.spv.types.get(decl.ty.fnParamType(i)).?;634 const param_type_id = self.spv.types.get(decl.ty.fnParamType(i)).?;
635 const arg_result_id = self.spv.allocResultId();635 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 {...@@ -180,7 +180,7 @@ pub fn parse(self: *Dylib, allocator: *Allocator, target: std.Target) !void {
180fn readLoadCommands(self: *Dylib, allocator: *Allocator, reader: anytype) !void {180fn readLoadCommands(self: *Dylib, allocator: *Allocator, reader: anytype) !void {
181 const should_lookup_reexports = self.header.?.flags & macho.MH_NO_REEXPORTED_DYLIBS == 0;181 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
185 var i: u16 = 0;185 var i: u16 = 0;
186 while (i < self.header.?.ncmds) : (i += 1) {186 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) !...@@ -267,7 +267,7 @@ pub fn readLoadCommands(self: *Object, allocator: *Allocator, reader: anytype) !
267 const header = self.header orelse unreachable; // Unreachable here signifies a fatal unexplored condition.267 const header = self.header orelse unreachable; // Unreachable here signifies a fatal unexplored condition.
268 const offset = self.file_offset orelse 0;268 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
272 var i: u16 = 0;272 var i: u16 = 0;
273 while (i < header.ncmds) : (i += 1) {273 while (i < header.ncmds) : (i += 1) {