From 3faa0164abc75949d62bb0c5f409bb11502e877f Mon Sep 17 00:00:00 2001 From: YoVinchen Date: Tue, 20 Jan 2026 20:23:12 +0800 Subject: [PATCH] fix(log): prevent usize underflow in KeepSome rotation strategy KeepSome(n) internally computes n-2, so n=1 causes underflow. Use KeepSome(2) as the minimum safe value. --- src-tauri/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 205120a56..06ee64564 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -292,8 +292,10 @@ pub fn run() { file_name: Some("cc-switch".into()), }), ]) - // 单文件模式:启动时删除旧文件,达到大小时轮转并保留 1 个 - .rotation_strategy(RotationStrategy::KeepSome(1)) + // 单文件模式:启动时删除旧文件,达到大小时轮转 + // 注意:KeepSome(n) 内部会做 n-2 运算,n=1 会导致 usize 下溢 + // KeepSome(2) 是最小安全值,表示不保留轮转文件 + .rotation_strategy(RotationStrategy::KeepSome(2)) // 单文件大小限制 1GB .max_file_size(1024 * 1024 * 1024) .timezone_strategy(TimezoneStrategy::UseLocal)