Ticket #3607: mc-3607-Cleanup-cppcheck-warning-at-input_complete.patch

File mc-3607-Cleanup-cppcheck-warning-at-input_complete.patch, 4.0 KB (added by and, 8 years ago)
  • lib/widget/input_complete.c

    From 8092fe3c0c75c5d78845103024a7446103e569c7 Mon Sep 17 00:00:00 2001
    From: Andreas Mohr <and@gmx.li>
    Date: Thu, 28 Apr 2016 15:24:05 +0000
    Subject: [PATCH] Cleanup cppcheck warning at input_complete.c
    
    As other local functions use "text" as function parameter variable
    to fix cppcheck warning:
    
    [lib/widget/input_complete.c:569]: (error) Uninitialized variable: text
    
    Signed-off-by: Andreas Mohr <and@gmx.li>
    ---
     lib/widget/input_complete.c | 27 +++++++++++++--------------
     1 file changed, 13 insertions(+), 14 deletions(-)
    
    diff --git a/lib/widget/input_complete.c b/lib/widget/input_complete.c
    index 06f9b07..fa9c78f 100644
    a b hostname_completion_function (const char *text, int state, input_complete_t flag 
    538538 */ 
    539539 
    540540static char * 
    541 command_completion_function (const char *_text, int state, input_complete_t flags) 
     541command_completion_function (const char *text, int state, input_complete_t flags) 
    542542{ 
    543     char *text; 
     543    char *u_text; 
    544544    static const char *path_end; 
    545545    static gboolean isabsolute; 
    546546    static int phase; 
    command_completion_function (const char *_text, int state, input_complete_t flag 
    565565    }; 
    566566    char *p, *found; 
    567567 
    568     /* cppcheck-suppress uninitvar */ 
    569568    SHOW_C_CTX ("command_completion_function"); 
    570569 
    571570    if (!(flags & INPUT_COMPLETE_COMMANDS)) 
    572571        return 0; 
    573572 
    574     text = strutils_shell_unescape (_text); 
     573    u_text = strutils_shell_unescape (text); 
    575574    flags &= ~INPUT_COMPLETE_SHELL_ESC; 
    576575 
    577576    if (state == 0) 
    578577    {                           /* Initialize us a little bit */ 
    579         isabsolute = strchr (text, PATH_SEP) != NULL; 
     578        isabsolute = strchr (u_text, PATH_SEP) != NULL; 
    580579        if (!isabsolute) 
    581580        { 
    582581            words = bash_reserved; 
    583582            phase = 0; 
    584             text_len = strlen (text); 
     583            text_len = strlen (u_text); 
    585584 
    586585            if (path == NULL) 
    587586            { 
    command_completion_function (const char *_text, int state, input_complete_t flag 
    601600 
    602601    if (isabsolute) 
    603602    { 
    604         p = filename_completion_function (text, state, flags); 
     603        p = filename_completion_function (u_text, state, flags); 
    605604 
    606605        if (p != NULL) 
    607606        { 
    command_completion_function (const char *_text, int state, input_complete_t flag 
    611610            g_free (temp_p); 
    612611        } 
    613612 
    614         g_free (text); 
     613        g_free (u_text); 
    615614        return p; 
    616615    } 
    617616 
    command_completion_function (const char *_text, int state, input_complete_t flag 
    620619    { 
    621620    case 0:                    /* Reserved words */ 
    622621        for (; *words != NULL; words++) 
    623             if (strncmp (*words, text, text_len) == 0) 
     622            if (strncmp (*words, u_text, text_len) == 0) 
    624623            { 
    625                 g_free (text); 
     624                g_free (u_text); 
    626625                return g_strdup (*(words++)); 
    627626            } 
    628627        phase++; 
    629628        words = bash_builtins; 
    630629    case 1:                    /* Builtin commands */ 
    631630        for (; *words != NULL; words++) 
    632             if (strncmp (*words, text, text_len) == 0) 
     631            if (strncmp (*words, u_text, text_len) == 0) 
    633632            { 
    634                 g_free (text); 
     633                g_free (u_text); 
    635634                return g_strdup (*(words++)); 
    636635            } 
    637636        phase++; 
    command_completion_function (const char *_text, int state, input_complete_t flag 
    649648                if (cur_path >= path_end) 
    650649                    break; 
    651650                expanded = tilde_expand (*cur_path ? cur_path : "."); 
    652                 cur_word = mc_build_filename (expanded, text, (char *) NULL); 
     651                cur_word = mc_build_filename (expanded, u_text, (char *) NULL); 
    653652                g_free (expanded); 
    654653                canonicalize_pathname (cur_word); 
    655654                cur_path = strchr (cur_path, 0) + 1; 
    command_completion_function (const char *_text, int state, input_complete_t flag 
    676675        } 
    677676    } 
    678677 
    679     g_free (text); 
     678    g_free (u_text); 
    680679    return found; 
    681680} 
    682681