1
Fork 0
This commit is contained in:
Motiejus Jakštys 2022-02-20 09:47:47 +02:00 committed by Motiejus Jakštys
parent 9487194c95
commit e54c153dd8
2 changed files with 6 additions and 9 deletions

View File

@ -61,7 +61,7 @@ pub const ShellWriter = struct {
};
var fullOffset: u12 = 0;
var idx: u6 = 0;
while (idx < shells.len) {
while (idx < shells.len) : (idx += 1) {
const len = @intCast(u6, shells.get(idx).len);
try self.blob.appendSlice(shells.get(idx));
const ourShell = self.blob.constSlice()[fullOffset .. fullOffset + len];
@ -77,7 +77,6 @@ pub const ShellWriter = struct {
//const stderr = std.io.getStdErr().writer();
//stderr.print("\n", .{}) catch unreachable;
try self.blob.appendNTimes(0, padding);
idx += 1;
}
return self;
}
@ -155,10 +154,9 @@ pub const ShellWriter = struct {
var topShells = try BoundedArray([]const u8, MaxShells).init(total);
var i: u32 = 0;
while (i < total) {
while (i < total) : (i += 1) {
const elem = deque.removeMax().shell;
topShells.set(i, elem);
i += 1;
}
const result = ShellSections.init(self.allocator, topShells);

View File

@ -17,7 +17,7 @@ pub const PackedUser = packed struct {
name_len: u5,
gecos_len: u8,
};
const PackedUserAlignment = 3; // bits
const PackedUserAlignmentBits = 3;
pub const User = struct {
uid: u32,
@ -35,6 +35,7 @@ pub const UserWriter = struct {
// function makes tests easier, and removes the Shell dependency of this
// module.
const shellIndexFnType = fn ([]const u8) ?u6;
appendTo: *ArrayList(u8),
shellIndexFn: shellIndexFnType,
@ -45,9 +46,7 @@ pub const UserWriter = struct {
};
}
const fromUserErr = error{InvalidRecord};
pub fn downCast(comptime T: type, n: u64) fromUserErr!T {
pub fn downCast(comptime T: type, n: u64) error{InvalidRecord}!T {
return std.math.cast(T, n) catch |err| switch (err) {
error.Overflow => {
return error.InvalidRecord;
@ -85,7 +84,7 @@ pub const UserWriter = struct {
try self.appendTo.appendNTimes(0, pad.roundUpPadding(
u64,
PackedUserAlignment,
PackedUserAlignmentBits,
self.appendTo.items.len,
));
}