Ticket #4572: mc-4572-listbox_c-fix-division-by-zero-warning.patch

File mc-4572-listbox_c-fix-division-by-zero-warning.patch, 1017 bytes (added by and, 10 hours ago)
  • lib/widget/listbox.c

    From d42cd4eb3f16fb8d76ab6d32329f33df0e039f9e Mon Sep 17 00:00:00 2001
    From: Andreas Mohr <and@gmx.li>
    Date: Thu, 19 Dec 2024 16:00:00 +0000
    Subject: [PATCH] (listbox.c) fix division by zero warning
    
    Make Static Analyzer happy.
    
    lib/widget/listbox.c:119:51: warning: Division by zero [clang-analyzer-core.DivideZero]
      119 |         line = 1 + ((l->current * (w->lines - 2)) / length);
    
    Found by Clang-19 Static Analyzer
    
    Signed-off-by: Andreas Mohr <and@gmx.li>
    ---
     lib/widget/listbox.c | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/lib/widget/listbox.c b/lib/widget/listbox.c
    index 9234812bb..ef82baf43 100644
    a b listbox_drawscroll (const WListbox *l) 
    115115        tty_print_char ('v'); 
    116116 
    117117    /* Now draw the nice relative pointer */ 
    118     if (!g_queue_is_empty (l->list)) 
     118    if (!g_queue_is_empty (l->list) && length > 0) 
    119119        line = 1 + ((l->current * (w->lines - 2)) / length); 
    120120 
    121121    for (i = 1; i < max_line; i++)