From 6cefb6d3bbb4d9b1e5832533d5237ebb591a0ed6 Mon Sep 17 00:00:00 2001 From: Roland Illig Date: Mon, 16 Aug 2004 03:12:05 +0000 Subject: [PATCH] Made the data type of some variables more appropriate. --- edit/edit.c | 22 ++++++++++++---------- edit/editcmd.c | 12 ++++++------ src/background.c | 4 ++-- src/color.c | 7 ++++--- src/command.c | 2 +- src/ext.c | 2 +- src/file.c | 6 +++--- src/hotlist.c | 12 ++++++------ src/layout.c | 2 +- src/menu.c | 4 ++-- src/slint.c | 2 +- src/util.c | 6 +++--- 12 files changed, 42 insertions(+), 39 deletions(-) diff --git a/edit/edit.c b/edit/edit.c index b91a22d09..b39f79cae 100644 --- a/edit/edit.c +++ b/edit/edit.c @@ -192,12 +192,11 @@ static const struct edit_filters { /* Return index of the filter or -1 is there is no appropriate filter */ static int edit_find_filter (const char *filename) { - int i, l; + size_t i, l, e; if (!filename) return -1; l = strlen (filename); - for (i = 0; i < sizeof (all_filters) / sizeof (struct edit_filters); i++) { - int e; + for (i = 0; i < sizeof (all_filters) / sizeof (all_filters[0]); i++) { e = strlen (all_filters[i].extension); if (l > e) if (!strcmp (all_filters[i].extension, filename + l - e)) @@ -511,8 +510,8 @@ edit_init (WEdit *edit, int lines, int columns, const char *filename, static char option_whole_chars_search_buf[256]; if (option_whole_chars_search_buf != option_whole_chars_search) { - int i; - int len = strlen (option_whole_chars_search); + size_t i; + size_t len = strlen (option_whole_chars_search); strcpy (option_whole_chars_search_buf, option_whole_chars_search); @@ -701,7 +700,7 @@ void edit_push_action (WEdit * edit, long c,...) if (sp > edit->stack_size - 10) { /* say */ if (option_max_undo < 256) option_max_undo = 256; - if (edit->stack_size < option_max_undo) { + if (edit->stack_size < (unsigned long) option_max_undo) { t = g_realloc (edit->undo_stack, (edit->stack_size * 2 + 10) * sizeof (long)); if (t) { edit->undo_stack = t; @@ -770,9 +769,12 @@ void edit_push_action (WEdit * edit, long c,...) edit->stack_pointer = (edit->stack_pointer + 1) & edit->stack_size_mask; -/*if the sp wraps round and catches the stack_bottom then erase the first set of actions on the stack to make space - by moving stack_bottom forward one "key press" */ + /* if the sp wraps round and catches the stack_bottom then erase + * the first set of actions on the stack to make space - by moving + * stack_bottom forward one "key press" */ c = (edit->stack_pointer + 2) & edit->stack_size_mask; - if (c == edit->stack_bottom || ((c + 1) & edit->stack_size_mask) == edit->stack_bottom) + if ((unsigned long) c == edit->stack_bottom || + (((unsigned long) c + 1) & edit->stack_size_mask) == edit->stack_bottom) do { edit->stack_bottom = (edit->stack_bottom + 1) & edit->stack_size_mask; } while (edit->undo_stack[edit->stack_bottom] < KEY_PRESS && edit->stack_bottom != edit->stack_pointer); @@ -1297,7 +1299,7 @@ void edit_update_curs_col (WEdit * edit) /*moves the display start position up by i lines */ void edit_scroll_upward (WEdit * edit, unsigned long i) { - int lines_above = edit->start_line; + unsigned long lines_above = edit->start_line; if (i > lines_above) i = lines_above; if (i) { @@ -1380,7 +1382,7 @@ edit_move_to_prev_col (WEdit * edit, long p) /* move i lines */ void edit_move_up (WEdit * edit, unsigned long i, int scroll) { - long p, l = edit->curs_line; + unsigned long p, l = edit->curs_line; if (i > l) i = l; diff --git a/edit/editcmd.c b/edit/editcmd.c index 5d45dcfc1..f0b34001b 100644 --- a/edit/editcmd.c +++ b/edit/editcmd.c @@ -165,7 +165,7 @@ char *catstrs (const char *first,...) /* Free temporary strings */ void freestrs(void) { - int i; + size_t i; for (i = 0; i < sizeof(stacked) / sizeof(stacked[0]); i++) { g_free (stacked[i]); @@ -394,10 +394,10 @@ void menu_save_mode_cmd (void) static int i18n_flag = 0; if (!i18n_flag) { - int i; - int maxlen = 0; + size_t i; + size_t maxlen = 0; int dlg_x; - int l1; + size_t l1; /* OK/Cancel buttons */ l1 = strlen (_(widgets[0].text)) + strlen (_(widgets[1].text)) + 5; @@ -2726,8 +2726,8 @@ edit_completion_dialog (WEdit *edit, int max_len, int word_len, char *curr = NULL; Dlg_head *compl_dlg; WListbox *compl_list; - unsigned int compl_dlg_h; /* completion dialog height */ - unsigned int compl_dlg_w; /* completion dialog width */ + int compl_dlg_h; /* completion dialog height */ + int compl_dlg_w; /* completion dialog width */ /* calculate the dialog metrics */ compl_dlg_h = num_compl + 2; diff --git a/src/background.c b/src/background.c index 9aff2b49d..d834712b1 100644 --- a/src/background.c +++ b/src/background.c @@ -195,13 +195,13 @@ background_attention (int fd, void *closure) void *routine; int argc, i, result, status; char *data [MAXCALLARGS]; - int bytes; + ssize_t bytes; enum ReturnType type; ctx = closure; bytes = read (fd, &routine, sizeof (routine)); - if (bytes < (sizeof (routine))) { + if (bytes == -1 || (size_t) bytes < (sizeof (routine))) { char *background_process_error = _(" Background process error "); unregister_task_running (ctx->pid, fd); diff --git a/src/color.c b/src/color.c index e91d400cc..aa0938b31 100644 --- a/src/color.c +++ b/src/color.c @@ -168,7 +168,7 @@ static char *default_colors = static void get_color (char *cpp, CTYPE *colp) { - int i; + size_t i; for (i = 0; i < ELEMENTS(color_table); i++){ if (strcmp (cpp, color_name (i)) == 0){ @@ -208,7 +208,8 @@ static void get_two_colors (char **cpp, struct colorpair *colorpairp) static void configure_colors_string (char *the_color_string) { char *color_string, *p; - int i, found; + size_t i; + int found; if (!the_color_string) return; @@ -274,7 +275,7 @@ load_dialog_colors (void) void init_colors (void) { - int i; + size_t i; int hascolors; diff --git a/src/command.c b/src/command.c index 071f895b1..af28f46e1 100644 --- a/src/command.c +++ b/src/command.c @@ -202,7 +202,7 @@ enter (WInput *cmdline) return MSG_HANDLED; } else { char *command, *s; - int i, j; + size_t i, j; if (!vfs_current_is_local ()) { message (1, MSG_ERROR, diff --git a/src/ext.c b/src/ext.c index 4a007cb3e..b028a2327 100644 --- a/src/ext.c +++ b/src/ext.c @@ -131,7 +131,7 @@ exec_extension (const char *filename, const char *data, int *move_dir, written_nonspace = 1; g_free (parameter); } else { - int len = strlen (prompt); + size_t len = strlen (prompt); if (len < sizeof (prompt) - 1) { prompt[len] = *data; diff --git a/src/file.c b/src/file.c index a3f77f7b5..94b0423eb 100644 --- a/src/file.c +++ b/src/file.c @@ -163,7 +163,7 @@ static int transform_error = 0; static unsigned char * do_transform_source (FileOpContext *ctx, unsigned char *source) { - int j, k, l, len; + size_t j, k, l, len; unsigned char *fnsource = x_basename (source); int next_reg; enum CaseConvs case_conv = NO_CONV; @@ -218,8 +218,8 @@ do_transform_source (FileOpContext *ctx, unsigned char *source) transform_error = FILE_ABORT; return NULL; } - for (l = ctx->regs.start[next_reg]; - l < ctx->regs.end[next_reg]; l++) + for (l = (size_t) ctx->regs.start[next_reg]; + l < (size_t) ctx->regs.end[next_reg]; l++) fntarget[k++] = convert_case (fnsource[l], &case_conv); next_reg++; break; diff --git a/src/hotlist.c b/src/hotlist.c index d242e9ccc..e8f3fcca7 100644 --- a/src/hotlist.c +++ b/src/hotlist.c @@ -593,7 +593,7 @@ init_i18n_stuff(int list_type, int cols) static void init_hotlist (int list_type) { - int i; + size_t i; char *title, *help_node; int hotlist_cols; @@ -664,7 +664,7 @@ init_hotlist (int list_type) static void init_movelist (int list_type, struct hotlist *item) { - int i; + size_t i; char *hdr = g_strdup_printf (_("Moving %s"), item->label); int movelist_cols = init_i18n_stuff (list_type, COLS - 6); @@ -843,7 +843,7 @@ static int add_new_entry_input (char *header, char *text1, char *text2, char *he 0, 0, "label-lbl" }, NULL_QuickWidget }; - int len; + size_t len; int i; int lines1, lines2; char *my_str1, *my_str2; @@ -852,8 +852,8 @@ static int add_new_entry_input (char *header, char *text1, char *text2, char *he static int i18n_flag = 0; #endif /* ENABLE_NLS */ - len = max (strlen (header), msglen (text1, &lines1)); - len = max (len, msglen (text2, &lines2)) + 4; + len = max (strlen (header), (size_t) msglen (text1, &lines1)); + len = max (len, (size_t) msglen (text2, &lines2)) + 4; len = max (len, 64); #ifdef ENABLE_NLS @@ -943,7 +943,7 @@ static int add_new_group_input (char *header, char *label, char **result) static int i18n_flag = 0; #endif /* ENABLE_NLS */ - len = max (strlen (header), msglen (label, &lines)) + 4; + len = max (strlen (header), (size_t) msglen (label, &lines)) + 4; len = max (len, 64); #ifdef ENABLE_NLS diff --git a/src/layout.c b/src/layout.c index 8c841f176..7877b9c54 100644 --- a/src/layout.c +++ b/src/layout.c @@ -852,7 +852,7 @@ void print_vfs_message (char *msg, ...) void rotate_dash (void) { static const char rotating_dash [] = "|/-\\"; - static int pos = 0; + static size_t pos = 0; if (!nice_rotating_dash || (ok_to_refresh <= 0)) return; diff --git a/src/menu.c b/src/menu.c index 3bb63e181..9e76a617f 100644 --- a/src/menu.c +++ b/src/menu.c @@ -67,10 +67,10 @@ create_menu (char *name, menu_entry *entries, int count, char *help_node) if (cp != NULL && *(cp+1) != '\0') { mp->hot_key = tolower (*(cp+1)); - menu->max_entry_len = max (strlen (mp->text) - 1, + menu->max_entry_len = max ((int) (strlen (mp->text) - 1), menu->max_entry_len); } else { - menu->max_entry_len = max (strlen (mp->text), + menu->max_entry_len = max ((int) strlen (mp->text), menu->max_entry_len); } } diff --git a/src/slint.c b/src/slint.c index be926f057..62c09c6ec 100644 --- a/src/slint.c +++ b/src/slint.c @@ -361,7 +361,7 @@ int has_colors (void) { char *terminal = getenv ("TERM"); char *cts = color_terminal_string, *s; - int i; + size_t i; if (force_colors) SLtt_Use_Ansi_Colors = 1; diff --git a/src/util.c b/src/util.c index 54cca0159..efd937d41 100644 --- a/src/util.c +++ b/src/util.c @@ -217,7 +217,7 @@ name_trunc (const char *txt, int trunc_len) int txt_len; char *p; - if (trunc_len > sizeof (x) - 1) { + if ((size_t) trunc_len > sizeof (x) - 1) { trunc_len = sizeof (x) - 1; } txt_len = strlen (txt); @@ -410,7 +410,7 @@ strip_password (char *p, int has_prefix) {"/#smb:", 6}, }; char *at, *inner_colon, *dir; - int i; + size_t i; char *result = p; for (i = 0; i < sizeof (prefixes)/sizeof (prefixes[0]); i++) { @@ -719,7 +719,7 @@ char *extract_line (char *s, char *top) static char tmp_line [BUF_MEDIUM]; char *t = tmp_line; - while (*s && *s != '\n' && (t - tmp_line) < sizeof (tmp_line)-1 && s < top) + while (*s && *s != '\n' && (size_t) (t - tmp_line) < sizeof (tmp_line)-1 && s < top) *t++ = *s++; *t = 0; return tmp_line;