From c99c4f56eee3a5ddaafb6d1219f38542d6a2e004 Mon Sep 17 00:00:00 2001
From: Georgy Moshkin <gmoshkin@picodata.io>
Date: Fri, 21 Oct 2022 09:49:08 +0300
Subject: [PATCH] fix: used to panic in picolib.raft_log

---
 src/main.rs | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/main.rs b/src/main.rs
index e5597e9436..b9160d9e61 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -260,7 +260,12 @@ fn picolib_setup(args: &args::Run) {
                 let total_width = 1 + header.len() + col_widths.iter().sum::<usize>();
                 let cols = util::screen_size().1 as usize;
                 if total_width > cols {
-                    cw -= total_width - cols;
+                    match cw.checked_sub(total_width - cols) {
+                        Some(new_cw) if new_cw > 0 => cw = new_cw,
+                        _ => {
+                            return Err(Error::other("screen too small"));
+                        }
+                    }
                 }
 
                 use std::io::Write;
-- 
GitLab