mirror of https://github.com/fairyglade/ly.git
positionSingleWidget: Resist integer overflows
Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
parent
84950136c9
commit
7c2ae2738c
75
src/main.zig
75
src/main.zig
|
|
@ -1950,8 +1950,9 @@ fn positionSingleWidget(state: *UiState, item: []const u8, current_x: *usize, cu
|
||||||
state.shutdown_label.positionXY(Position.init(current_x.*, current_y));
|
state.shutdown_label.positionXY(Position.init(current_x.*, current_y));
|
||||||
current_x.* += width + 1;
|
current_x.* += width + 1;
|
||||||
} else {
|
} else {
|
||||||
state.shutdown_label.positionXY(Position.init(current_x.* - width, current_y));
|
const dwidth = if (width > current_x.*) 0 else current_x.* - width;
|
||||||
current_x.* -= width + 1;
|
state.shutdown_label.positionXY(Position.init(dwidth, current_y));
|
||||||
|
if (width + 1 <= current_x.*) current_x.* -= width + 1;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (std.mem.eql(u8, item, "restart")) {
|
} else if (std.mem.eql(u8, item, "restart")) {
|
||||||
|
|
@ -1961,8 +1962,9 @@ fn positionSingleWidget(state: *UiState, item: []const u8, current_x: *usize, cu
|
||||||
state.restart_label.positionXY(Position.init(current_x.*, current_y));
|
state.restart_label.positionXY(Position.init(current_x.*, current_y));
|
||||||
current_x.* += width + 1;
|
current_x.* += width + 1;
|
||||||
} else {
|
} else {
|
||||||
state.restart_label.positionXY(Position.init(current_x.* - width, current_y));
|
const dwidth = if (width > current_x.*) 0 else current_x.* - width;
|
||||||
current_x.* -= width + 1;
|
state.restart_label.positionXY(Position.init(dwidth, current_y));
|
||||||
|
if (width + 1 <= current_x.*) current_x.* -= width + 1;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (std.mem.eql(u8, item, "britup")) {
|
} else if (std.mem.eql(u8, item, "britup")) {
|
||||||
|
|
@ -1972,8 +1974,9 @@ fn positionSingleWidget(state: *UiState, item: []const u8, current_x: *usize, cu
|
||||||
state.brightness_up_label.positionXY(Position.init(current_x.*, current_y));
|
state.brightness_up_label.positionXY(Position.init(current_x.*, current_y));
|
||||||
current_x.* += width + 1;
|
current_x.* += width + 1;
|
||||||
} else {
|
} else {
|
||||||
state.brightness_up_label.positionXY(Position.init(current_x.* - width, current_y));
|
const dwidth = if (width > current_x.*) 0 else current_x.* - width;
|
||||||
current_x.* -= width + 1;
|
state.brightness_up_label.positionXY(Position.init(dwidth, current_y));
|
||||||
|
if (width + 1 <= current_x.*) current_x.* -= width + 1;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (std.mem.eql(u8, item, "britdown")) {
|
} else if (std.mem.eql(u8, item, "britdown")) {
|
||||||
|
|
@ -1983,8 +1986,9 @@ fn positionSingleWidget(state: *UiState, item: []const u8, current_x: *usize, cu
|
||||||
state.brightness_down_label.positionXY(Position.init(current_x.*, current_y));
|
state.brightness_down_label.positionXY(Position.init(current_x.*, current_y));
|
||||||
current_x.* += width + 1;
|
current_x.* += width + 1;
|
||||||
} else {
|
} else {
|
||||||
state.brightness_down_label.positionXY(Position.init(current_x.* - width, current_y));
|
const dwidth = if (width > current_x.*) 0 else current_x.* - width;
|
||||||
current_x.* -= width + 1;
|
state.brightness_down_label.positionXY(Position.init(dwidth, current_y));
|
||||||
|
if (width + 1 <= current_x.*) current_x.* -= width + 1;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (std.mem.eql(u8, item, "password")) {
|
} else if (std.mem.eql(u8, item, "password")) {
|
||||||
|
|
@ -1994,8 +1998,9 @@ fn positionSingleWidget(state: *UiState, item: []const u8, current_x: *usize, cu
|
||||||
state.toggle_password_label.positionXY(Position.init(current_x.*, current_y));
|
state.toggle_password_label.positionXY(Position.init(current_x.*, current_y));
|
||||||
current_x.* += width + 1;
|
current_x.* += width + 1;
|
||||||
} else {
|
} else {
|
||||||
state.toggle_password_label.positionXY(Position.init(current_x.* - width, current_y));
|
const dwidth = if (width > current_x.*) 0 else current_x.* - width;
|
||||||
current_x.* -= width + 1;
|
state.toggle_password_label.positionXY(Position.init(dwidth, current_y));
|
||||||
|
if (width + 1 <= current_x.*) current_x.* -= width + 1;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (std.mem.eql(u8, item, "clock") or std.mem.eql(u8, item, "time")) {
|
} else if (std.mem.eql(u8, item, "clock") or std.mem.eql(u8, item, "time")) {
|
||||||
|
|
@ -2005,8 +2010,9 @@ fn positionSingleWidget(state: *UiState, item: []const u8, current_x: *usize, cu
|
||||||
state.clock_label.positionXY(Position.init(current_x.*, current_y));
|
state.clock_label.positionXY(Position.init(current_x.*, current_y));
|
||||||
current_x.* += width + 1;
|
current_x.* += width + 1;
|
||||||
} else {
|
} else {
|
||||||
state.clock_label.positionXY(Position.init(current_x.* - width, current_y));
|
const dwidth = if (width > current_x.*) 0 else current_x.* - width;
|
||||||
current_x.* -= width + 1;
|
state.clock_label.positionXY(Position.init(dwidth, current_y));
|
||||||
|
if (width + 1 <= current_x.*) current_x.* -= width + 1;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (std.mem.eql(u8, item, "tty")) {
|
} else if (std.mem.eql(u8, item, "tty")) {
|
||||||
|
|
@ -2015,8 +2021,9 @@ fn positionSingleWidget(state: *UiState, item: []const u8, current_x: *usize, cu
|
||||||
state.tty_label.positionXY(Position.init(current_x.*, current_y));
|
state.tty_label.positionXY(Position.init(current_x.*, current_y));
|
||||||
current_x.* += width + 1;
|
current_x.* += width + 1;
|
||||||
} else {
|
} else {
|
||||||
state.tty_label.positionXY(Position.init(current_x.* - width, current_y));
|
const dwidth = if (width > current_x.*) 0 else current_x.* - width;
|
||||||
current_x.* -= width + 1;
|
state.tty_label.positionXY(Position.init(dwidth, current_y));
|
||||||
|
if (width + 1 <= current_x.*) current_x.* -= width + 1;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (std.mem.eql(u8, item, "battery")) {
|
} else if (std.mem.eql(u8, item, "battery")) {
|
||||||
|
|
@ -2026,8 +2033,9 @@ fn positionSingleWidget(state: *UiState, item: []const u8, current_x: *usize, cu
|
||||||
state.battery_label.positionXY(Position.init(current_x.*, current_y));
|
state.battery_label.positionXY(Position.init(current_x.*, current_y));
|
||||||
current_x.* += width + 1;
|
current_x.* += width + 1;
|
||||||
} else {
|
} else {
|
||||||
state.battery_label.positionXY(Position.init(current_x.* - width, current_y));
|
const dwidth = if (width > current_x.*) 0 else current_x.* - width;
|
||||||
current_x.* -= width + 1;
|
state.battery_label.positionXY(Position.init(dwidth, current_y));
|
||||||
|
if (width + 1 <= current_x.*) current_x.* -= width + 1;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (std.mem.eql(u8, item, "version")) {
|
} else if (std.mem.eql(u8, item, "version")) {
|
||||||
|
|
@ -2036,8 +2044,9 @@ fn positionSingleWidget(state: *UiState, item: []const u8, current_x: *usize, cu
|
||||||
state.version_label.positionXY(Position.init(current_x.*, current_y));
|
state.version_label.positionXY(Position.init(current_x.*, current_y));
|
||||||
current_x.* += width + 1;
|
current_x.* += width + 1;
|
||||||
} else {
|
} else {
|
||||||
state.version_label.positionXY(Position.init(current_x.* - width, current_y));
|
const dwidth = if (width > current_x.*) 0 else current_x.* - width;
|
||||||
current_x.* -= width + 1;
|
state.version_label.positionXY(Position.init(dwidth, current_y));
|
||||||
|
if (width + 1 <= current_x.*) current_x.* -= width + 1;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (std.mem.eql(u8, item, "numlock")) {
|
} else if (std.mem.eql(u8, item, "numlock")) {
|
||||||
|
|
@ -2046,8 +2055,9 @@ fn positionSingleWidget(state: *UiState, item: []const u8, current_x: *usize, cu
|
||||||
state.numlock_label.positionXY(Position.init(current_x.*, current_y));
|
state.numlock_label.positionXY(Position.init(current_x.*, current_y));
|
||||||
current_x.* += width + 1;
|
current_x.* += width + 1;
|
||||||
} else {
|
} else {
|
||||||
state.numlock_label.positionXY(Position.init(current_x.* - width, current_y));
|
const dwidth = if (width > current_x.*) 0 else current_x.* - width;
|
||||||
current_x.* -= width + 1;
|
state.numlock_label.positionXY(Position.init(dwidth, current_y));
|
||||||
|
if (width + 1 <= current_x.*) current_x.* -= width + 1;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (std.mem.eql(u8, item, "capslock")) {
|
} else if (std.mem.eql(u8, item, "capslock")) {
|
||||||
|
|
@ -2056,8 +2066,9 @@ fn positionSingleWidget(state: *UiState, item: []const u8, current_x: *usize, cu
|
||||||
state.capslock_label.positionXY(Position.init(current_x.*, current_y));
|
state.capslock_label.positionXY(Position.init(current_x.*, current_y));
|
||||||
current_x.* += width + 1;
|
current_x.* += width + 1;
|
||||||
} else {
|
} else {
|
||||||
state.capslock_label.positionXY(Position.init(current_x.* - width, current_y));
|
const dwidth = if (width > current_x.*) 0 else current_x.* - width;
|
||||||
current_x.* -= width + 1;
|
state.capslock_label.positionXY(Position.init(dwidth, current_y));
|
||||||
|
if (width + 1 <= current_x.*) current_x.* -= width + 1;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (std.mem.eql(u8, item, "labels")) {
|
} else if (std.mem.eql(u8, item, "labels")) {
|
||||||
|
|
@ -2068,8 +2079,9 @@ fn positionSingleWidget(state: *UiState, item: []const u8, current_x: *usize, cu
|
||||||
info.lbl.positionXY(Position.init(current_x.*, current_y));
|
info.lbl.positionXY(Position.init(current_x.*, current_y));
|
||||||
current_x.* += width + 1;
|
current_x.* += width + 1;
|
||||||
} else {
|
} else {
|
||||||
info.lbl.positionXY(Position.init(current_x.* - width, current_y));
|
const dwidth = if (width > current_x.*) 0 else current_x.* - width;
|
||||||
current_x.* -= width + 1;
|
info.lbl.positionXY(Position.init(dwidth, current_y));
|
||||||
|
if (width + 1 <= current_x.*) current_x.* -= width + 1;
|
||||||
}
|
}
|
||||||
positioned.labels[i] = true;
|
positioned.labels[i] = true;
|
||||||
}
|
}
|
||||||
|
|
@ -2094,8 +2106,9 @@ fn positionSingleWidget(state: *UiState, item: []const u8, current_x: *usize, cu
|
||||||
local_x = state.buffer.width - state.edge_margin.x;
|
local_x = state.buffer.width - state.edge_margin.x;
|
||||||
if (is_top) local_y += 1 else local_y -= 1;
|
if (is_top) local_y += 1 else local_y -= 1;
|
||||||
}
|
}
|
||||||
bind.lbl.positionXY(Position.init(local_x - width, local_y));
|
const dwidth = if (width > local_x) 0 else local_x - width;
|
||||||
local_x -= width + 1;
|
bind.lbl.positionXY(Position.init(dwidth, current_y));
|
||||||
|
if (width + 1 <= local_x) local_x -= width + 1;
|
||||||
}
|
}
|
||||||
positioned.binds[i] = true;
|
positioned.binds[i] = true;
|
||||||
}
|
}
|
||||||
|
|
@ -2111,8 +2124,9 @@ fn positionSingleWidget(state: *UiState, item: []const u8, current_x: *usize, cu
|
||||||
info.lbl.positionXY(Position.init(current_x.*, current_y));
|
info.lbl.positionXY(Position.init(current_x.*, current_y));
|
||||||
current_x.* += width + 1;
|
current_x.* += width + 1;
|
||||||
} else {
|
} else {
|
||||||
info.lbl.positionXY(Position.init(current_x.* - width, current_y));
|
const dwidth = if (width > current_x.*) 0 else current_x.* - width;
|
||||||
current_x.* -= width + 1;
|
info.lbl.positionXY(Position.init(dwidth, current_y));
|
||||||
|
if (width + 1 <= current_x.*) current_x.* -= width + 1;
|
||||||
}
|
}
|
||||||
positioned.labels[i] = true;
|
positioned.labels[i] = true;
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -2128,8 +2142,9 @@ fn positionSingleWidget(state: *UiState, item: []const u8, current_x: *usize, cu
|
||||||
bind.lbl.positionXY(Position.init(current_x.*, current_y));
|
bind.lbl.positionXY(Position.init(current_x.*, current_y));
|
||||||
current_x.* += width + 1;
|
current_x.* += width + 1;
|
||||||
} else {
|
} else {
|
||||||
bind.lbl.positionXY(Position.init(current_x.* - width, current_y));
|
const dwidth = if (width > current_x.*) 0 else current_x.* - width;
|
||||||
current_x.* -= width + 1;
|
bind.lbl.positionXY(Position.init(dwidth, current_y));
|
||||||
|
if (width + 1 <= current_x.*) current_x.* -= width + 1;
|
||||||
}
|
}
|
||||||
positioned.binds[i] = true;
|
positioned.binds[i] = true;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue