diff --git a/lib/charsets.c b/lib/charsets.c index 3bbf9a273..59ebd0947 100644 --- a/lib/charsets.c +++ b/lib/charsets.c @@ -535,7 +535,6 @@ convert_from_8bit_to_utf_c2 (const char input_char) unsigned char str[2]; unsigned char buf_ch[UTF8_CHAR_LEN + 1]; int ch = '.'; - int res = 0; GIConv conv; const char *cp_from; @@ -547,6 +546,8 @@ convert_from_8bit_to_utf_c2 (const char input_char) if (conv != INVALID_CONV) { + int res = 0; + switch (str_translate_char (conv, (char *) str, -1, (char *) buf_ch, sizeof (buf_ch))) { case ESTR_SUCCESS: diff --git a/lib/filehighlight/get-color.c b/lib/filehighlight/get-color.c index 8736bdea5..a4a392fa1 100644 --- a/lib/filehighlight/get-color.c +++ b/lib/filehighlight/get-color.c @@ -253,7 +253,6 @@ int mc_fhl_get_color (mc_fhl_t * fhl, file_entry_t * fe) { guint i; - mc_fhl_filter_t *mc_filter; int ret; if (fhl == NULL) @@ -261,6 +260,8 @@ mc_fhl_get_color (mc_fhl_t * fhl, file_entry_t * fe) for (i = 0; i < fhl->filters->len; i++) { + mc_fhl_filter_t *mc_filter; + mc_filter = (mc_fhl_filter_t *) g_ptr_array_index (fhl->filters, i); switch (mc_filter->type) { diff --git a/lib/keybind.c b/lib/keybind.c index eedea6bae..9e101b3b5 100644 --- a/lib/keybind.c +++ b/lib/keybind.c @@ -456,13 +456,14 @@ keybind_lookup_actionname (unsigned long action) const char * keybind_lookup_keymap_shortcut (const global_keymap_t * keymap, unsigned long action) { - size_t i; - if (keymap != NULL) + { + size_t i; + for (i = 0; keymap[i].key != 0; i++) if (keymap[i].command == action) return (keymap[i].caption[0] != '\0') ? keymap[i].caption : NULL; - + } return NULL; } @@ -471,12 +472,14 @@ keybind_lookup_keymap_shortcut (const global_keymap_t * keymap, unsigned long ac unsigned long keybind_lookup_keymap_command (const global_keymap_t * keymap, long key) { - size_t i; - if (keymap != NULL) + { + size_t i; + for (i = 0; keymap[i].key != 0; i++) if (keymap[i].key == key) return keymap[i].command; + } return CK_IgnoreKey; } diff --git a/lib/logging.c b/lib/logging.c index 4a7121099..7a7e961f1 100644 --- a/lib/logging.c +++ b/lib/logging.c @@ -112,13 +112,14 @@ get_log_filename (void) static void mc_va_log (const char *fmt, va_list args) { - FILE *f; char *logfilename; logfilename = get_log_filename (); if (logfilename != NULL) { + FILE *f; + f = fopen (logfilename, "a"); if (f != NULL) { diff --git a/lib/search/regex.c b/lib/search/regex.c index 748a52394..8fe513aab 100644 --- a/lib/search/regex.c +++ b/lib/search/regex.c @@ -6,7 +6,7 @@ The Free Software Foundation, Inc. Written by: - Slava Zanko , 2009, 2010, 2011 + Slava Zanko , 2009, 2010, 2011, 2013 Vitaliy Filippov , 2011 Andrew Borodin , 2013 @@ -290,11 +290,12 @@ static mc_search__found_cond_t mc_search__regex_found_cond (mc_search_t * lc_mc_search, GString * search_str) { gsize loop1; - mc_search_cond_t *mc_search_cond; - mc_search__found_cond_t ret; for (loop1 = 0; loop1 < lc_mc_search->conditions->len; loop1++) { + mc_search_cond_t *mc_search_cond; + mc_search__found_cond_t ret; + mc_search_cond = (mc_search_cond_t *) g_ptr_array_index (lc_mc_search->conditions, loop1); if (!mc_search_cond->regex_handle) @@ -303,7 +304,6 @@ mc_search__regex_found_cond (mc_search_t * lc_mc_search, GString * search_str) ret = mc_search__regex_found_cond_one (lc_mc_search, mc_search_cond->regex_handle, search_str); - if (ret != COND__NOT_FOUND) return ret; } @@ -330,16 +330,19 @@ mc_search_regex__get_max_num_of_replace_tokens (const gchar * str, gsize len) if (str[loop] == '$' && str[loop + 1] == '{') { gsize tmp_len; - char *tmp_str; - int tmp_token; + if (strutils_is_char_escaped (str, &str[loop])) continue; for (tmp_len = 0; loop + tmp_len + 2 < len && (str[loop + 2 + tmp_len] & (char) 0xf0) == 0x30; tmp_len++); + if (str[loop + 2 + tmp_len] == '}') { + int tmp_token; + char *tmp_str; + tmp_str = g_strndup (&str[loop + 2], tmp_len); tmp_token = atoi (tmp_str); if (max_token < tmp_token) @@ -458,7 +461,6 @@ mc_search_regex__process_replace_str (const GString * replace_str, const gsize c gsize * skip_len, replace_transform_type_t * replace_flags) { int ret = -1; - char *tmp_str; const char *curr_str = &(replace_str->str[current_pos]); if (current_pos > replace_str->len) @@ -469,6 +471,8 @@ mc_search_regex__process_replace_str (const GString * replace_str, const gsize c if ((*curr_str == '$') && (*(curr_str + 1) == '{') && ((*(curr_str + 2) & (char) 0xf0) == 0x30) && (replace_str->len > current_pos + 2)) { + char *tmp_str; + if (strutils_is_char_escaped (replace_str->str, curr_str)) { *skip_len = 1; @@ -914,7 +918,7 @@ mc_search_regex_prepare_replace_str (mc_search_t * lc_mc_search, GString * repla GString *ret; gchar *tmp_str; - int num_replace_tokens, lc_index; + int num_replace_tokens; gsize loop; gsize len = 0; gchar *prev_str; @@ -939,6 +943,8 @@ mc_search_regex_prepare_replace_str (mc_search_t * lc_mc_search, GString * repla for (loop = 0; loop < replace_str->len - 1; loop++) { + int lc_index; + lc_index = mc_search_regex__process_replace_str (replace_str, loop, &len, &replace_flags); if (lc_index == REPLACE_PREPARE_T_NOTHING_SPECIAL) diff --git a/lib/strutil/strutil.c b/lib/strutil/strutil.c index 184fa86f7..e887a3f9a 100644 --- a/lib/strutil/strutil.c +++ b/lib/strutil/strutil.c @@ -760,7 +760,6 @@ str_msg_term_size (const char *text, int *lines, int *columns) char *p, *tmp; char *q; char c = '\0'; - int width; *lines = 1; *columns = 0; @@ -770,6 +769,8 @@ str_msg_term_size (const char *text, int *lines, int *columns) while (TRUE) { + int width; + q = strchr (p, '\n'); if (q != NULL) { diff --git a/lib/strutil/strutil8bit.c b/lib/strutil/strutil8bit.c index 1a6f123a1..5431fab8d 100644 --- a/lib/strutil/strutil8bit.c +++ b/lib/strutil/strutil8bit.c @@ -348,7 +348,6 @@ str_8bit_term_trim (const char *text, int width) static char result[BUF_MEDIUM]; size_t remain; char *actual; - size_t pos = 0; size_t length; length = strlen (text); @@ -357,9 +356,12 @@ str_8bit_term_trim (const char *text, int width) if (width > 0) { + size_t pos; + if (width >= (int) length) { - for (; pos < length && remain > 1; pos++, actual++, remain--) + + for (pos = 0; pos < length && remain > 1; pos++, actual++, remain--) actual[0] = char_isprint (text[pos]) ? text[pos] : '.'; } else if (width <= 3) @@ -373,8 +375,7 @@ str_8bit_term_trim (const char *text, int width) actual += 3; remain -= 3; - pos += length - width + 3; - for (; pos < length && remain > 1; pos++, actual++, remain--) + for (pos = length - width + 3; pos < length && remain > 1; pos++, actual++, remain--) actual[0] = char_isprint (text[pos]) ? text[pos] : '.'; } } @@ -408,7 +409,6 @@ str_8bit_term_substring (const char *text, int start, int width) static char result[BUF_MEDIUM]; size_t remain; char *actual; - size_t pos = 0; size_t length; actual = result; @@ -417,8 +417,10 @@ str_8bit_term_substring (const char *text, int start, int width) if (start < (int) length) { - pos += start; - for (; pos < length && width > 0 && remain > 1; pos++, width--, actual++, remain--) + size_t pos; + + for (pos = start; pos < length && width > 0 && remain > 1; + pos++, width--, actual++, remain--) actual[0] = char_isprint (text[pos]) ? text[pos] : '.'; } @@ -518,7 +520,6 @@ str_8bit_search_first (const char *text, const char *search, int case_sen) char *fold_text; char *fold_search; const char *match; - size_t offset; fold_text = (case_sen) ? (char *) text : str_8bit_strdown (text); fold_search = (case_sen) ? (char *) search : str_8bit_strdown (search); @@ -526,6 +527,8 @@ str_8bit_search_first (const char *text, const char *search, int case_sen) match = g_strstr_len (fold_text, -1, fold_search); if (match != NULL) { + size_t offset; + offset = match - fold_text; match = text + offset; } @@ -545,7 +548,6 @@ str_8bit_search_last (const char *text, const char *search, int case_sen) char *fold_text; char *fold_search; const char *match; - size_t offset; fold_text = (case_sen) ? (char *) text : str_8bit_strdown (text); fold_search = (case_sen) ? (char *) search : str_8bit_strdown (search); @@ -553,6 +555,8 @@ str_8bit_search_last (const char *text, const char *search, int case_sen) match = g_strrstr_len (fold_text, -1, fold_search); if (match != NULL) { + size_t offset; + offset = match - fold_text; match = text + offset; } diff --git a/lib/strutil/strutilascii.c b/lib/strutil/strutilascii.c index d0638c202..c8946243a 100644 --- a/lib/strutil/strutilascii.c +++ b/lib/strutil/strutilascii.c @@ -313,20 +313,20 @@ str_ascii_term_trim (const char *text, int width) static char result[BUF_MEDIUM]; size_t remain; char *actual; - size_t pos = 0; size_t length; length = strlen (text); actual = result; remain = sizeof (result); - if (width > 0) { + size_t pos; + if (width >= (int) length) { /* copy all characters */ - for (; pos < length && remain > 1; pos++, actual++, remain--) + for (pos = 0; pos < length && remain > 1; pos++, actual++, remain--) { actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?'; actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.'; @@ -343,10 +343,8 @@ str_ascii_term_trim (const char *text, int width) actual += 3; remain -= 3; - pos += length - width + 3; - /* copy suffix of text */ - for (; pos < length && remain > 1; pos++, actual++, remain--) + for (pos = length - width + 3; pos < length && remain > 1; pos++, actual++, remain--) { actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?'; actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.'; @@ -383,7 +381,6 @@ str_ascii_term_substring (const char *text, int start, int width) static char result[BUF_MEDIUM]; size_t remain; char *actual; - size_t pos = 0; size_t length; actual = result; @@ -392,11 +389,12 @@ str_ascii_term_substring (const char *text, int start, int width) if (start < (int) length) { - pos += start; - /* copy at most width characters from text from start */ - for (; pos < length && width > 0 && remain > 1; pos++, width--, actual++, remain--) - { + size_t pos; + /* copy at most width characters from text from start */ + for (pos = start; pos < length && width > 0 && remain > 1; + pos++, width--, actual++, remain--) + { actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?'; actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.'; } @@ -497,7 +495,6 @@ str_ascii_search_first (const char *text, const char *search, int case_sen) char *fold_text; char *fold_search; const char *match; - size_t offset; fold_text = (case_sen) ? (char *) text : g_ascii_strdown (text, -1); fold_search = (case_sen) ? (char *) search : g_ascii_strdown (search, -1); @@ -505,6 +502,8 @@ str_ascii_search_first (const char *text, const char *search, int case_sen) match = g_strstr_len (fold_text, -1, fold_search); if (match != NULL) { + size_t offset; + offset = match - fold_text; match = text + offset; } @@ -524,7 +523,6 @@ str_ascii_search_last (const char *text, const char *search, int case_sen) char *fold_text; char *fold_search; const char *match; - size_t offset; fold_text = (case_sen) ? (char *) text : g_ascii_strdown (text, -1); fold_search = (case_sen) ? (char *) search : g_ascii_strdown (search, -1); @@ -532,6 +530,8 @@ str_ascii_search_last (const char *text, const char *search, int case_sen) match = g_strrstr_len (fold_text, -1, fold_search); if (match != NULL) { + size_t offset; + offset = match - fold_text; match = text + offset; } diff --git a/lib/strutil/strutilutf8.c b/lib/strutil/strutilutf8.c index f759c6473..a06b59fc0 100644 --- a/lib/strutil/strutilutf8.c +++ b/lib/strutil/strutilutf8.c @@ -439,11 +439,12 @@ str_utf8_term_form (const char *text) { static char result[BUF_MEDIUM * 6]; const struct term_form *pre_form; - char *composed; pre_form = str_utf8_make_make_term_form (text, (size_t) (-1)); if (pre_form->compose) { + char *composed; + composed = g_utf8_normalize (pre_form->text, -1, G_NORMALIZE_DEFAULT_COMPOSE); g_strlcpy (result, composed, sizeof (result)); g_free (composed); diff --git a/lib/tty/color-internal.c b/lib/tty/color-internal.c index 70c965a76..77ee4e9fc 100644 --- a/lib/tty/color-internal.c +++ b/lib/tty/color-internal.c @@ -2,12 +2,12 @@ Internal stuff of color setup Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - 2007, 2008, 2009, 2010, 2011 + 2007, 2008, 2009, 2010, 2011, 2013 The Free Software Foundation, Inc. Written by: Andrew Borodin , 2009 - Slava Zanko , 2009 + Slava Zanko , 2009, 2013 Egmont Koblinger , 2010 This file is part of the Midnight Commander. @@ -124,7 +124,6 @@ parse_256_color_name (const char *color_name) const char * tty_color_get_name_by_index (int idx) { - static char **color_N_names = NULL; int i; /* Find the real English name of the first 16 colors, */ @@ -135,6 +134,8 @@ tty_color_get_name_by_index (int idx) /* Create and return the strings "color16" to "color255". */ if (idx >= 16 && idx < 256) { + static char **color_N_names = NULL; + if (color_N_names == NULL) { color_N_names = g_try_malloc0 (240 * sizeof (char *)); @@ -172,14 +173,18 @@ int tty_attr_get_bits (const char *attrs) { int attr_bits = 0; - gchar **attr_list; - int i, j; if (attrs != NULL) { + gchar **attr_list; + int i; + attr_list = g_strsplit (attrs, "+", -1); + for (i = 0; attr_list[i] != NULL; i++) { + int j; + for (j = 0; attributes_table[j].name != NULL; j++) { if (strcmp (attr_list[i], attributes_table[j].name) == 0) diff --git a/lib/tty/color-slang.c b/lib/tty/color-slang.c index a41c46987..01ef3ac22 100644 --- a/lib/tty/color-slang.c +++ b/lib/tty/color-slang.c @@ -65,18 +65,17 @@ has_colors (gboolean disable, gboolean force) { const char *terminal = getenv ("TERM"); const size_t len = strlen (terminal); - char *cts = mc_global.tty.color_terminal_string; - char *s; - size_t i; /* check mc_global.tty.color_terminal_string */ while (*cts != '\0') { + char *s; + size_t i = 0; + while (*cts == ' ' || *cts == '\t') cts++; s = cts; - i = 0; while (*cts != '\0' && *cts != ',') { @@ -145,7 +144,6 @@ tty_color_deinit_lib (void) void tty_color_try_alloc_pair_lib (tty_color_pair_t * mc_color_pair) { - const char *fg, *bg; if (mc_color_pair->ifg <= (int) SPEC_A_REVERSE) { switch (mc_color_pair->ifg) @@ -172,6 +170,8 @@ tty_color_try_alloc_pair_lib (tty_color_pair_t * mc_color_pair) } else { + const char *fg, *bg; + fg = tty_color_get_name_by_index (mc_color_pair->ifg); bg = tty_color_get_name_by_index (mc_color_pair->ibg); SLtt_set_color (mc_color_pair->pair_index, (char *) "", (char *) fg, (char *) bg); diff --git a/lib/tty/key.c b/lib/tty/key.c index a77141b35..d020ebf91 100644 --- a/lib/tty/key.c +++ b/lib/tty/key.c @@ -606,17 +606,16 @@ try_channels (int set_timeout) { struct timeval time_out; static fd_set select_set; - struct timeval *timeptr; - int v; - int maxfdp; while (1) { + struct timeval *timeptr = NULL; + int maxfdp, v; + FD_ZERO (&select_set); FD_SET (input_fd, &select_set); /* Add stdin */ maxfdp = max (add_selects (&select_set), input_fd); - timeptr = NULL; if (set_timeout) { time_out.tv_sec = 0; @@ -867,7 +866,7 @@ get_modifier (void) { int result = 0; #ifdef __QNXNTO__ - int mod_status, shift_ext_status; + int mod_status; static int in_photon = 0; static int ph_ig = 0; PhCursorInfo_t cursor_info; @@ -922,6 +921,8 @@ get_modifier (void) console or xterm */ if (in_photon == -1) { + int shift_ext_status; + if (devctl (fileno (stdin), DCMD_CHR_LINESTATUS, &mod_status, sizeof (int), NULL) == -1) return 0; shift_ext_status = mod_status & 0xffffff00UL; @@ -1951,7 +1952,6 @@ int tty_get_event (struct Gpm_Event *event, gboolean redo_event, gboolean block) { int c; - static int flag = 0; /* Return value from select */ #ifdef HAVE_LIBGPM static struct Gpm_Event ev; /* Mouse event */ #endif @@ -1984,6 +1984,7 @@ tty_get_event (struct Gpm_Event *event, gboolean redo_event, gboolean block) while (pending_keys == NULL) { int nfd; + static int flag = 0; /* Return value from select */ fd_set select_set; FD_ZERO (&select_set); diff --git a/lib/tty/keyxdef.c b/lib/tty/keyxdef.c index 66739c262..2764d26e0 100644 --- a/lib/tty/keyxdef.c +++ b/lib/tty/keyxdef.c @@ -415,7 +415,7 @@ load_qnx_key_defines (void) if (!_qnx_keys_defined) { - int idx, str_idx; + int idx; int term_setup_ok; __setupterm (NULL, fileno (stdout), &term_setup_ok); @@ -424,7 +424,8 @@ load_qnx_key_defines (void) for (idx = 0; idx < sizeof (xtra_key_defines) / sizeof (xtra_key_defines[0]); idx++) { - str_idx = xtra_key_defines[idx].str_idx; + int str_idx = xtra_key_defines[idx].str_idx; + if (__QTISOFFS (str_idx)) { if (*__QTISSTR (str_idx)) diff --git a/lib/tty/tty-ncurses.c b/lib/tty/tty-ncurses.c index 9599aca8a..5bf8612f1 100644 --- a/lib/tty/tty-ncurses.c +++ b/lib/tty/tty-ncurses.c @@ -528,8 +528,6 @@ tty_print_char (int c) void tty_print_anychar (int c) { - unsigned char str[UTF8_CHAR_LEN + 1]; - if (mc_global.utf8_display || c > 255) { int res; @@ -543,6 +541,7 @@ tty_print_anychar (int c) } else { + unsigned char str[UTF8_CHAR_LEN + 1]; const char *s; str[res] = '\0'; diff --git a/lib/tty/tty-slang.c b/lib/tty/tty-slang.c index 8b830a4c4..6e6f2388e 100644 --- a/lib/tty/tty-slang.c +++ b/lib/tty/tty-slang.c @@ -168,12 +168,13 @@ static void slang_reset_softkeys (void) { int key; - char *send; static const char display[] = " "; char tmp[BUF_SMALL]; for (key = 1; key < 9; key++) { + char *send; + g_snprintf (tmp, sizeof (tmp), "k%d", key); send = (char *) SLtt_tgetstr (tmp); if (send != NULL) @@ -672,11 +673,12 @@ tty_print_alt_char (int c, gboolean single) void tty_print_anychar (int c) { - char str[UTF8_CHAR_LEN + 1]; - if (c > 255) { - int res = g_unichar_to_utf8 (c, str); + char str[UTF8_CHAR_LEN + 1]; + int res; + + res = g_unichar_to_utf8 (c, str); if (res == 0) { str[0] = '.'; diff --git a/lib/tty/x11conn.c b/lib/tty/x11conn.c index 0ce1f22f6..e05120cbc 100644 --- a/lib/tty/x11conn.c +++ b/lib/tty/x11conn.c @@ -179,12 +179,12 @@ x11_available (void) Display * mc_XOpenDisplay (const char *displayname) { - Display *retval; - if (x11_available ()) { if (setjmp (x11_exception) == 0) { + Display *retval; + longjmp_allowed = TRUE; retval = func_XOpenDisplay (displayname); longjmp_allowed = FALSE; @@ -199,12 +199,12 @@ mc_XOpenDisplay (const char *displayname) int mc_XCloseDisplay (Display * display) { - int retval; - if (x11_available ()) { if (setjmp (x11_exception) == 0) { + int retval; + longjmp_allowed = TRUE; retval = func_XCloseDisplay (display); longjmp_allowed = FALSE; diff --git a/lib/utilunix.c b/lib/utilunix.c index 3f8129e31..715561dce 100644 --- a/lib/utilunix.c +++ b/lib/utilunix.c @@ -240,7 +240,6 @@ char * get_owner (int uid) { struct passwd *pwd; - static char ibuf[10]; char *name; static int uid_last; @@ -256,6 +255,8 @@ get_owner (int uid) } else { + static char ibuf[10]; + g_snprintf (ibuf, sizeof (ibuf), "%d", uid); return ibuf; } @@ -267,7 +268,6 @@ char * get_group (int gid) { struct group *grp; - static char gbuf[10]; char *name; static int gid_last; @@ -283,6 +283,8 @@ get_group (int gid) } else { + static char gbuf[10]; + g_snprintf (gbuf, sizeof (gbuf), "%d", gid); return gbuf; } @@ -463,7 +465,6 @@ tilde_expand (const char *directory) { struct passwd *passwd; const char *p, *q; - char *name; if (*directory != '~') return g_strdup (directory); @@ -485,6 +486,8 @@ tilde_expand (const char *directory) } else { + char *name; + name = g_strndup (p, q - p); passwd = getpwnam (name); q++; @@ -624,7 +627,6 @@ void custom_canonicalize_pathname (char *path, CANON_PATH_FLAGS flags) { char *p, *s; - size_t len; char *lpath = path; /* path without leading UNC part */ const size_t url_delim_len = strlen (VFS_PATH_URL_DELIMITER); @@ -672,6 +674,8 @@ custom_canonicalize_pathname (char *path, CANON_PATH_FLAGS flags) if (flags & CANON_PATH_REMSLASHDOTS) { + size_t len; + /* Remove trailing slashes */ p = lpath + strlen (lpath) - 1; while (p > lpath && *p == PATH_SEP) diff --git a/lib/vfs/direntry.c b/lib/vfs/direntry.c index b4c433d68..0dbc79944 100644 --- a/lib/vfs/direntry.c +++ b/lib/vfs/direntry.c @@ -1238,7 +1238,6 @@ vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode) char *dirname, *name; struct vfs_s_entry *ent; struct vfs_s_inode *dir; - int tmp_handle; /* If the filesystem is read-only, disable file creation */ if (!(flags & O_CREAT) || !(path_element->class->write)) @@ -1258,6 +1257,7 @@ vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode) vfs_s_insert_entry (path_element->class, dir, ent); if ((VFSDATA (path_element)->flags & VFS_S_USETMP) != 0) { + int tmp_handle; vfs_path_t *tmp_vpath; tmp_handle = vfs_mkstemps (&tmp_vpath, path_element->class->name, name); @@ -1547,7 +1547,6 @@ vfs_s_get_line (struct vfs_class *me, int sock, char *buf, int buf_len, char ter int vfs_s_get_line_interruptible (struct vfs_class *me, char *buffer, int size, int fd) { - int n; int i; (void) me; @@ -1555,6 +1554,8 @@ vfs_s_get_line_interruptible (struct vfs_class *me, char *buffer, int size, int tty_enable_interrupt_key (); for (i = 0; i < size - 1; i++) { + int n; + n = read (fd, buffer + i, 1); tty_disable_interrupt_key (); if (n == -1 && errno == EINTR) diff --git a/lib/vfs/path.c b/lib/vfs/path.c index e847a2b4e..b792fad16 100644 --- a/lib/vfs/path.c +++ b/lib/vfs/path.c @@ -239,7 +239,7 @@ vfs_path_url_split (vfs_path_element_t * path_element, const char *path) { char *pcopy; const char *pend; - char *colon, *inner_colon, *at, *rest; + char *colon, *at, *rest; path_element->port = 0; @@ -254,6 +254,8 @@ vfs_path_url_split (vfs_path_element_t * path_element, const char *path) rest = pcopy; else { + char *inner_colon; + *at = '\0'; inner_colon = strchr (pcopy, ':'); if (inner_colon != NULL) @@ -443,7 +445,6 @@ vfs_path_from_str_uri_parser (char *path, vfs_path_flag_t flags) { char *vfs_prefix_start; char *real_vfs_prefix_start = url_delimiter; - char *slash_pointer; struct vfs_s_subclass *sub = NULL; while (real_vfs_prefix_start > path && *(real_vfs_prefix_start) != PATH_SEP) @@ -463,6 +464,8 @@ vfs_path_from_str_uri_parser (char *path, vfs_path_flag_t flags) sub = VFSDATA (element); if (sub != NULL && (sub->flags & VFS_S_REMOTE) != 0) { + char *slash_pointer; + slash_pointer = strchr (url_delimiter, PATH_SEP); if (slash_pointer == NULL) { diff --git a/lib/vfs/utilvfs.c b/lib/vfs/utilvfs.c index d16ff0681..df104413a 100644 --- a/lib/vfs/utilvfs.c +++ b/lib/vfs/utilvfs.c @@ -2,7 +2,7 @@ Utilities for VFS modules. Copyright (C) 1988, 1992, 1998, 1999, 2000, 2001, 2002, 2003, 2004, - 2005, 2006, 2007, 2011 + 2005, 2006, 2007, 2011, 2013 The Free Software Foundation, Inc. Copyright (C) 1995, 1996 Miguel de Icaza @@ -60,11 +60,13 @@ #define TGNMLEN 256 #endif -#define myuid ( my_uid < 0? (my_uid = getuid()): my_uid ) -#define mygid ( my_gid < 0? (my_gid = getgid()): my_gid ) - #define MC_HISTORY_VFS_PASSWORD "mc.vfs.password" +/* + * FIXME2, the "-993" is to reduce the chance of a hit on the first lookup. + */ +#define GUID_DEFAULT_CONST -993 + /*** file scope type declarations ****************************************************************/ /*** file scope variables ************************************************************************/ @@ -96,7 +98,6 @@ vfs_get_local_username (void) /** * Look up a user or group name from a uid/gid, maintaining a cache. * FIXME, for now it's a one-entry cache. - * FIXME2, the "-993" is to reduce the chance of a hit on the first lookup. * This file should be modified for non-unix systems to do something * reasonable. */ @@ -106,15 +107,14 @@ vfs_get_local_username (void) int vfs_finduid (const char *uname) { - static int saveuid = -993; - static char saveuname[TUNMLEN]; - static int my_uid = -993; - - struct passwd *pw; + static int saveuid = GUID_DEFAULT_CONST; + static char saveuname[TUNMLEN] = "\0"; if (uname[0] != saveuname[0] /* Quick test w/o proc call */ || 0 != strncmp (uname, saveuname, TUNMLEN)) { + struct passwd *pw; + g_strlcpy (saveuname, uname, TUNMLEN); pw = getpwnam (uname); if (pw) @@ -123,7 +123,12 @@ vfs_finduid (const char *uname) } else { - saveuid = myuid; + static int my_uid = GUID_DEFAULT_CONST; + + if (my_uid < 0) + my_uid = getuid (); + + saveuid = my_uid; } } return saveuid; @@ -134,15 +139,15 @@ vfs_finduid (const char *uname) int vfs_findgid (const char *gname) { - static int savegid = -993; - static char savegname[TGNMLEN]; - static int my_gid = -993; + static int savegid = GUID_DEFAULT_CONST; + static char savegname[TGNMLEN] = "\0"; - struct group *gr; if (gname[0] != savegname[0] /* Quick test w/o proc call */ || 0 != strncmp (gname, savegname, TUNMLEN)) { + struct group *gr; + g_strlcpy (savegname, gname, TUNMLEN); gr = getgrnam (gname); if (gr) @@ -151,7 +156,12 @@ vfs_findgid (const char *gname) } else { - savegid = mygid; + static int my_gid = GUID_DEFAULT_CONST; + + if (my_gid < 0) + my_gid = getgid (); + + savegid = my_gid; } } return savegid; @@ -232,7 +242,7 @@ vfs_url_split (const char *path, int default_port, vfs_url_flags_t flags) char *pcopy; size_t pcopy_len; const char *pend; - char *dir, *colon, *inner_colon, *at, *rest; + char *dir, *colon, *at, *rest; path_element = g_new0 (vfs_path_element_t, 1); path_element->port = default_port; @@ -264,6 +274,8 @@ vfs_url_split (const char *path, int default_port, vfs_url_flags_t flags) rest = pcopy; else { + char *inner_colon; + *at = '\0'; inner_colon = strchr (pcopy, ':'); if (inner_colon != NULL) diff --git a/lib/vfs/vfs.c b/lib/vfs/vfs.c index 6e0b3369b..f14e22ab3 100644 --- a/lib/vfs/vfs.c +++ b/lib/vfs/vfs.c @@ -113,7 +113,6 @@ _vfs_translate_path (const char *path, int size, GIConv defcnv, GString * buffer estr_t state = ESTR_SUCCESS; #ifdef HAVE_CHARSET const char *semi; - const char *slash; if (size == 0) return ESTR_SUCCESS; @@ -125,6 +124,7 @@ _vfs_translate_path (const char *path, int size, GIConv defcnv, GString * buffer if (semi != NULL && (semi == path || *(semi - 1) == PATH_SEP)) { char encoding[16]; + const char *slash; GIConv coder = INVALID_CONV; int ms; diff --git a/lib/widget/buttonbar.c b/lib/widget/buttonbar.c index ad48073b8..90ef2d97a 100644 --- a/lib/widget/buttonbar.c +++ b/lib/widget/buttonbar.c @@ -162,7 +162,6 @@ buttonbar_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, voi { WButtonBar *bb = BUTTONBAR (w); int i; - const char *text; switch (msg) { @@ -187,6 +186,7 @@ buttonbar_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, voi for (i = 0; i < BUTTONBAR_LABELS_NUM; i++) { int width; + const char *text; width = buttonbar_get_button_width (bb, i); if (width <= 0) diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c index 058ae92e9..8bf638c9d 100644 --- a/lib/widget/dialog.c +++ b/lib/widget/dialog.c @@ -528,7 +528,6 @@ dlg_key_event (WDialog * h, int d_key) static void frontend_dlg_run (WDialog * h) { - int d_key; Gpm_Event event; event.x = -1; @@ -542,6 +541,8 @@ frontend_dlg_run (WDialog * h) while (h->state == DLG_ACTIVE) { + int d_key; + if (mc_global.tty.winch_flag != 0) dialog_change_screen_size (); diff --git a/lib/widget/history.c b/lib/widget/history.c index a723ddb74..fdc58285a 100644 --- a/lib/widget/history.c +++ b/lib/widget/history.c @@ -290,7 +290,7 @@ char * history_show (GList ** history, Widget * widget, int current) { GList *z, *hlist = NULL, *hi; - size_t maxlen, i, count = 0; + size_t maxlen, count = 0; char *r = NULL; WDialog *query_dlg; WListbox *query_list; @@ -304,6 +304,7 @@ history_show (GList ** history, Widget * widget, int current) for (z = *history; z != NULL; z = g_list_previous (z)) { WLEntry *entry; + size_t i; i = str_term_width1 ((char *) z->data); maxlen = max (maxlen, i); diff --git a/lib/widget/input.c b/lib/widget/input.c index 65e9170fa..a285f5b16 100644 --- a/lib/widget/input.c +++ b/lib/widget/input.c @@ -312,7 +312,6 @@ move_buffer_backward (WInput * in, int start, int end) static cb_ret_t insert_char (WInput * in, int c_code) { - size_t i; int res; if (in->highlight) @@ -356,6 +355,7 @@ insert_char (WInput * in, int c_code) if (strlen (in->buffer) + in->charpoint < in->current_max_size) { + size_t i; /* bytes from begin */ size_t ins_point = str_offset_to_pos (in->buffer, in->point); /* move chars */ @@ -1253,7 +1253,6 @@ input_update (WInput * in, gboolean clear_first) { Widget *w = WIDGET (in); int has_history = 0; - int i; int buf_len; const char *cp; int pw; @@ -1332,6 +1331,8 @@ input_update (WInput * in, gboolean clear_first) } else { + int i; + cp = str_term_substring (in->buffer, in->term_first_shown, w->cols - has_history); tty_setcolor (in->color[WINPUTC_MAIN]); for (i = 0; i < w->cols - has_history; i++) diff --git a/lib/widget/input_complete.c b/lib/widget/input_complete.c index 9ca47ef52..6fc6866ac 100644 --- a/lib/widget/input_complete.c +++ b/lib/widget/input_complete.c @@ -736,8 +736,6 @@ completion_matches (const char *text, CompletionFunction entry_function, input_c lowest common denominator. That then becomes match_list[0]. */ if (matches) { - register size_t i = 1; - int low = 4096; /* Count of max-matched characters. */ /* If only one match, just use that. */ if (matches == 1) @@ -747,6 +745,8 @@ completion_matches (const char *text, CompletionFunction entry_function, input_c } else { + size_t i = 1; + int low = 4096; /* Count of max-matched characters. */ size_t j; qsort (match_list + 1, matches, sizeof (char *), match_compare); @@ -847,12 +847,11 @@ try_complete_commands_prepare (try_complete_automation_state_t * state, char *te state->in_command_position++; else if (strchr (command_separator_chars, ti[0]) != NULL) { - int this_char, prev_char; - state->in_command_position++; - if (ti != text) { + int this_char, prev_char; + /* Handle the two character tokens '>&', '<&', and '>|'. We are not in a command position after one of these. */ this_char = ti[0]; @@ -938,20 +937,20 @@ try_complete_all_possible (try_complete_automation_state_t * state, char *text, { char *const cdpath_ref = g_strdup (getenv ("CDPATH")); char *cdpath = cdpath_ref; - char c, *s; + char c; + + c = (cdpath == NULL) ? '\0' : ':'; - if (cdpath == NULL) - c = 0; - else - c = ':'; while (!matches && c == ':') { + char *s; + s = strchr (cdpath, ':'); if (s == NULL) - s = strchr (cdpath, 0); + s = strchr (cdpath, '\0'); c = *s; - *s = 0; - if (*cdpath) + *s = '\0'; + if (*cdpath != '\0') { state->r = mc_build_filename (cdpath, state->word, NULL); SHOW_C_CTX ("try_complete:filename_subst_2"); @@ -1009,7 +1008,6 @@ insert_text (WInput * in, char *text, ssize_t size) static cb_ret_t query_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data) { - static char buff[MB_LEN_MAX] = ""; static int bl = 0; WDialog *h = DIALOG (w); @@ -1085,6 +1083,7 @@ query_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d } else { + static char buff[MB_LEN_MAX] = ""; GList *e; int i; int need_redraw = 0; diff --git a/lib/widget/listbox-window.c b/lib/widget/listbox-window.c index eaec3fefc..656e6bf07 100644 --- a/lib/widget/listbox-window.c +++ b/lib/widget/listbox-window.c @@ -70,7 +70,7 @@ create_listbox_window_centered (int center_y, int center_x, int lines, int cols, const int space = 4; - int xpos, ypos, len; + int xpos, ypos; Listbox *listbox; /* Adjust sizes */ @@ -78,6 +78,8 @@ create_listbox_window_centered (int center_y, int center_x, int lines, int cols, if (title != NULL) { + int len; + len = str_term_width1 (title) + 4; cols = max (cols, len); } diff --git a/lib/widget/menu.c b/lib/widget/menu.c index ad2143a32..fb993fdc9 100644 --- a/lib/widget/menu.c +++ b/lib/widget/menu.c @@ -395,7 +395,6 @@ static void menubar_first (WMenuBar * menubar) { menu_t *menu = MENU (g_list_nth_data (menubar->menu, menubar->selected)); - menu_entry_t *entry; if (menu->selected == 0) return; @@ -406,6 +405,8 @@ menubar_first (WMenuBar * menubar) while (TRUE) { + menu_entry_t *entry; + entry = MENUENTRY (g_list_nth_data (menu->entries, menu->selected)); if ((entry == NULL) || (entry->command == CK_IgnoreKey)) diff --git a/lib/widget/wtools.c b/lib/widget/wtools.c index fcce526ed..925e6ec98 100644 --- a/lib/widget/wtools.c +++ b/lib/widget/wtools.c @@ -274,12 +274,10 @@ query_dialog (const char *header, const char *text, int flags, int count, ...) va_list ap; WDialog *query_dlg; WButton *button; - WButton *defbutton = NULL; int win_len = 0; int i; int result = -1; int cols, lines; - char *cur_name; const int *query_colors = (flags & D_ERROR) != 0 ? alarm_colors : dialog_colors; dlg_flags_t dlg_flags = (flags & D_CENTER) != 0 ? (DLG_CENTER | DLG_TRYUP) : DLG_NONE; @@ -311,9 +309,10 @@ query_dialog (const char *header, const char *text, int flags, int count, ...) if (count > 0) { + WButton *defbutton = NULL; + add_widget_autopos (query_dlg, label_new (2, 3, text), WPOS_KEEP_TOP | WPOS_CENTER_HORZ, NULL); - add_widget (query_dlg, hline_new (lines - 4, -1, -1)); cols = (cols - win_len - 2) / 2 + 2; @@ -321,6 +320,7 @@ query_dialog (const char *header, const char *text, int flags, int count, ...) for (i = 0; i < count; i++) { int xpos; + char *cur_name; cur_name = va_arg (ap, char *); xpos = str_term_width1 (cur_name) + 6; @@ -487,11 +487,12 @@ input_expand_dialog (const char *header, const char *text, input_complete_t completion_flags) { char *result; - char *expanded; result = input_dialog (header, text, history_name, def_text, completion_flags); if (result) { + char *expanded; + expanded = tilde_expand (result); g_free (result); return expanded; diff --git a/src/cons.handler.c b/src/cons.handler.c index 5797ab8e2..8c1ff4ff2 100644 --- a/src/cons.handler.c +++ b/src/cons.handler.c @@ -138,8 +138,6 @@ show_console_contents_linux (int starty, unsigned char begin_line, unsigned char static void handle_console_linux (console_action_t action) { - char *tty_name; - char *mc_conssaver; int status; switch (action) @@ -186,6 +184,8 @@ handle_console_linux (console_action_t action) else { /* Child */ + char *tty_name; + /* Close the extra pipe ends */ status = close (pipefd1[1]); status = close (pipefd2[0]); @@ -206,8 +206,10 @@ handle_console_linux (console_action_t action) if (dup2 (status, 2) == -1) break; status = close (status); - if (tty_name) + if (tty_name != NULL) { + char *mc_conssaver; + /* Exec the console save/restore handler */ mc_conssaver = mc_build_filename (SAVERDIR, "cons.saver", NULL); execl (mc_conssaver, "cons.saver", tty_name, (char *) NULL); diff --git a/src/diffviewer/search.c b/src/diffviewer/search.c index 9a0ea67cd..75ef95ef8 100644 --- a/src/diffviewer/search.c +++ b/src/diffviewer/search.c @@ -143,7 +143,6 @@ static gboolean mcdiffview_do_search_backward (WDiff * dview) { ssize_t ind; - DIFFLN *p; if (dview->search.last_accessed_num_line < 0) { @@ -156,6 +155,8 @@ mcdiffview_do_search_backward (WDiff * dview) for (ind = --dview->search.last_accessed_num_line; ind >= 0; ind--) { + DIFFLN *p; + p = (DIFFLN *) & g_array_index (dview->a[dview->ord], DIFFLN, (size_t) ind); if (p->u.len == 0) continue; @@ -177,7 +178,6 @@ static gboolean mcdiffview_do_search_forward (WDiff * dview) { size_t ind; - DIFFLN *p; if (dview->search.last_accessed_num_line < 0) dview->search.last_accessed_num_line = -1; @@ -190,6 +190,8 @@ mcdiffview_do_search_forward (WDiff * dview) for (ind = (size_t)++ dview->search.last_accessed_num_line; ind < dview->a[dview->ord]->len; ind++) { + DIFFLN *p; + p = (DIFFLN *) & g_array_index (dview->a[dview->ord], DIFFLN, ind); if (p->u.len == 0) continue; diff --git a/src/diffviewer/ydiff.c b/src/diffviewer/ydiff.c index 38149a0c3..6cc1ff57a 100644 --- a/src/diffviewer/ydiff.c +++ b/src/diffviewer/ydiff.c @@ -70,9 +70,11 @@ #define g_array_foreach(a, TP, cbf) \ do { \ size_t g_array_foreach_i;\ - TP *g_array_foreach_var = NULL; \ + \ for (g_array_foreach_i = 0; g_array_foreach_i < a->len; g_array_foreach_i++) \ { \ + TP *g_array_foreach_var; \ + \ g_array_foreach_var = &g_array_index (a, TP, g_array_foreach_i); \ (*cbf) (g_array_foreach_var); \ } \ @@ -1419,8 +1421,7 @@ cvt_mget (const char *src, size_t srcsize, char *dst, int dstsize, int skip, int utf_ch = dview_get_utf ((char *) src, &w, &res); if (w > 1) skip += w - 1; - if (!g_unichar_isprint (utf_ch)) - utf_ch = '.'; + (void) utf_ch; } else { @@ -1521,8 +1522,7 @@ cvt_mgeta (const char *src, size_t srcsize, char *dst, int dstsize, int skip, in utf_ch = dview_get_utf ((char *) src, &w, &res); if (w > 1) skip += w - 1; - if (!g_unichar_isprint (utf_ch)) - utf_ch = '.'; + (void) utf_ch; } else { @@ -1799,12 +1799,12 @@ redo_diff (WDiff * dview) if (dview->hdiff != NULL) { size_t i; - const DIFFLN *p; - const DIFFLN *q; for (i = 0; i < dview->a[DIFF_LEFT]->len; i++) { GArray *h = NULL; + const DIFFLN *p; + const DIFFLN *q; p = &g_array_index (dview->a[DIFF_LEFT], DIFFLN, i); q = &g_array_index (dview->a[DIFF_RIGHT], DIFFLN, i); @@ -2921,10 +2921,10 @@ dview_goto_cmd (WDiff * dview, diff_place_t ord) if (newline > 0) { - const DIFFLN *p; - for (; i < dview->a[ord]->len; i++) { + const DIFFLN *p; + p = &g_array_index (dview->a[ord], DIFFLN, i); if (p->line == newline) break; diff --git a/src/editor/edit.c b/src/editor/edit.c index 6bb50fb45..66a97fe4d 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -186,7 +186,7 @@ edit_load_file_fast (edit_buffer_t * buf, const vfs_path_t * filename_vpath) static int edit_find_filter (const vfs_path_t * filename_vpath) { - size_t i, l, e; + size_t i, l; if (filename_vpath == NULL) return -1; @@ -194,6 +194,8 @@ edit_find_filter (const vfs_path_t * filename_vpath) l = strlen (vfs_path_as_str (filename_vpath)); for (i = 0; i < G_N_ELEMENTS (all_filters); i++) { + size_t e; + e = strlen (all_filters[i].extension); if (l > e) if (!strcmp (all_filters[i].extension, vfs_path_as_str (filename_vpath) + l - e)) @@ -1336,7 +1338,6 @@ static void edit_auto_indent (WEdit * edit) { off_t p; - char c; p = edit->buffer.curs1; /* use the previous line as a template */ @@ -1344,6 +1345,8 @@ edit_auto_indent (WEdit * edit) /* copy the leading whitespace of the line */ while (TRUE) { /* no range check - the line _is_ \n-terminated */ + char c; + c = edit_buffer_get_byte (&edit->buffer, p++); if (c != ' ' && c != '\t') break; @@ -1419,7 +1422,6 @@ static void check_and_wrap_line (WEdit * edit) { off_t curs; - int c; if (!option_typewriter_wrap) return; @@ -1429,6 +1431,8 @@ check_and_wrap_line (WEdit * edit) curs = edit->buffer.curs1; while (TRUE) { + int c; + curs--; c = edit_buffer_get_byte (&edit->buffer, curs); if (c == '\n' || curs <= 0) @@ -1461,7 +1465,7 @@ static off_t edit_get_bracket (WEdit * edit, gboolean in_screen, unsigned long furthest_bracket_search) { const char *const b = "{}{[][()(", *p; - int i = 1, a, inc = -1, c, d, n = 0; + int i = 1, inc = -1, c, d, n = 0; unsigned long j = 0; off_t q; @@ -1481,6 +1485,8 @@ edit_get_bracket (WEdit * edit, gboolean in_screen, unsigned long furthest_brack inc = 1; for (q = edit->buffer.curs1 + inc;; q += inc) { + int a; + /* out of buffer? */ if (q >= edit->buffer.size || q < 0) break; @@ -3311,7 +3317,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) { str[res] = '\0'; } - while (i <= UTF8_CHAR_LEN && str[i] != 0) + while (i <= UTF8_CHAR_LEN && str[i] != '\0') { char_for_insertion = str[i]; edit_insert (edit, char_for_insertion); diff --git a/src/editor/editbuffer.c b/src/editor/editbuffer.c index 6a8964df6..1b73b5024 100644 --- a/src/editor/editbuffer.c +++ b/src/editor/editbuffer.c @@ -584,8 +584,6 @@ edit_buffer_backspace (edit_buffer_t * buf) off_t edit_buffer_move_forward (const edit_buffer_t * buf, off_t current, long lines, off_t upto) { - long next; - if (upto != 0) return (off_t) edit_buffer_count_lines (buf, current, upto); @@ -593,6 +591,8 @@ edit_buffer_move_forward (const edit_buffer_t * buf, off_t current, long lines, while (lines-- != 0) { + long next; + next = edit_buffer_get_eol (buf, current) + 1; if (next > buf->size) break; diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index f333ef949..8c6b9206f 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -1924,7 +1924,6 @@ edit_load_macro_cmd (WEdit * edit) gsize len, values_len; const char *section_name = "editor"; gchar *macros_fname; - int hotkey; (void) edit; @@ -1938,6 +1937,7 @@ edit_load_macro_cmd (WEdit * edit) keys = mc_config_get_keys (macros_config, section_name, &len); for (profile_keys = keys; *profile_keys != NULL; profile_keys++) { + int hotkey; gboolean have_macro = FALSE; GArray *macros; macros_t macro; @@ -2008,8 +2008,6 @@ edit_load_macro_cmd (WEdit * edit) gboolean edit_save_confirm_cmd (WEdit * edit) { - char *f = NULL; - if (edit->filename_vpath == NULL) return edit_save_as_cmd (edit); @@ -2018,6 +2016,7 @@ edit_save_confirm_cmd (WEdit * edit) if (edit_confirm_save) { + char *f; gboolean ok; f = g_strdup_printf (_("Confirm save file: \"%s\""), @@ -2278,7 +2277,6 @@ void edit_block_copy_cmd (WEdit * edit) { off_t start_mark, end_mark, current = edit->buffer.curs1; - long col_delta = 0; off_t mark1, mark2; long c1, c2; off_t size; @@ -2296,6 +2294,8 @@ edit_block_copy_cmd (WEdit * edit) if (edit->column_highlight) { + long col_delta; + col_delta = abs (edit->column2 - edit->column1); edit_insert_column_of_text (edit, copy_buf, size, col_delta, &mark1, &mark2, &c1, &c2); } diff --git a/src/editor/editcmd_dialogs.c b/src/editor/editcmd_dialogs.c index bde36351d..bccd6cbb5 100644 --- a/src/editor/editcmd_dialogs.c +++ b/src/editor/editcmd_dialogs.c @@ -419,7 +419,6 @@ editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_l WListbox *def_list; int def_dlg_h; /* dialog height */ int def_dlg_w; /* dialog width */ - char *label_def = NULL; (void) word_len; /* calculate the dialog metrics */ @@ -456,6 +455,8 @@ editcmd_dialog_select_definition_show (WEdit * edit, char *match_expr, int max_l /* fill the listbox with the completions */ for (i = 0; i < num_lines; i++) { + char *label_def; + label_def = g_strdup_printf ("%s -> %s:%ld", def_hash[i].short_define, def_hash[i].filename, def_hash[i].line); diff --git a/src/editor/editdraw.c b/src/editor/editdraw.c index cd084deb0..db7ad2480 100644 --- a/src/editor/editdraw.c +++ b/src/editor/editdraw.c @@ -510,13 +510,9 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c struct line_s *p = line; off_t m1 = 0, m2 = 0, q; - long c1, c2; int col, start_col_real; - unsigned int c; int color; int abn_style; - int i; - unsigned int cur_line = 0; int book_mark = 0; char line_stat[LINE_STATE_WIDTH + 1] = "\0"; @@ -547,6 +543,8 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c if (option_line_state) { + unsigned int cur_line; + cur_line = edit->start_line + row; if (cur_line <= (unsigned int) edit->buffer.lines) { @@ -572,6 +570,8 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c off_t tws = 0; if (tty_use_colors () && visible_tws) { + unsigned int c; + tws = edit_buffer_get_eol (&edit->buffer, b); while (tws > b && ((c = edit_buffer_get_byte (&edit->buffer, tws - 1)) == ' ' || c == '\t')) @@ -581,7 +581,7 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c while (col <= end_col - edit->start_col) { int cw = 1; - int tab_over = 0; + unsigned int c; gboolean wide_width_char = FALSE; gboolean control_char = FALSE; @@ -594,6 +594,7 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c if (edit->column_highlight) { long x; + long c1, c2; x = (long) edit_move_forward3 (edit, b, 0, q); c1 = min (edit->column1, edit->column2); @@ -632,74 +633,80 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c col = end_col - edit->start_col + 1; /* quit */ break; case '\t': - i = TAB_SIZE - ((int) col % TAB_SIZE); - tab_over = (end_col - edit->start_col) - (col + i - 1); - if (tab_over < 0) - i += tab_over; - col += i; - if (tty_use_colors () && - ((visible_tabs || (visible_tws && q >= tws)) && enable_show_tabs_tws)) { - if (p->style & MOD_MARKED) - c = p->style; - else if (book_mark) - c |= book_mark << 16; - else - c = p->style | MOD_WHITESPACE; - if (i > 2) + int tab_over; + int i; + + i = TAB_SIZE - ((int) col % TAB_SIZE); + tab_over = (end_col - edit->start_col) - (col + i - 1); + if (tab_over < 0) + i += tab_over; + col += i; + if (tty_use_colors () && + ((visible_tabs || (visible_tws && q >= tws)) && enable_show_tabs_tws)) { - p->ch = '<'; - p->style = c; - p++; - while (--i > 1) + if (p->style & MOD_MARKED) + c = p->style; + else if (book_mark) + c |= book_mark << 16; + else + c = p->style | MOD_WHITESPACE; + if (i > 2) { - p->ch = '-'; + p->ch = '<'; + p->style = c; + p++; + while (--i > 1) + { + p->ch = '-'; + p->style = c; + p++; + } + p->ch = '>'; + p->style = c; + p++; + } + else if (i > 1) + { + p->ch = '<'; + p->style = c; + p++; + p->ch = '>'; + p->style = c; + p++; + } + else + { + p->ch = '>'; p->style = c; p++; } - p->ch = '>'; - p->style = c; - p++; } - else if (i > 1) + else if (tty_use_colors () && visible_tws && q >= tws + && enable_show_tabs_tws) { - p->ch = '<'; - p->style = c; - p++; - p->ch = '>'; - p->style = c; + p->ch = '.'; + p->style |= MOD_WHITESPACE; + c = p->style & ~MOD_CURSOR; p++; + while (--i) + { + p->ch = ' '; + p->style = c; + p++; + } } else { - p->ch = '>'; - p->style = c; - p++; - } - } - else if (tty_use_colors () && visible_tws && q >= tws && enable_show_tabs_tws) - { - p->ch = '.'; - p->style |= MOD_WHITESPACE; - c = p->style & ~MOD_CURSOR; - p++; - while (--i) - { - p->ch = ' '; - p->style = c; - p++; - } - } - else - { - p->ch |= ' '; - c = p->style & ~MOD_CURSOR; - p++; - while (--i) - { - p->ch = ' '; - p->style = c; + p->ch |= ' '; + c = p->style & ~MOD_CURSOR; p++; + while (--i) + { + p->ch = ' '; + p->style = c; + p++; + } } } break; @@ -847,9 +854,7 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, Widget *w = WIDGET (edit); Widget *wh = WIDGET (w->owner); - long row = 0, curs_row; int force = edit->force; - long b; int y1, x1, y2, x2; int last_line; @@ -903,6 +908,8 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, */ if ((force & REDRAW_CHAR_ONLY) == 0 || (force & REDRAW_PAGE) != 0) { + long row, b; + if ((force & REDRAW_PAGE) != 0) { row = start_row; @@ -918,7 +925,7 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, } else { - curs_row = edit->curs_row; + long curs_row = edit->curs_row; if ((force & REDRAW_BEFORE_CURSOR) != 0 && start_row < curs_row) { diff --git a/src/editor/syntax.c b/src/editor/syntax.c index eca575847..84f832942 100644 --- a/src/editor/syntax.c +++ b/src/editor/syntax.c @@ -888,8 +888,6 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size) struct context_rule **r, *c = NULL; int num_words = -1, num_contexts = -1; int result = 0; - int argc; - int i, j; int alloc_contexts = MAX_CONTEXTS, alloc_words_per_context = MAX_WORDS_PER_CONTEXT, max_alloc_words_per_context = MAX_WORDS_PER_CONTEXT; @@ -909,6 +907,7 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size) { char **a; size_t len; + int argc; line++; l = 0; @@ -1200,7 +1199,8 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size) if (result == 0) { - char *first_chars, *p; + int i; + char *first_chars; if (num_contexts == -1) return line; @@ -1209,6 +1209,9 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size) for (i = 0; edit->rules[i] != NULL; i++) { + char *p; + int j; + c = edit->rules[i]; p = first_chars; *p++ = (char) 1; diff --git a/src/execute.c b/src/execute.c index de3401a1f..9dc8156be 100644 --- a/src/execute.c +++ b/src/execute.c @@ -450,7 +450,6 @@ toggle_panels (void) { #ifdef ENABLE_SUBSHELL vfs_path_t *new_dir_vpath = NULL; - vfs_path_t **new_dir_p; #endif /* ENABLE_SUBSHELL */ SIG_ATOMIC_VOLATILE_T was_sigwinch = 0; @@ -479,6 +478,8 @@ toggle_panels (void) #ifdef ENABLE_SUBSHELL if (mc_global.tty.use_subshell) { + vfs_path_t **new_dir_p; + new_dir_p = vfs_current_is_local ()? &new_dir_vpath : NULL; invoke_subshell (NULL, VISIBLY, new_dir_p); } diff --git a/src/filemanager/achown.c b/src/filemanager/achown.c index bda9a1eaa..2a1072d25 100644 --- a/src/filemanager/achown.c +++ b/src/filemanager/achown.c @@ -316,18 +316,19 @@ chl_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *dat static void do_enter_key (WDialog * h, int f_pos) { - WDialog *chl_dlg; WListbox *chl_list; struct passwd *chl_pass; struct group *chl_grp; int fe; - int lxx, lyy, b_pos; gboolean chl_end, is_owner; - const char *title; - int result; do { + int result; + WDialog *chl_dlg; + const char *title; + int lxx, lyy, b_pos; + is_owner = (f_pos == 3); title = is_owner ? _("owner") : _("group"); diff --git a/src/filemanager/boxes.c b/src/filemanager/boxes.c index f932f5273..62aa3a8dd 100644 --- a/src/filemanager/boxes.c +++ b/src/filemanager/boxes.c @@ -520,18 +520,17 @@ configure_box (void) void panel_options_box (void) { - const char *qsearch_options[] = { - N_("Case &insensitive"), - N_("Cas&e sensitive"), - N_("Use panel sort mo&de") - }; - int simple_swap; simple_swap = mc_config_get_bool (mc_main_config, CONFIG_PANELS_SECTION, "simple_swap", FALSE) ? 1 : 0; - { + const char *qsearch_options[] = { + N_("Case &insensitive"), + N_("Cas&e sensitive"), + N_("Use panel sort mo&de") + }; + quick_widget_t quick_widgets[] = { /* *INDENT-OFF* */ QUICK_START_COLUMNS, diff --git a/src/filemanager/chown.c b/src/filemanager/chown.c index cc04112b7..5040b1650 100644 --- a/src/filemanager/chown.c +++ b/src/filemanager/chown.c @@ -332,7 +332,6 @@ chown_cmd (void) { char *fname; struct stat sf_stat; - WDialog *ch_dlg; uid_t new_user; gid_t new_group; char buffer[BUF_TINY]; @@ -342,6 +341,7 @@ chown_cmd (void) do { /* do while any files remaining */ vfs_path_t *vpath; + WDialog *ch_dlg; ch_dlg = init_chown (); new_user = new_group = -1; diff --git a/src/filemanager/cmd.c b/src/filemanager/cmd.c index e5cf8ee7c..ba0d427f9 100644 --- a/src/filemanager/cmd.c +++ b/src/filemanager/cmd.c @@ -294,7 +294,7 @@ select_unselect_cmd (const char *title, const char *history_name, gboolean do_se static int compare_files (const vfs_path_t * vpath1, const vfs_path_t * vpath2, off_t size) { - int file1, file2; + int file1; int result = -1; /* Different by default */ if (size == 0) @@ -303,15 +303,20 @@ compare_files (const vfs_path_t * vpath1, const vfs_path_t * vpath2, off_t size) file1 = open (vfs_path_as_str (vpath1), O_RDONLY); if (file1 >= 0) { + int file2; + file2 = open (vfs_path_as_str (vpath2), O_RDONLY); if (file2 >= 0) { #ifdef HAVE_MMAP - char *data1, *data2; + char *data1; + /* Ugly if jungle */ data1 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file1, 0); if (data1 != (char *) -1) { + char *data2; + data2 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file2, 0); if (data2 != (char *) -1) { @@ -619,7 +624,6 @@ set_basic_panel_listing_to (int panel_index, int listing_mode) gboolean view_file_at_line (const vfs_path_t * filename_vpath, int plain_view, int internal, long start_line) { - static const char *viewer = NULL; gboolean ret = TRUE; if (plain_view) @@ -670,6 +674,8 @@ view_file_at_line (const vfs_path_t * filename_vpath, int plain_view, int intern } else { + static const char *viewer = NULL; + if (viewer == NULL) { viewer = getenv ("VIEWER"); @@ -784,7 +790,6 @@ view_filtered_cmd (void) void do_edit_at_line (const vfs_path_t * what_vpath, gboolean internal, long start_line) { - static const char *editor = NULL; #ifdef USE_INTERNAL_EDIT if (internal) @@ -792,6 +797,8 @@ do_edit_at_line (const vfs_path_t * what_vpath, gboolean internal, long start_li else #endif /* USE_INTERNAL_EDIT */ { + static const char *editor = NULL; + (void) internal; if (editor == NULL) @@ -1056,11 +1063,11 @@ void select_invert_cmd (void) { int i; - file_entry_t *file; for (i = 0; i < current_panel->dir.len; i++) { - file = ¤t_panel->dir.list[i]; + file_entry_t *file = ¤t_panel->dir.list[i]; + if (!panels_options.reverse_files_only || !S_ISDIR (file->st.st_mode)) do_file_mark (current_panel, i, !file->f.marked); } @@ -1087,7 +1094,6 @@ unselect_cmd (void) void ext_cmd (void) { - vfs_path_t *buffer_vpath; vfs_path_t *extdir_vpath; int dir; @@ -1102,6 +1108,8 @@ ext_cmd (void) if (dir == 0) { + vfs_path_t *buffer_vpath; + buffer_vpath = mc_config_get_full_vpath (MC_FILEBIND_FILE); check_for_default (extdir_vpath, buffer_vpath); do_edit (buffer_vpath); @@ -1180,7 +1188,6 @@ edit_mc_menu_cmd (void) void edit_fhl_cmd (void) { - vfs_path_t *buffer_vpath = NULL; vfs_path_t *fhlfile_vpath = NULL; int dir; @@ -1196,6 +1203,8 @@ edit_fhl_cmd (void) if (dir == 0) { + vfs_path_t *buffer_vpath; + buffer_vpath = mc_config_get_full_vpath (MC_FHL_INI_FILE); check_for_default (fhlfile_vpath, buffer_vpath); do_edit (buffer_vpath); @@ -1369,7 +1378,7 @@ edit_symlink_cmd (void) char buffer[MC_MAXPATHLEN]; char *p = NULL; int i; - char *dest, *q; + char *q; vfs_path_t *p_vpath; p = selection (current_panel)->fname; @@ -1380,6 +1389,8 @@ edit_symlink_cmd (void) i = readlink (p, buffer, MC_MAXPATHLEN - 1); if (i > 0) { + char *dest; + buffer[i] = 0; dest = input_expand_dialog (_("Edit symlink"), q, MC_HISTORY_FM_EDIT_LINK, buffer, diff --git a/src/filemanager/dir.c b/src/filemanager/dir.c index 05d06a448..ca7cc2841 100644 --- a/src/filemanager/dir.c +++ b/src/filemanager/dir.c @@ -386,12 +386,13 @@ sort_vers (file_entry_t * a, file_entry_t * b) int sort_ext (file_entry_t * a, file_entry_t * b) { - int r; int ad = MY_ISDIR (a); int bd = MY_ISDIR (b); if (ad == bd || panels_options.mix_all_files) { + int r; + if (a->second_sort_key == NULL) a->second_sort_key = str_create_key (extension (a->fname), case_sensitive); if (b->second_sort_key == NULL) diff --git a/src/filemanager/ext.c b/src/filemanager/ext.c index 58862216a..2bf56bf90 100644 --- a/src/filemanager/ext.c +++ b/src/filemanager/ext.c @@ -625,9 +625,6 @@ regex_check_type (const vfs_path_t * filename_vpath, const char *ptr, gboolean c /* Following variables are valid if *have_type is TRUE */ static char content_string[2048]; -#ifdef HAVE_CHARSET - static char encoding_id[21]; /* CSISO51INISCYRILLIC -- 20 */ -#endif static size_t content_shift = 0; static int got_data = 0; @@ -640,6 +637,7 @@ regex_check_type (const vfs_path_t * filename_vpath, const char *ptr, gboolean c const char *realname; /* name used with "file" */ #ifdef HAVE_CHARSET + static char encoding_id[21]; /* CSISO51INISCYRILLIC -- 20 */ int got_encoding_data; #endif /* HAVE_CHARSET */ diff --git a/src/filemanager/file.c b/src/filemanager/file.c index 83bfdef74..f2f3b631b 100644 --- a/src/filemanager/file.c +++ b/src/filemanager/file.c @@ -401,13 +401,13 @@ make_symlink (FileOpContext * ctx, const char *src_path, const char *dst_path) if (ctx->stable_symlinks && !g_path_is_absolute (link_target)) { - char *p, *s; - vfs_path_t *q; - const char *r = strrchr (src_path, PATH_SEP); if (r) { + char *p; + vfs_path_t *q; + p = g_strndup (src_path, r - src_path + 1); if (g_path_is_absolute (dst_path)) q = vfs_path_from_str_flags (dst_path, VPF_NO_CANON); @@ -416,6 +416,7 @@ make_symlink (FileOpContext * ctx, const char *src_path, const char *dst_path) if (vfs_path_tokens_count (q) > 1) { + char *s; vfs_path_t *tmp_vpath1, *tmp_vpath2; tmp_vpath1 = vfs_path_vtokens_get (q, -1, 1); @@ -1026,7 +1027,6 @@ move_file_file (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, c static FileProgressStatus erase_file (FileOpTotalContext * tctx, FileOpContext * ctx, const vfs_path_t * vpath) { - int return_status; struct stat buf; file_progress_show_deleting (ctx, vfs_path_as_str (vpath), &tctx->progress_count); @@ -1044,6 +1044,8 @@ erase_file (FileOpTotalContext * tctx, FileOpContext * ctx, const vfs_path_t * v while (mc_unlink (vpath) != 0 && !ctx->skip_all) { + int return_status; + return_status = file_error (_("Cannot delete file \"%s\"\n%s"), vfs_path_as_str (vpath)); if (return_status == FILE_ABORT) return return_status; diff --git a/src/filemanager/filegui.c b/src/filemanager/filegui.c index 7adb77f96..915bb0864 100644 --- a/src/filemanager/filegui.c +++ b/src/filemanager/filegui.c @@ -879,8 +879,6 @@ file_progress_show (FileOpContext * ctx, off_t done, off_t total, { FileOpContextUI *ui; char buffer[BUF_TINY]; - char buffer2[BUF_TINY]; - char buffer3[BUF_TINY]; if (!verbose || ctx == NULL || ctx->ui == NULL) return; @@ -901,11 +899,15 @@ file_progress_show (FileOpContext * ctx, off_t done, off_t total, if (ui->showing_eta && ctx->eta_secs > 0.5) { + char buffer2[BUF_TINY]; + file_eta_prepare_for_show (buffer2, ctx->eta_secs, FALSE); if (ctx->bps == 0) g_snprintf (buffer, BUF_TINY, "%s %s", buffer2, stalled_msg); else { + char buffer3[BUF_TINY]; + file_bps_prepare_for_show (buffer3, ctx->bps); g_snprintf (buffer, BUF_TINY, "%s (%s) %s", buffer2, buffer3, stalled_msg); } diff --git a/src/filemanager/find.c b/src/filemanager/find.c index dd56ba036..f261c0722 100644 --- a/src/filemanager/find.c +++ b/src/filemanager/find.c @@ -1810,10 +1810,11 @@ find_file (void) char *start_dir = NULL, *pattern = NULL, *content = NULL, *ignore_dirs = NULL; ssize_t start_dir_len; char *filename = NULL, *dirname = NULL; - int v; while (find_parameters (&start_dir, &start_dir_len, &ignore_dirs, &pattern, &content)) { + int v; + if (pattern[0] == '\0') break; /* nothing search */ diff --git a/src/filemanager/hotlist.c b/src/filemanager/hotlist.c index 74206cc8e..f05d0dd3e 100644 --- a/src/filemanager/hotlist.c +++ b/src/filemanager/hotlist.c @@ -1393,7 +1393,6 @@ static void clean_up_hotlist_groups (const char *section) { char *grp_section; - gchar **profile_keys, **keys; gsize len; grp_section = g_strconcat (section, ".Group", (char *) NULL); @@ -1402,6 +1401,8 @@ clean_up_hotlist_groups (const char *section) if (mc_config_has_group (mc_main_config, grp_section)) { + char **profile_keys, **keys; + profile_keys = keys = mc_config_get_keys (mc_main_config, grp_section, &len); while (*profile_keys != NULL) diff --git a/src/filemanager/layout.c b/src/filemanager/layout.c index 70503eaf8..00537a6e2 100644 --- a/src/filemanager/layout.c +++ b/src/filemanager/layout.c @@ -877,8 +877,6 @@ set_hintbar (const char *str) void rotate_dash (gboolean show) { - static const char rotating_dash[4] = "|/-\\"; - static size_t pos = 0; Widget *w = WIDGET (midnight_dlg); if (!nice_rotating_dash || (ok_to_refresh <= 0)) @@ -891,6 +889,9 @@ rotate_dash (gboolean show) tty_print_alt_char (ACS_URCORNER, FALSE); else { + static const char rotating_dash[4] = "|/-\\"; + static size_t pos = 0; + tty_print_char (rotating_dash[pos]); pos = (pos + 1) % sizeof (rotating_dash); } @@ -903,14 +904,14 @@ rotate_dash (gboolean show) const char * get_nth_panel_name (int num) { - static char buffer[BUF_SMALL]; - if (!num) return "New Left Panel"; else if (num == 1) return "New Right Panel"; else { + static char buffer[BUF_SMALL]; + g_snprintf (buffer, sizeof (buffer), "%ith Panel", num); return buffer; } diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c index 3dd8cd7dd..f3ba77495 100644 --- a/src/filemanager/midnight.c +++ b/src/filemanager/midnight.c @@ -814,13 +814,13 @@ put_prog_name (void) static void put_tagged (WPanel * panel) { - int i; - if (!command_prompt) return; input_disable_update (cmdline); if (panel->marked) { + int i; + for (i = 0; i < panel->dir.len; i++) { if (panel->dir.list[i].f.marked) diff --git a/src/filemanager/mountlist.c b/src/filemanager/mountlist.c index 2ef19817e..a3355efe7 100644 --- a/src/filemanager/mountlist.c +++ b/src/filemanager/mountlist.c @@ -621,7 +621,6 @@ read_file_system_list (int need_fs_type) #ifdef MOUNTED_LISTMNTENT { struct tabmntent *mntlist, *p; - struct mntent *mnt; struct mount_entry *me; /* the third and fourth arguments could be used to filter mounts, @@ -633,7 +632,8 @@ read_file_system_list (int need_fs_type) return NULL; for (p = mntlist; p; p = p->next) { - mnt = p->ment; + struct mntent *mnt = p->ment; + me = g_malloc (sizeof (*me)); me->me_devname = g_strdup (mnt->mnt_fsname); me->me_mountdir = g_strdup (mnt->mnt_dir); @@ -1590,13 +1590,15 @@ void my_statfs (struct my_statfs *myfs_stats, const char *path) { #ifdef HAVE_INFOMOUNT_LIST - size_t i, len = 0; + size_t len = 0; struct mount_entry *entry = NULL; struct mount_entry *temp = mc_mount_list; struct fs_usage fs_use; while (temp) { + size_t i; + i = strlen (temp->me_mountdir); if (i > len && (strncmp (path, temp->me_mountdir, i) == 0)) if (!entry || (path[i] == PATH_SEP || path[i] == '\0')) diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index 1824333ac..bac486ec0 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -1548,7 +1548,6 @@ paint_frame (WPanel * panel) Widget *w = WIDGET (panel); int side, width; - GString *format_txt; adjust_top_file (panel); @@ -1559,6 +1558,7 @@ paint_frame (WPanel * panel) for (side = 0; side <= panel->split; side++) { + GString *format_txt; format_e *format; if (side) @@ -1826,7 +1826,6 @@ use_display_format (WPanel * panel, const char *format, char **error, int isstat int expand_top = 0; /* Max used element in expand */ int usable_columns; /* Usable columns in the panel */ int total_cols = 0; - int i; format_e *darr, *home; if (!format) @@ -1856,11 +1855,12 @@ use_display_format (WPanel * panel, const char *format, char **error, int isstat /* If we used more columns than the available columns, adjust that */ if (total_cols > usable_columns) { - int pdif, dif = total_cols - usable_columns; + int dif = total_cols - usable_columns; while (dif) { - pdif = dif; + int pdif = dif; + for (darr = home; darr; darr = darr->next) { if (dif && darr->field_len - 1) @@ -1880,6 +1880,7 @@ use_display_format (WPanel * panel, const char *format, char **error, int isstat /* Expand the available space */ if ((usable_columns > total_cols) && expand_top) { + int i; int spaces = (usable_columns - total_cols) / expand_top; int extra = (usable_columns - total_cols) % expand_top; @@ -2699,7 +2700,7 @@ static void chdir_to_readlink (WPanel * panel) { vfs_path_t *new_dir_vpath; - char buffer[MC_MAXPATHLEN], *p; + char buffer[MC_MAXPATHLEN]; int i; struct stat st; vfs_path_t *panel_fname_vpath; @@ -2724,6 +2725,8 @@ chdir_to_readlink (WPanel * panel) buffer[i] = 0; if (!S_ISDIR (st.st_mode)) { + char *p; + p = strrchr (buffer, PATH_SEP); if (p && !p[1]) { @@ -3529,7 +3532,6 @@ mouse_sort_col (WPanel * panel, int x) const char *lc_sort_name = NULL; panel_field_t *col_sort_format = NULL; format_e *format; - gchar *title; for (i = 0, format = panel->format; format != NULL; format = format->next) { @@ -3547,6 +3549,8 @@ mouse_sort_col (WPanel * panel, int x) for (i = 0; panel_fields[i].id != NULL; i++) { + char *title; + title = panel_get_title_without_hotkey (panel_fields[i].title_hotkey); if (!strcmp (lc_sort_name, title) && panel_fields[i].sort_routine) { diff --git a/src/filemanager/tree.c b/src/filemanager/tree.c index 7a505a8bf..35dba51d4 100644 --- a/src/filemanager/tree.c +++ b/src/filemanager/tree.c @@ -172,14 +172,14 @@ static void save_tree (WTree * tree) { int error; - char *tree_name; (void) tree; error = tree_store_save (); - if (error) { + char *tree_name; + tree_name = mc_config_get_full_path (MC_TREESTORE_FILE); fprintf (stderr, _("Cannot open the %s file for writing:\n%s\n"), tree_name, unix_error_string (error)); diff --git a/src/filemanager/treestore.c b/src/filemanager/treestore.c index 959a8f6eb..ee0b6dae4 100644 --- a/src/filemanager/treestore.c +++ b/src/filemanager/treestore.c @@ -207,9 +207,7 @@ static int tree_store_load_from (char *name) { FILE *file; - char buffer[MC_MAXPATHLEN + 20], oldname[MC_MAXPATHLEN]; - char *different; - int common; + char buffer[MC_MAXPATHLEN + 20]; int do_load; g_return_val_if_fail (name != NULL, FALSE); @@ -239,6 +237,8 @@ tree_store_load_from (char *name) if (do_load) { + char oldname[MC_MAXPATHLEN]; + ts.loaded = TRUE; /* File open -> read contents */ @@ -264,8 +264,11 @@ tree_store_load_from (char *name) /* Clear-text decompression */ char *s = strtok (lc_name, " "); - if (s) + if (s != NULL) { + char *different; + int common; + common = atoi (s); different = strtok (NULL, ""); if (different) @@ -344,10 +347,10 @@ tree_store_save_to (char *name) current = ts.tree_first; while (current) { - int i, common; - if (vfs_file_is_local (current->name)) { + int i, common; + /* Clear-text compression */ if (current->prev && (common = str_common (current->prev->name, current->name)) > 2) { @@ -482,11 +485,11 @@ static void tree_store_notify_remove (tree_entry * entry) { hook_t *p = remove_entry_hooks; - tree_store_remove_fn r; while (p != NULL) { - r = (tree_store_remove_fn) p->hook_fn; + tree_store_remove_fn r = (tree_store_remove_fn) p->hook_fn; + r (entry, p->hook_data); p = p->next; } @@ -689,7 +692,7 @@ tree_store_remove_entry_remove_hook (tree_store_remove_fn callback) void tree_store_remove_entry (const vfs_path_t * name_vpath) { - tree_entry *current, *base, *old; + tree_entry *current, *base; size_t len; g_return_if_fail (name_vpath != NULL); @@ -715,6 +718,7 @@ tree_store_remove_entry (const vfs_path_t * name_vpath) while (current != NULL && vfs_path_equal_len (current->name, base->name, len)) { gboolean ok; + tree_entry *old; const char *cname; cname = vfs_path_as_str (current->name); @@ -859,7 +863,7 @@ tree_store_start_check (const vfs_path_t * vpath) void tree_store_end_check (void) { - tree_entry *current, *old; + tree_entry *current; size_t len; GList *the_queue; @@ -875,6 +879,7 @@ tree_store_end_check (void) while (current != NULL && vfs_path_equal_len (current->name, ts.check_name, len)) { gboolean ok; + tree_entry *old; const char *cname; cname = vfs_path_as_str (current->name); @@ -905,7 +910,6 @@ tree_entry * tree_store_rescan (const vfs_path_t * vpath) { DIR *dirp; - struct dirent *dp; struct stat buf; tree_entry *entry; @@ -923,6 +927,8 @@ tree_store_rescan (const vfs_path_t * vpath) dirp = mc_opendir (vpath); if (dirp) { + struct dirent *dp; + for (dp = mc_readdir (dirp); dp; dp = mc_readdir (dirp)) { vfs_path_t *tmp_vpath; diff --git a/src/filemanager/usermenu.c b/src/filemanager/usermenu.c index bafb1a752..b4a818b3b 100644 --- a/src/filemanager/usermenu.c +++ b/src/filemanager/usermenu.c @@ -307,15 +307,16 @@ static void debug_out (char *start, char *end, int cond) { static char *msg; - int len; if (start == NULL && end == NULL) { /* Show output */ if (debug_flag && msg) { + size_t len; + len = strlen (msg); - if (len) + if (len != 0) msg[len - 1] = 0; message (D_NORMAL, _("Debug"), "%s", msg); @@ -361,11 +362,12 @@ test_line (WEdit * edit_widget, char *p, int *result) { int condition; char operator; - char *debug_start, *debug_end; /* Repeat till end of line */ while (*p && *p != '\n') { + char *debug_start, *debug_end; + /* support quote space .mnu */ while ((*p == ' ' && *(p - 1) != '\\') || *p == '\t') p++; @@ -473,7 +475,6 @@ execute_menu_command (WEdit * edit_widget, const char *commands, gboolean show_p { if (*commands == '}') { - char *tmp; *parameter = 0; parameter = input_dialog (_("Parameter"), lc_prompt, MC_HISTORY_FM_MENU_EXEC_PARAM, "", @@ -490,6 +491,8 @@ execute_menu_command (WEdit * edit_widget, const char *commands, gboolean show_p } if (do_quote) { + char *tmp; + tmp = name_quote (parameter, 0); fputs (tmp, cmd_file); g_free (tmp); @@ -689,12 +692,13 @@ check_format_var (const char *p, char **v) { const char *q = p; char *var_name; - const char *value; - const char *dots = 0; - *v = 0; + *v = NULL; if (!strncmp (p, "var{", 4)) { + const char *dots = NULL; + const char *value; + for (q += 4; *q && *q != '}'; q++) { if (*q == ':') @@ -925,7 +929,6 @@ user_menu_cmd (struct WEdit * edit_widget, const char *menu_file, int selected_e int max_cols, menu_lines, menu_limit; int col, i, accept_entry = 1; int selected, old_patterns; - Listbox *listbox; gboolean res = FALSE; gboolean interactive = TRUE; @@ -1093,6 +1096,8 @@ user_menu_cmd (struct WEdit * edit_widget, const char *menu_file, int selected_e selected = selected_entry; else { + Listbox *listbox; + max_cols = min (max (max_cols, col), MAX_ENTRY_LEN); /* Create listbox */ diff --git a/src/help.c b/src/help.c index b374f42fd..326a1465b 100644 --- a/src/help.c +++ b/src/help.c @@ -296,9 +296,7 @@ move_to_bottom (void) static const char * help_follow_link (const char *start, const char *lc_selected_item) { - char link_name[MAXLINKNAME]; const char *p; - int i = 0; if (lc_selected_item == NULL) return start; @@ -307,6 +305,9 @@ help_follow_link (const char *start, const char *lc_selected_item) ; if (*p == CHAR_LINK_POINTER) { + int i; + char link_name[MAXLINKNAME]; + link_name[0] = '['; for (i = 1; *p != CHAR_LINK_END && *p && *p != CHAR_NODE_END && i < MAXLINKNAME - 3;) link_name[i++] = *++p; diff --git a/src/main.c b/src/main.c index 8938ad628..c6c7d9788 100644 --- a/src/main.c +++ b/src/main.c @@ -453,9 +453,10 @@ main (int argc, char *argv[]) if (macros_list != NULL) { guint i; - macros_t *macros; for (i = 0; i < macros_list->len; i++) { + macros_t *macros; + macros = &g_array_index (macros_list, struct macros_t, i); if (macros != NULL && macros->macro != NULL) (void) g_array_free (macros->macro, FALSE); diff --git a/src/setup.c b/src/setup.c index 7d2d9f5e3..b1ff58d1f 100644 --- a/src/setup.c +++ b/src/setup.c @@ -510,7 +510,6 @@ setup__move_panels_config_into_separate_file (const char *profile) { mc_config_t *tmp_cfg; char **groups, **curr_grp; - const char *need_grp; if (!exist_file (profile)) return; @@ -547,6 +546,8 @@ setup__move_panels_config_into_separate_file (const char *profile) while (*curr_grp) { + const char *need_grp; + need_grp = setup__is_cfg_group_must_panel_config (*curr_grp); if (need_grp != NULL) { diff --git a/src/subshell.c b/src/subshell.c index aaff5dbfe..dbee58175 100644 --- a/src/subshell.c +++ b/src/subshell.c @@ -184,10 +184,12 @@ static struct termios raw_mode; static ssize_t write_all (int fd, const void *buf, size_t count) { - ssize_t ret; ssize_t written = 0; + while (count > 0) { + ssize_t ret; + ret = write (fd, (const unsigned char *) buf + written, count); if (ret < 0) { @@ -471,7 +473,6 @@ static gboolean feed_subshell (int how, int fail_on_error) { fd_set read_set; /* For 'select' */ - int maxfdp; int bytes; /* For the return value from 'read' */ int i; /* Loop counter */ @@ -485,6 +486,8 @@ feed_subshell (int how, int fail_on_error) while (TRUE) { + int maxfdp; + if (!subshell_alive) return FALSE; diff --git a/src/vfs/fish/fish.c b/src/vfs/fish/fish.c index 6d86535cb..6378fce68 100644 --- a/src/vfs/fish/fish.c +++ b/src/vfs/fish/fish.c @@ -384,12 +384,12 @@ fish_set_env (int flags) static gboolean fish_info (struct vfs_class *me, struct vfs_s_super *super) { - char buffer[BUF_8K]; if (fish_command (me, super, NONE, SUP->scr_info) == COMPLETE) { while (TRUE) { int res; + char buffer[BUF_8K]; res = vfs_s_get_line_interruptible (me, buffer, sizeof (buffer), SUP->sockr); if ((res == 0) || (res == EINTR)) diff --git a/src/vfs/ftpfs/ftpfs.c b/src/vfs/ftpfs/ftpfs.c index c043b3a5e..939c6f3b4 100644 --- a/src/vfs/ftpfs/ftpfs.c +++ b/src/vfs/ftpfs/ftpfs.c @@ -697,23 +697,27 @@ static void ftpfs_load_no_proxy_list (void) { /* FixMe: shouldn't be hardcoded!!! */ - char s[BUF_LARGE]; /* provide for BUF_LARGE characters */ - FILE *npf; - int c; - char *p; static char *mc_file = NULL; mc_file = g_build_filename (mc_global.sysconfig_dir, "mc.no_proxy", (char *) NULL); if (exist_file (mc_file)) { + FILE *npf; + npf = fopen (mc_file, "r"); if (npf != NULL) { + char s[BUF_LARGE]; /* provide for BUF_LARGE characters */ + while (fgets (s, sizeof (s), npf) != NULL) { + char *p; + p = strchr (s, '\n'); if (p == NULL) /* skip bogus entries */ { + int c; + while ((c = fgetc (npf)) != EOF && c != '\n') ; continue; @@ -1409,7 +1413,6 @@ ftpfs_linear_abort (struct vfs_class *me, vfs_file_handler_t * fh) struct vfs_s_super *super = FH_SUPER; static unsigned char const ipbuf[3] = { IAC, IP, IAC }; fd_set mask; - char buf[BUF_8K]; int dsock = FH_SOCK; FH_SOCK = -1; SUP->ctl_connection_busy = 0; @@ -1437,6 +1440,8 @@ ftpfs_linear_abort (struct vfs_class *me, vfs_file_handler_t * fh) if (select (dsock + 1, &mask, NULL, NULL, NULL) > 0) { struct timeval start_tim, tim; + char buf[BUF_8K]; + gettimeofday (&start_tim, NULL); /* flush the remaining data */ while (read (dsock, buf, sizeof (buf)) > 0) @@ -2310,11 +2315,12 @@ ftpfs_netrc_next (void) static int ftpfs_netrc_bad_mode (const char *netrcname) { - static int be_angry = 1; struct stat mystat; if (stat (netrcname, &mystat) >= 0 && (mystat.st_mode & 077)) { + static int be_angry = 1; + if (be_angry) { message (D_ERROR, MSG_ERROR, @@ -2404,7 +2410,6 @@ ftpfs_netrc_lookup (const char *host, char **login, char **pass) char *tmp_pass = NULL; char hostname[MAXHOSTNAMELEN]; const char *domain; - keyword_t keyword; static struct rupcache { struct rupcache *next; @@ -2456,6 +2461,8 @@ ftpfs_netrc_lookup (const char *host, char **login, char **pass) /* Scan for keywords following "default" and "machine" */ while (1) { + keyword_t keyword; + int need_break = 0; keyword = ftpfs_netrc_next (); diff --git a/src/vfs/sfs/sfs.c b/src/vfs/sfs/sfs.c index bd98ff72a..1947cc36c 100644 --- a/src/vfs/sfs/sfs.c +++ b/src/vfs/sfs/sfs.c @@ -129,7 +129,7 @@ sfs_vfmake (const vfs_path_t * vpath, vfs_path_t * cache_vpath) char pad[10240]; char *s_iter, *t = pad; int was_percent = 0; - vfs_path_t *pname, *s; /* name of parent archive */ + vfs_path_t *pname; /* name of parent archive */ char *pqname; /* name of parent archive, quoted */ const vfs_path_element_t *path_element; @@ -150,6 +150,8 @@ sfs_vfmake (const vfs_path_t * vpath, vfs_path_t * cache_vpath) /* if ((sfs_flags[w] & F_2) || (!inpath) || (!*inpath)); else return -1; */ if ((sfs_flags[w] & F_NOLOCALCOPY) == 0) { + vfs_path_t *s; + s = mc_getlocalcopy (pname); if (s == NULL) { diff --git a/src/vfs/tar/tar.c b/src/vfs/tar/tar.c index e1e59013c..b43fd4bf3 100644 --- a/src/vfs/tar/tar.c +++ b/src/vfs/tar/tar.c @@ -754,7 +754,6 @@ tar_open_archive (struct vfs_s_super *archive, const vfs_path_t * vpath, { /* Initial status at start of archive */ ReadStatus status = STATUS_EOFMARK; - ReadStatus prev_status; int tard; current_tar_position = 0; @@ -766,8 +765,8 @@ tar_open_archive (struct vfs_s_super *archive, const vfs_path_t * vpath, while (TRUE) { size_t h_size; + ReadStatus prev_status = status; - prev_status = status; status = tar_read_header (vpath_element->class, archive, tard, &h_size); switch (status) diff --git a/src/viewer/display.c b/src/viewer/display.c index 5168ef82b..ed3ed2afc 100644 --- a/src/viewer/display.c +++ b/src/viewer/display.c @@ -148,13 +148,13 @@ mcview_display_status (mcview_t * view) if (width > 40) { - char buffer[BUF_TRUNC_LEN + 1]; - widget_move (view, top, width - 32); if (view->hex_mode) tty_printf ("0x%08" PRIxMAX, (uintmax_t) view->hex_cursor); else { + char buffer[BUF_TRUNC_LEN + 1]; + size_trunc_len (buffer, BUF_TRUNC_LEN, mcview_get_filesize (view), 0, panels_options.kilobyte_si); tty_printf ("%9" PRIuMAX "/%s%s %s", (uintmax_t) view->dpy_end, diff --git a/src/viewer/growbuf.c b/src/viewer/growbuf.c index 64ccc9f77..0f0688fba 100644 --- a/src/viewer/growbuf.c +++ b/src/viewer/growbuf.c @@ -113,8 +113,6 @@ void mcview_growbuf_read_until (mcview_t * view, off_t ofs) { ssize_t nread; - byte *p; - size_t bytesfree; gboolean short_read; #ifdef HAVE_ASSERT_H @@ -127,6 +125,9 @@ mcview_growbuf_read_until (mcview_t * view, off_t ofs) short_read = FALSE; while (mcview_growbuf_filesize (view) < ofs || short_read) { + byte *p; + size_t bytesfree; + if (view->growbuf_lastindex == VIEW_PAGE_SIZE) { /* Append a new block to the growing buffer */ diff --git a/src/viewer/hex.c b/src/viewer/hex.c index b126d7ce6..26ecee901 100644 --- a/src/viewer/hex.c +++ b/src/viewer/hex.c @@ -3,7 +3,7 @@ Function for hex view Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, - 2004, 2005, 2006, 2007, 2009, 2011 + 2004, 2005, 2006, 2007, 2009, 2011, 2013 The Free Software Foundation, Inc. Written by: @@ -14,7 +14,7 @@ Norbert Warmuth, 1997 Pavel Machek, 1998 Roland Illig , 2004, 2005 - Slava Zanko , 2009 + Slava Zanko , 2009, 2013 Andrew Borodin , 2009 Ilia Maslakov , 2009 @@ -129,7 +129,7 @@ mcview_display_hex (mcview_t * view) * text column. */ - screen_dimen row, col; + screen_dimen row; off_t from; int c; mark_t boldflag = MARK_NORMAL; @@ -152,7 +152,9 @@ mcview_display_hex (mcview_t * view) for (row = 0; mcview_get_byte (view, from, NULL) == TRUE && row < height; row++) { + screen_dimen col = 0; size_t i; + col = 0; /* Print the hex offset */ @@ -173,17 +175,22 @@ mcview_display_hex (mcview_t * view) #ifdef HAVE_CHARSET if (view->utf8) { - char corr_buf[UTF8_CHAR_LEN + 1]; - int cnt, cw = 1; + int cw = 1; gboolean read_res = TRUE; + ch = mcview_get_utf (view, from, &cw, &read_res); if (!read_res) break; /* char width is greater 0 bytes */ if (cw != 0) { + int cnt; + char corr_buf[UTF8_CHAR_LEN + 1]; struct hexedit_change_node *corr = curr; - int res = g_unichar_to_utf8 (ch, (char *) corr_buf); + int res; + + res = g_unichar_to_utf8 (ch, (char *) corr_buf); + for (cnt = 0; cnt < cw; cnt++) { if (curr != NULL && from + cnt == curr->offset)