File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -225,8 +225,9 @@ impl CardView for CommandsCard {
225225
226226 fn desired_height ( & self , max_height : u16 , _width : u16 ) -> u16 {
227227 // Base height for list items + search bar + some padding
228- let command_count = self . commands . len ( ) as u16 ;
229- let content_height = command_count + 2 ; // +2 for search bar and padding
228+ // Use saturating conversion to prevent overflow when count > u16::MAX
229+ let command_count = u16:: try_from ( self . commands . len ( ) ) . unwrap_or ( u16:: MAX ) ;
230+ let content_height = command_count. saturating_add ( 2 ) ; // +2 for search bar and padding
230231
231232 // Clamp between min 5 and max 14, respecting max_height
232233 content_height. clamp ( 5 , 14 ) . min ( max_height)
Original file line number Diff line number Diff line change @@ -147,8 +147,9 @@ impl CardView for ModelsCard {
147147
148148 fn desired_height ( & self , max_height : u16 , _width : u16 ) -> u16 {
149149 // Base height for list items + search bar + some padding
150- let model_count = self . models . len ( ) as u16 ;
151- let content_height = model_count + 2 ; // +2 for search bar and padding
150+ // Use saturating conversion to prevent overflow when count > u16::MAX
151+ let model_count = u16:: try_from ( self . models . len ( ) ) . unwrap_or ( u16:: MAX ) ;
152+ let content_height = model_count. saturating_add ( 2 ) ; // +2 for search bar and padding
152153
153154 // Clamp between min 5 and max 12, respecting max_height
154155 content_height. clamp ( 5 , 12 ) . min ( max_height)
Original file line number Diff line number Diff line change @@ -207,7 +207,9 @@ impl CardView for SessionsCard {
207207
208208 fn desired_height ( & self , max_height : u16 , _width : u16 ) -> u16 {
209209 // Base height: sessions + header + search bar + padding
210- let content_height = self . sessions . len ( ) as u16 + 3 ;
210+ // Use saturating conversion to prevent overflow when count > u16::MAX
211+ let session_count = u16:: try_from ( self . sessions . len ( ) ) . unwrap_or ( u16:: MAX ) ;
212+ let content_height = session_count. saturating_add ( 3 ) ;
211213 let min_height = 5 ;
212214 let max_desired = 15 ;
213215 content_height
You can’t perform that action at this time.
0 commit comments