Skip to content

Commit 70ef9bc

Browse files
squeek502andrewrk
authored andcommitted
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.
1 parent 77eefeb commit 70ef9bc

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/codegen/spirv.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub fn parse(self: *Dylib, allocator: *Allocator, target: std.Target) !void {
180180
fn 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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) {

0 commit comments

Comments
 (0)