From b6d46039be75bd2b868ee6c32b091a1e37720a20 Mon Sep 17 00:00:00 2001 From: rbuj Date: Sun, 19 Dec 2021 23:34:14 +0100 Subject: Fix some -Wsign-compare warnings --- eel/eel-gtk-extensions.c | 10 +++++--- libcaja-private/caja-debug-log.c | 2 +- libcaja-private/caja-desktop-metadata.c | 2 +- libcaja-private/caja-file-operations.c | 44 +++++++++++++++++---------------- libcaja-private/caja-file.c | 4 +-- libcaja-private/caja-query.c | 5 ---- src/caja-application.c | 3 ++- src/caja-connect-server-dialog.c | 23 +++++++++++------ src/caja-file-management-properties.c | 6 ++--- src/caja-image-properties-page.c | 2 +- src/caja-navigation-window.c | 10 ++++---- src/caja-places-sidebar.c | 11 +++++---- src/caja-query-editor.c | 8 +++--- src/caja-window.c | 2 +- src/file-manager/fm-directory-view.c | 4 +-- src/file-manager/fm-properties-window.c | 2 +- 16 files changed, 75 insertions(+), 63 deletions(-) diff --git a/eel/eel-gtk-extensions.c b/eel/eel-gtk-extensions.c index b2a47d95..2218b02b 100644 --- a/eel/eel-gtk-extensions.c +++ b/eel/eel-gtk-extensions.c @@ -115,21 +115,25 @@ static void sanity_check_window_dimensions (guint *width, guint *height) { GdkScreen *screen; - gint scale; + int screen_width; + int screen_height; + int scale; g_assert (width != NULL); g_assert (height != NULL); screen = gdk_screen_get_default (); scale = gdk_window_get_scale_factor (gdk_screen_get_root_window (screen)); + screen_width = WidthOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale; + screen_height = HeightOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale; /* Pin the size of the window to the screen, so we don't end up in * a state where the window is so big essential parts of it can't * be reached (might not be necessary with all window managers, * but seems reasonable anyway). */ - *width = MIN (*width, WidthOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale); - *height = MIN (*height, HeightOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale); + *width = MIN (*width, (guint) screen_width); + *height = MIN (*height, (guint) screen_height); } /** diff --git a/libcaja-private/caja-debug-log.c b/libcaja-private/caja-debug-log.c index d872f91d..a7594757 100644 --- a/libcaja-private/caja-debug-log.c +++ b/libcaja-private/caja-debug-log.c @@ -358,7 +358,7 @@ caja_debug_log_load_configuration (const char *filename, GError **error) g_error_free (my_error); else { - int i; + gsize i; for (i = 0; i < num_strings; i++) strings[i] = g_strstrip (strings[i]); diff --git a/libcaja-private/caja-desktop-metadata.c b/libcaja-private/caja-desktop-metadata.c index fd3bf08e..7fad726f 100644 --- a/libcaja-private/caja-desktop-metadata.c +++ b/libcaja-private/caja-desktop-metadata.c @@ -240,7 +240,7 @@ caja_desktop_update_metadata_from_keyfile (CajaFile *file, gsize length, values_length; GKeyFile *keyfile; GFileInfo *info; - gint idx; + gsize idx; gboolean res; keyfile = get_keyfile (); diff --git a/libcaja-private/caja-file-operations.c b/libcaja-private/caja-file-operations.c index e82fe259..60193d47 100644 --- a/libcaja-private/caja-file-operations.c +++ b/libcaja-private/caja-file-operations.c @@ -376,7 +376,7 @@ get_link_name (const char *name, int count, int max_length) { const char *format; char *result; - int unshortened_length; + size_t unshortened_length; gboolean use_count; g_assert (name != NULL); @@ -444,10 +444,10 @@ get_link_name (const char *name, int count, int max_length) else result = g_strdup_printf (format, name); - if (max_length > 0 && (unshortened_length = strlen (result)) > max_length) { + if (max_length > 0 && (unshortened_length = strlen (result)) > (size_t) max_length) { char *new_name; - new_name = shorten_utf8_string (name, unshortened_length - max_length); + new_name = shorten_utf8_string (name, ((int) unshortened_length) - max_length); if (new_name) { g_free (result); @@ -456,7 +456,7 @@ get_link_name (const char *name, int count, int max_length) else result = g_strdup_printf (format, new_name); - g_assert (strlen (result) <= max_length); + g_assert (strlen (result) <= (size_t) max_length); g_free (new_name); } } @@ -655,7 +655,7 @@ make_next_duplicate_name (const char *base, const char *suffix, int count, int m { const char *format; char *result; - int unshortened_length; + size_t unshortened_length; gboolean use_count; if (count < 1) { @@ -733,10 +733,10 @@ make_next_duplicate_name (const char *base, const char *suffix, int count, int m else result = g_strdup_printf (format, base, suffix); - if (max_length > 0 && (unshortened_length = strlen (result)) > max_length) { + if (max_length > 0 && (unshortened_length = strlen (result)) > (size_t) max_length) { char *new_base; - new_base = shorten_utf8_string (base, unshortened_length - max_length); + new_base = shorten_utf8_string (base, ((int) unshortened_length) - max_length); if (new_base) { g_free (result); @@ -745,7 +745,7 @@ make_next_duplicate_name (const char *base, const char *suffix, int count, int m else result = g_strdup_printf (format, new_base, suffix); - g_assert (strlen (result) <= max_length); + g_assert (strlen (result) <= (size_t) max_length); g_free (new_base); } } @@ -1778,7 +1778,7 @@ delete_file (CommonJob *job, GFile *file, } static void -delete_files (CommonJob *job, GList *files, int *files_skipped) +delete_files (CommonJob *job, GList *files, guint *files_skipped) { GList *l; SourceInfo source_info; @@ -1821,10 +1821,10 @@ delete_files (CommonJob *job, GList *files, int *files_skipped) static void report_trash_progress (CommonJob *job, - int files_trashed, - int total_files) + guint files_trashed, + guint total_files) { - int files_left; + guint files_left; char *s; files_left = total_files - files_trashed; @@ -1844,13 +1844,13 @@ report_trash_progress (CommonJob *job, } static void -trash_files (CommonJob *job, GList *files, int *files_skipped) +trash_files (CommonJob *job, GList *files, guint *files_skipped) { GList *l; GFile *file; GList *to_delete; GError *error; - int total_files, files_trashed; + guint total_files, files_trashed; char *primary, *secondary, *details; int response; @@ -1978,7 +1978,7 @@ delete_job (GIOSchedulerJob *io_job, gboolean must_confirm_delete_in_trash; gboolean must_confirm_delete; gboolean must_confirm_trash; - int files_skipped; + guint files_skipped; GFile *file = NULL; common = (CommonJob *)job; @@ -2923,11 +2923,11 @@ verify_destination (CommonJob *job, free_size = g_file_info_get_attribute_uint64 (fsinfo, G_FILE_ATTRIBUTE_FILESYSTEM_FREE); - if (free_size < required_size) { + if (free_size < (guint64) required_size) { primary = f (_("Error while copying to \"%B\"."), dest); secondary = f(_("There is not enough space on the destination. Try to remove files to make space.")); - details = f (_("There is %S available, but %S is required."), free_size, required_size); + details = f (_("There is %" G_GUINT64_FORMAT " available, but %" G_GOFFSET_FORMAT " is required."), free_size, required_size); response = run_warning (job, primary, @@ -3174,7 +3174,7 @@ make_file_name_valid_for_dest_fs (char *filename, !strcmp (dest_fs_type, "msdos") || !strcmp (dest_fs_type, "msdosfs")) { gboolean ret; - int i, old_len; + size_t i, old_len; ret = str_replace (filename, FAT_FORBIDDEN_CHARACTERS, '_'); @@ -6134,11 +6134,13 @@ create_job (GIOSchedulerJob *io_job, if (count == 1) { new_filename = g_strdup (filename); } else if (job->make_dir) { - filename2 = g_strdup_printf ("%s %d", filename, count); + size_t unshortened_length; + filename2 = g_strdup_printf ("%s %d", filename, count); + unshortened_length = strlen (filename2); new_filename = NULL; - if (max_length > 0 && strlen (filename2) > max_length) { - new_filename = shorten_utf8_string (filename2, strlen (filename2) - max_length); + if (max_length > 0 && unshortened_length > (size_t) max_length) { + new_filename = shorten_utf8_string (filename2, ((int) unshortened_length) - max_length); } if (new_filename == NULL) { diff --git a/libcaja-private/caja-file.c b/libcaja-private/caja-file.c index a5ed4ff9..27856bf7 100644 --- a/libcaja-private/caja-file.c +++ b/libcaja-private/caja-file.c @@ -6254,9 +6254,9 @@ caja_file_get_size_as_string (CajaFile *file, } if (g_settings_get_boolean (caja_preferences, CAJA_PREFERENCES_USE_IEC_UNITS)) - return g_format_size_full (size, G_FORMAT_SIZE_IEC_UNITS); + return g_format_size_full ((guint64) size, G_FORMAT_SIZE_IEC_UNITS); else - return g_format_size (size); + return g_format_size ((guint64) size); } /** diff --git a/libcaja-private/caja-query.c b/libcaja-private/caja-query.c index d0902652..ddeb8d24 100644 --- a/libcaja-private/caja-query.c +++ b/libcaja-private/caja-query.c @@ -335,11 +335,6 @@ caja_query_parse_xml (char *xml, gsize xml_len) ParserInfo info = { NULL }; GMarkupParseContext *ctx; - if (xml_len == -1) - { - xml_len = strlen (xml); - } - info.query = caja_query_new (); info.in_text = FALSE; diff --git a/src/caja-application.c b/src/caja-application.c index 8f920108..c000b27f 100644 --- a/src/caja-application.c +++ b/src/caja-application.c @@ -283,6 +283,7 @@ open_tabs (CajaApplication *application, CajaApplication *self = CAJA_APPLICATION (application); CajaWindow *window; gchar *uri = NULL; + guint i; /* monitor the preference to use browser or spatial windows */ /* connect before trying to read or this preference won't be read by root or after change */ @@ -307,7 +308,7 @@ open_tabs (CajaApplication *application, g_debug ("Opening new tab at uri %s\n", uri); caja_window_go_to (window, locations[0]); g_free (uri); - for (int i = 1; i< n_files;i++) { + for (i = 1; i < n_files; i++) { /* open tabs in reverse order because each * tab is opened before the previous one */ guint tab = n_files-i; diff --git a/src/caja-connect-server-dialog.c b/src/caja-connect-server-dialog.c index d97bcb0a..66b2001a 100644 --- a/src/caja-connect-server-dialog.c +++ b/src/caja-connect-server-dialog.c @@ -92,6 +92,12 @@ enum RESPONSE_CONNECT }; +enum { + COL_TYPE_COMBO_INDEX = 0, + COL_TYPE_COMBO_DESCRIPTION, + COL_TYPE_COMBO_NUM +}; + struct MethodInfo { const char *scheme; @@ -532,7 +538,7 @@ connect_dialog_connect_to_server (CajaConnectServerDialog *dialog) gtk_combo_box_get_active_iter (GTK_COMBO_BOX (dialog->details->type_combo), &iter); gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (dialog->details->type_combo)), &iter, 0, &index, -1); - g_assert (index < G_N_ELEMENTS (methods) && index >= 0); + g_assert (index >= 0 && ((gsize) index) < G_N_ELEMENTS (methods)); meth = &(methods[index]); server = gtk_editable_get_chars (GTK_EDITABLE (dialog->details->server_entry), 0, -1); @@ -778,7 +784,7 @@ connect_dialog_setup_for_type (CajaConnectServerDialog *dialog) gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (dialog->details->type_combo)), &iter, 0, &index, -1); - g_assert (index < G_N_ELEMENTS (methods) && index >= 0); + g_assert (index >= 0 && ((gsize) index) < G_N_ELEMENTS (methods)); meth = &(methods[index]); g_object_set (dialog->details->share_entry, @@ -847,7 +853,7 @@ caja_connect_server_dialog_init (CajaConnectServerDialog *dialog) GtkListStore *store; GtkCellRenderer *renderer; gchar *str; - int i; + gsize i; dialog->details = caja_connect_server_dialog_get_instance_private (dialog); @@ -932,13 +938,16 @@ caja_connect_server_dialog_init (CajaConnectServerDialog *dialog) dialog->details->type_combo = combo = gtk_combo_box_new (); /* each row contains: method index, textual description */ - store = gtk_list_store_new (2, G_TYPE_INT, G_TYPE_STRING); + store = gtk_list_store_new (COL_TYPE_COMBO_NUM, + G_TYPE_INT, /* COL_TYPE_COMBO_INDEX */ + G_TYPE_STRING); /* COL_TYPE_COMBO_DESCRIPTION */ gtk_combo_box_set_model (GTK_COMBO_BOX (combo), GTK_TREE_MODEL (store)); g_object_unref (store); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE); - gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo), renderer, "text", 1); + gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo), renderer, "text", + COL_TYPE_COMBO_DESCRIPTION); for (i = 0; i < G_N_ELEMENTS (methods); i++) { @@ -971,8 +980,8 @@ caja_connect_server_dialog_init (CajaConnectServerDialog *dialog) gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, - 0, i, - 1, get_method_description (&(methods[i])), + COL_TYPE_COMBO_INDEX, (int) i, + COL_TYPE_COMBO_DESCRIPTION, get_method_description (&(methods[i])), -1); if (methods[i].flags & DEFAULT_METHOD) diff --git a/src/caja-file-management-properties.c b/src/caja-file-management-properties.c index a01e058a..ba76ebda 100644 --- a/src/caja-file-management-properties.c +++ b/src/caja-file-management-properties.c @@ -384,7 +384,7 @@ update_caption_combo_box (GtkBuilder *builder, const char *name) { GtkWidget *combo_box; - int i; + guint i; GPtrArray *column_names; combo_box = GTK_WIDGET (gtk_builder_get_object (builder, combo_box_name)); @@ -401,7 +401,7 @@ update_caption_combo_box (GtkBuilder *builder, { if (!strcmp (name, g_ptr_array_index (column_names, i))) { - gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), i); + gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), (int) i); break; } } @@ -842,7 +842,7 @@ caja_file_management_properties_dialog_setup_extension_page (GtkBuilder *builder gchar *ext_text_info; GList *extensions; - int i; + guint i; extensions = caja_extensions_get_list (); diff --git a/src/caja-image-properties-page.c b/src/caja-image-properties-page.c index afb66c9e..344f8339 100644 --- a/src/caja-image-properties-page.c +++ b/src/caja-image-properties-page.c @@ -472,7 +472,7 @@ file_read_callback (GObject *object, { int exif_still_loading; - g_assert (count_read <= sizeof(page->details->buffer)); + g_assert (((size_t) count_read) <= sizeof (page->details->buffer)); #ifdef HAVE_EXIF exif_still_loading = exif_loader_write (page->details->exifldr, diff --git a/src/caja-navigation-window.c b/src/caja-navigation-window.c index 0768d326..0cdbb1dd 100644 --- a/src/caja-navigation-window.c +++ b/src/caja-navigation-window.c @@ -519,7 +519,7 @@ caja_navigation_window_key_press_event (GtkWidget *widget, GdkEventKey *event) { CajaNavigationWindow *window; - int i; + gsize i; window = CAJA_NAVIGATION_WINDOW (widget); @@ -604,12 +604,12 @@ caja_navigation_window_button_press_event (GtkWidget *widget, handled = FALSE; window = CAJA_NAVIGATION_WINDOW (widget); - if (mouse_extra_buttons && (event->button == mouse_back_button)) + if (mouse_extra_buttons && (((int) event->button) == mouse_back_button)) { caja_navigation_window_go_back (window); handled = TRUE; } - else if (mouse_extra_buttons && (event->button == mouse_forward_button)) + else if (mouse_extra_buttons && (((int) event->button) == mouse_forward_button)) { caja_navigation_window_go_forward (window); handled = TRUE; @@ -1082,7 +1082,7 @@ gint caja_navigation_window_get_base_page_index (CajaNavigationWindow *window) { CajaNavigationWindowSlot *slot; - gint forward_count; + guint forward_count; slot = CAJA_NAVIGATION_WINDOW_SLOT (CAJA_WINDOW (window)->details->active_pane->active_slot); @@ -1097,7 +1097,7 @@ caja_navigation_window_get_base_page_index (CajaNavigationWindow *window) /* The forward count indicate the relative postion of the base page * in the history list */ - return forward_count; + return (int) forward_count; } /** diff --git a/src/caja-places-sidebar.c b/src/caja-places-sidebar.c index 2cd22148..d0ef6ee8 100644 --- a/src/caja-places-sidebar.c +++ b/src/caja-places-sidebar.c @@ -1461,6 +1461,7 @@ reorder_bookmarks (CajaPlacesSidebar *sidebar, GtkTreeIter iter; PlaceType type; int old_position; + guint list_length; /* Get the selected path */ @@ -1472,12 +1473,12 @@ reorder_bookmarks (CajaPlacesSidebar *sidebar, PLACES_SIDEBAR_COLUMN_INDEX, &old_position, -1); - if (type != PLACES_BOOKMARK || - old_position < 0 || - old_position >= caja_bookmark_list_length (sidebar->bookmarks)) - { + if (type != PLACES_BOOKMARK || old_position < 0) + return; + + list_length = caja_bookmark_list_length (sidebar->bookmarks); + if (((guint) old_position) >= list_length) return; - } caja_bookmark_list_move_item (sidebar->bookmarks, old_position, new_position); diff --git a/src/caja-query-editor.c b/src/caja-query-editor.c index 2c600c5d..b4f96179 100644 --- a/src/caja-query-editor.c +++ b/src/caja-query-editor.c @@ -468,7 +468,7 @@ tags_row_add_to_query (CajaQueryEditorRow *row, char **strv = g_strsplit (tags, " ", -1); guint len = g_strv_length (strv); - int i; + guint i; for (i = 0; i < len; ++i) { strv[i] = g_strstrip (strv[i]); @@ -839,7 +839,7 @@ type_row_create_widgets (CajaQueryEditorRow *row) GtkCellRenderer *cell; GtkListStore *store; GtkTreeIter iter; - int i; + gsize i; store = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_BOOLEAN); combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store)); @@ -993,7 +993,7 @@ type_add_rows_from_query (CajaQueryEditor *editor, char *mime_type; CajaQueryEditorRow *row; GtkTreeIter iter; - int i; + gsize i; GtkTreeModel *model; GList *l; @@ -1017,7 +1017,7 @@ type_add_rows_from_query (CajaQueryEditor *editor, model = gtk_combo_box_get_model (GTK_COMBO_BOX (row->type_widget)); - gtk_tree_model_iter_nth_child (model, &iter, NULL, i + 2); + gtk_tree_model_iter_nth_child (model, &iter, NULL, ((gint) i) + 2); gtk_combo_box_set_active_iter (GTK_COMBO_BOX (row->type_widget), &iter); } diff --git a/src/caja-window.c b/src/caja-window.c index a180414c..2417e07c 100644 --- a/src/caja-window.c +++ b/src/caja-window.c @@ -1073,7 +1073,7 @@ caja_window_key_press_event (GtkWidget *widget, return TRUE; CajaWindow *window; - int i; + gsize i; window = CAJA_WINDOW (widget); diff --git a/src/file-manager/fm-directory-view.c b/src/file-manager/fm-directory-view.c index ddaa334c..c76eefba 100644 --- a/src/file-manager/fm-directory-view.c +++ b/src/file-manager/fm-directory-view.c @@ -2351,9 +2351,9 @@ fm_directory_view_display_selection_info (FMDirectoryView *view) char *size_string; if (g_settings_get_boolean (caja_preferences, CAJA_PREFERENCES_USE_IEC_UNITS)) - size_string = g_format_size_full (non_folder_size, G_FORMAT_SIZE_IEC_UNITS); + size_string = g_format_size_full ((guint64) non_folder_size, G_FORMAT_SIZE_IEC_UNITS); else - size_string = g_format_size(non_folder_size); + size_string = g_format_size ((guint64) non_folder_size); /* Translators: This is marked for translation in case a localiser * needs to use something other than parentheses. The diff --git a/src/file-manager/fm-properties-window.c b/src/file-manager/fm-properties-window.c index 0ab2bfc7..2b38788d 100644 --- a/src/file-manager/fm-properties-window.c +++ b/src/file-manager/fm-properties-window.c @@ -4139,7 +4139,7 @@ permission_combo_update (FMPropertiesWindow *window, int current_perm; gtk_tree_model_get (model, &iter, 1, ¤t_perm, -1); - if (current_perm == all_perm) { + if (((PermissionValue) current_perm) == all_perm) { found = TRUE; break; } -- cgit v1.2.1