From 886c5795d46f6b1bc9b399308136d539f2e09e4d Mon Sep 17 00:00:00 2001 From: llama <100429699+iamllama@users.noreply.github.com> Date: Tue, 25 Mar 2025 01:24:11 +0800 Subject: [PATCH] Fix panic when clearing today limits on the day collection was made (#3877) * fix panic on clearing today limits on the day collection was made * avoid possible overflow * clear future today limits --- rslib/src/deckconfig/update.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/rslib/src/deckconfig/update.rs b/rslib/src/deckconfig/update.rs index af4bb7572..956786995 100644 --- a/rslib/src/deckconfig/update.rs +++ b/rslib/src/deckconfig/update.rs @@ -411,10 +411,16 @@ fn update_deck_limits(deck: &mut NormalDeck, limits: &Limits, today: u32) { fn update_day_limit(day_limit: &mut Option, new_limit: Option, today: u32) { if let Some(limit) = new_limit { day_limit.replace(DayLimit { limit, today }); - } else if let Some(limit) = day_limit { - // instead of setting to None, only make sure today is in the past, - // thus preserving last used value - limit.today = limit.today.min(today - 1); + } else { + // if the collection was created today, the + // "preserve last value" hack below won't work + // clear "future" limits as well (from imports) + day_limit.take_if(|limit| limit.today == 0 || limit.today > today); + if let Some(limit) = day_limit { + // instead of setting to None, only make sure today is in the past, + // thus preserving last used value + limit.today = limit.today.min(today.saturating_sub(1)); + } } }