Ticket #4572: mc-4572-editsearch_c-fix-uninitialized-value-and-null-pointer-dereference.patch

File mc-4572-editsearch_c-fix-uninitialized-value-and-null-pointer-dereference.patch, 1.6 KB (added by and, 10 hours ago)
  • src/editor/editsearch.c

    From 4cfbe22de224fd647bfd2595f9d1be3194893727 Mon Sep 17 00:00:00 2001
    From: Andreas Mohr <and@gmx.li>
    Date: Sat, 21 Dec 2024 17:00:00 +0000
    Subject: [PATCH] (editsearch.c) fix uninitialized value and null pointer dereference
    
    Make Static Analyzer happy.
    
    /tmp/portage/app-misc/mc-9999/work/mc-9999/src/editor/editsearch.c:124:38: warning: Array access (from variable 'search_text') results in a null pointer dereference [clang-analyzer-core.NullDereference]
      124 |     if (dialog_result == B_CANCEL || search_text[0] == '\0')
          |                                      ^
    
    src/editor/editsearch.c:126:9: warning: 1st function call argument is an uninitialized value [clang-analyzer-core.CallAndMessage]
      126 |         g_free (search_text);
          |         ^
    
    Found by Clang-19 Static Analyzer
    
    Signed-off-by: Andreas Mohr <and@gmx.li>
    ---
     src/editor/editsearch.c | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
    
    diff --git a/src/editor/editsearch.c b/src/editor/editsearch.c
    index 72f2a53e6..229c505f0 100644
    a b edit_search_options_t edit_search_options = { 
    7575static gboolean 
    7676edit_dialog_search_show (WEdit *edit) 
    7777{ 
    78     char *search_text; 
     78    char *search_text = NULL; 
    7979    size_t num_of_types = 0; 
    8080    gchar **list_of_types; 
    8181    int dialog_result; 
    edit_dialog_search_show (WEdit *edit) 
    121121 
    122122    g_strfreev (list_of_types); 
    123123 
    124     if (dialog_result == B_CANCEL || search_text[0] == '\0') 
     124    if (dialog_result == B_CANCEL || search_text == NULL || search_text[0] == '\0') 
    125125    { 
    126126        g_free (search_text); 
    127127        return FALSE;