mirror of
https://github.com/fairyglade/ly.git
synced 2026-11-05 09:41:43 +00:00
fix: prevent underflow when session list is empty (#1060)
## What are the changes about? Fixes an integer underflow in `min_session_index`, which was computed by subtracting 1 from the session list length without checking for zero. Caused a panic (Debug/ReleaseSafe) or wraparound (ReleaseFast) on installs with no available sessions. ## What existing issue(s) does this resolve? N/A ## Pre-requisites - [x] I have tested & confirmed the changes work locally - [x] I have read and fully adhere to the rules set in the contributing guidelines found in `CONTRIBUTING.md` Co-authored-by: Matheus C. <245040149+matheusc457@users.noreply.github.com> Reviewed-on: https://codeberg.org/fairyglade/ly/pulls/1060 Reviewed-by: AnErrupTion <anerruption+codeberg@disroot.org>
This commit is contained in:
1 parent
f802d3bcb5
commit
55de3bc26c
2 files changed
+3
-1
No files matched your search
@@ -140,6 +140,7 @@ pub fn CyclableLabel(comptime ItemType: type, comptime ChangeItemType: type) typ
|
||||
fn goLeft(ptr: *anyopaque) !bool {
|
||||
var self: *Self = @ptrCast(@alignCast(ptr));
|
||||
|
||||
if (self.list.items.len == 0) return false;
|
||||
self.current = if (self.current == 0) self.list.items.len - 1 else self.current - 1;
|
||||
|
||||
if (self.change_item_fn) |change_item_fn| {
|
||||
@@ -156,6 +157,7 @@ pub fn CyclableLabel(comptime ItemType: type, comptime ChangeItemType: type) typ
|
||||
fn goRight(ptr: *anyopaque) !bool {
|
||||
var self: *Self = @ptrCast(@alignCast(ptr));
|
||||
|
||||
if (self.list.items.len == 0) return false;
|
||||
self.current = if (self.current == self.list.items.len - 1) 0 else self.current + 1;
|
||||
|
||||
if (self.change_item_fn) |change_item_fn| {
|
||||
|
||||
+1
-1
@@ -1148,7 +1148,7 @@ pub fn main(init: std.process.Init) !void {
|
||||
// Skip if autologin is active to prevent overriding autologin session
|
||||
var default_input = state.config.default_input;
|
||||
|
||||
const min_session_index = state.session.label.list.items.len - 1;
|
||||
const min_session_index = if (state.session.label.list.items.len == 0) 0 else state.session.label.list.items.len - 1;
|
||||
|
||||
if (state.config.save_file_dir != null and !state.is_autologin) {
|
||||
if (state.login_text) |box| {
|
||||
|
||||
Reference in new issue
Block a user