From b25889293ea20ccc23ea37b1474ecbcaec9c65a3 Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Sat, 3 Feb 2024 14:48:24 +0000 Subject: [PATCH] clang-tidy: readability-else-after-return - Fix warnings identified by this flag - Remove the exclude from .clang-tidy file --- .clang-tidy | 1 - scripts/lua-test.sh | 2 +- src/bar-gps.cc | 12 ++--- src/cache-maint.cc | 4 +- src/collect-io.cc | 10 ++-- src/collect.cc | 11 +++-- src/color-man.cc | 32 ++++++------- src/dupe.cc | 54 ++++++++------------- src/exif-common.cc | 6 +-- src/filedata.cc | 13 +++--- src/image-load-gdk.cc | 7 ++- src/image-load-heif.cc | 58 +++++++++++------------ src/image-load-psd.cc | 37 +++++++++------ src/image-load-tiff.cc | 14 +++--- src/image-overlay.cc | 14 +++--- src/image.cc | 10 ++-- src/jpeg-parser.cc | 8 ++-- src/layout.cc | 3 +- src/lua.cc | 19 ++++---- src/metadata.cc | 40 +++++++--------- src/misc.cc | 4 +- src/osd.cc | 6 +-- src/pan-view/pan-view-filter.cc | 12 ++--- src/preferences.cc | 3 +- src/print.cc | 6 +-- src/remote.cc | 3 +- src/renderer-tiles.cc | 4 +- src/search.cc | 8 ++-- src/slideshow.cc | 4 +- src/ui-fileops.cc | 3 +- src/ui-misc.cc | 20 ++++---- src/ui-tabcomp.cc | 83 ++++++++++++++++----------------- src/view-dir-tree.cc | 23 ++++----- src/view-dir.cc | 6 +-- src/view-file/view-file.cc | 10 ++-- src/zonedetect.cc | 8 ++-- 36 files changed, 254 insertions(+), 304 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index af037ae4..94f0a7b6 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -46,7 +46,6 @@ Checks: > -modernize-use-trailing-return-type, -performance-no-int-to-ptr, -readability-braces-around-statements, - -readability-else-after-return, -readability-function-cognitive-complexity, -readability-identifier-length, -readability-implicit-bool-conversion, diff --git a/scripts/lua-test.sh b/scripts/lua-test.sh index 29bc31b8..4e1feb50 100755 --- a/scripts/lua-test.sh +++ b/scripts/lua-test.sh @@ -26,7 +26,7 @@ ## ## Create a basic image and run all lua built-in functions on it. ## The image file and the Lua test file are created within this script. -set -x + if [ -z "$XDG_CONFIG_HOME" ] then config_home="$HOME/.config" diff --git a/src/bar-gps.cc b/src/bar-gps.cc index a0d29513..203fa292 100644 --- a/src/bar-gps.cc +++ b/src/bar-gps.cc @@ -872,12 +872,14 @@ static gboolean bar_pane_gps_map_keypress_cb(GtkWidget *, GdkEventButton *bevent gtk_menu_popup_at_pointer(GTK_MENU(menu), nullptr); return TRUE; } - else if (bevent->button == MOUSE_BUTTON_MIDDLE) + + if (bevent->button == MOUSE_BUTTON_MIDDLE) { bar_pane_gps_map_centreing(pgd); return TRUE; } - else if (bevent->button == MOUSE_BUTTON_LEFT) + + if (bevent->button == MOUSE_BUTTON_LEFT) { clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); geo_coords = g_strdup_printf("%lf %lf", @@ -891,10 +893,8 @@ static gboolean bar_pane_gps_map_keypress_cb(GtkWidget *, GdkEventButton *bevent return TRUE; } - else - { - return FALSE; - } + + return FALSE; } #endif diff --git a/src/cache-maint.cc b/src/cache-maint.cc index f73236d4..f7cf7c49 100644 --- a/src/cache-maint.cc +++ b/src/cache-maint.cc @@ -765,7 +765,7 @@ static gboolean cache_manager_render_file(CacheOpsData *cd) return (!success); } - else if (cd->list_dir) + if (cd->list_dir) { FileData *fd; @@ -1434,7 +1434,7 @@ static gboolean cache_manager_sim_file(CacheOpsData *cd) return FALSE; } - else if (cd->list_dir) + if (cd->list_dir) { FileData *fd; diff --git a/src/collect-io.cc b/src/collect-io.cc index e0c1933b..40937343 100644 --- a/src/collect-io.cc +++ b/src/collect-io.cc @@ -194,12 +194,10 @@ static gboolean collection_load_private(CollectionData *cd, const gchar *path, C g_string_append(extended_filename_buffer, buf); continue; } - else - { - /* end of extended filename found */ - g_string_append_len(extended_filename_buffer, buf, p - buf); - reading_extended_filename = FALSE; - } + + /* end of extended filename found */ + g_string_append_len(extended_filename_buffer, buf, p - buf); + reading_extended_filename = FALSE; } if (extended_filename_buffer->len > 0) diff --git a/src/collect.cc b/src/collect.cc index 61bea6d8..e3fd8202 100644 --- a/src/collect.cc +++ b/src/collect.cc @@ -180,8 +180,8 @@ static gint collection_list_sort_cb(gconstpointer a, gconstpointer b) if (options->file_sort.case_sensitive) return strcmp(cia->fd->collate_key_name, cib->fd->collate_key_name); - else - return strcmp(cia->fd->collate_key_name_nocase, cib->fd->collate_key_name_nocase); + + return strcmp(cia->fd->collate_key_name_nocase, cib->fd->collate_key_name_nocase); } GList *collection_list_sort(GList *list, SortType method) @@ -575,8 +575,8 @@ CollectionData *collection_from_dnd_data(const gchar *data, GList **list, GList while (*ptr != '\n' && *ptr != '\0') ptr++; if (*ptr == '\0') break; - else - while (*ptr == '\n') ptr++; + + while (*ptr == '\n') ptr++; info = static_cast(g_list_nth_data(cd->list, item_number)); if (!info) continue; @@ -1191,7 +1191,8 @@ static void collection_close_save_cb(GenericDialog *gd, gpointer data) collection_dialog_save_close(cw->cd); return; } - else if (!collection_save(cw->cd, cw->cd->path)) + + if (!collection_save(cw->cd, cw->cd->path)) { gchar *buf; buf = g_strdup_printf(_("Failed to save the collection:\n%s"), cw->cd->path); diff --git a/src/color-man.cc b/src/color-man.cc index e9be69bd..63dacd45 100644 --- a/src/color-man.cc +++ b/src/color-man.cc @@ -724,16 +724,12 @@ static guchar *nclx_to_lcms_profile(const struct heif_color_profile_nclx *nclx, cmsCloseProfile(profile); return static_cast(data); } - else - { - cmsCloseProfile(profile); - return nullptr; - } - } - else - { + + cmsCloseProfile(profile); return nullptr; } + + return nullptr; } guchar *heif_color_profile(FileData *fd, guint *profile_len) @@ -788,20 +784,18 @@ guchar *heif_color_profile(FileData *fd, guint *profile_len) return static_cast(data); } - else - { - error_code = heif_image_handle_get_nclx_color_profile(handle, &nclxcp); - if (error_code.code) - { - log_printf("warning: heif reader error: %s\n", error_code.message); - heif_context_free(ctx); - heif_nclx_color_profile_free(nclxcp); - return nullptr; - } - profile = nclx_to_lcms_profile(nclxcp, profile_len); + error_code = heif_image_handle_get_nclx_color_profile(handle, &nclxcp); + if (error_code.code) + { + log_printf("warning: heif reader error: %s\n", error_code.message); + heif_context_free(ctx); + heif_nclx_color_profile_free(nclxcp); + return nullptr; } + profile = nclx_to_lcms_profile(nclxcp, profile_len); + heif_context_free(ctx); heif_nclx_color_profile_free(nclxcp); diff --git a/src/dupe.cc b/src/dupe.cc index 71373479..f03ed75f 100644 --- a/src/dupe.cc +++ b/src/dupe.cc @@ -351,7 +351,8 @@ static void dupe_window_update_progress(DupeWindow *dw, const gchar *status, gdo return; } - else if (force || + + if (force || value == 0.0 || dw->setup_count == 0 || dw->setup_time_count == 0 || @@ -1509,15 +1510,10 @@ static gboolean dupe_match(DupeItem *a, DupeItem *b, DupeMatchType mask, gdouble { return TRUE; } - else - { - return FALSE; - } - } - else - { + return FALSE; } + return FALSE; } if (mask & DUPE_MATCH_NAME_CI_CONTENT) { @@ -1531,15 +1527,11 @@ static gboolean dupe_match(DupeItem *a, DupeItem *b, DupeMatchType mask, gdouble { return TRUE; } - else - { - return FALSE; - } - } - else - { + return FALSE; } + return FALSE; + } if (mask & DUPE_MATCH_SIZE) { @@ -1817,10 +1809,8 @@ static gint dupe_match_sort_cb(gconstpointer a, gconstpointer b, gpointer data) { return -1; } - else - { - return strcmp(di1->md5sum, di2->md5sum); - } + + return strcmp(di1->md5sum, di2->md5sum); } if (mask & DUPE_MATCH_DIM) { @@ -2813,14 +2803,12 @@ static gboolean dupe_files_add_queue_cb(gpointer data) { return TRUE; } - else - { - dw->add_files_queue_id = 0; - dupe_destroy_list_cache(dw); - g_idle_add(dupe_check_start_cb, dw); - gtk_widget_set_sensitive(dw->controls_box, TRUE); - return FALSE; - } + + dw->add_files_queue_id = 0; + dupe_destroy_list_cache(dw); + g_idle_add(dupe_check_start_cb, dw); + gtk_widget_set_sensitive(dw->controls_box, TRUE); + return FALSE; } static void dupe_files_add(DupeWindow *dw, CollectionData *, CollectInfo *info, @@ -2881,10 +2869,8 @@ static void dupe_files_add(DupeWindow *dw, CollectionData *, CollectInfo *info, { return; } - else - { - work = work->next; - } + + work = work->next; } if (dw->second_list) @@ -2897,10 +2883,8 @@ static void dupe_files_add(DupeWindow *dw, CollectionData *, CollectInfo *info, { return; } - else - { - work = work->next; - } + + work = work->next; } } diff --git a/src/exif-common.cc b/src/exif-common.cc index 1fcfb6ac..8ebc3796 100644 --- a/src/exif-common.cc +++ b/src/exif-common.cc @@ -1213,10 +1213,8 @@ gchar *metadata_file_info(FileData *fd, const gchar *key, MetadataFormat) page_n_of_m = g_strdup_printf("[%d/%d]", fd->page_num + 1, fd->page_total); return page_n_of_m; } - else - { - return nullptr; - } + + return nullptr; } return g_strdup(""); } diff --git a/src/filedata.cc b/src/filedata.cc index c990c27c..5e032c7d 100644 --- a/src/filedata.cc +++ b/src/filedata.cc @@ -332,7 +332,8 @@ static void file_data_set_path(FileData *fd, const gchar *path) file_data_set_collate_keys(fd); return; } - else if (strcmp(fd->name, ".") == 0) + + if (strcmp(fd->name, ".") == 0) { g_free(fd->path); fd->path = remove_level_from_path(path); @@ -2965,11 +2966,11 @@ static gboolean file_data_perform_delete(FileData *fd) { if (isdir(fd->path) && !islink(fd->path)) return rmdir_utf8(fd->path); - else - if (options->file_ops.safe_delete_enable) - return file_util_safe_unlink(fd->path); - else - return unlink_file(fd->path); + + if (options->file_ops.safe_delete_enable) + return file_util_safe_unlink(fd->path); + + return unlink_file(fd->path); } gboolean file_data_perform_ci(FileData *fd) diff --git a/src/image-load-gdk.cc b/src/image-load-gdk.cc index 62e0f331..f532e682 100644 --- a/src/image-load-gdk.cc +++ b/src/image-load-gdk.cc @@ -35,11 +35,10 @@ static gchar* image_loader_gdk_get_format_name(gpointer loader) { return gdk_pixbuf_format_get_name(format); } - else - { - return nullptr; - } + + return nullptr; } + static gchar** image_loader_gdk_get_format_mime_types(gpointer loader) { return gdk_pixbuf_format_get_mime_types(gdk_pixbuf_loader_get_format(GDK_PIXBUF_LOADER(loader))); diff --git a/src/image-load-heif.cc b/src/image-load-heif.cc index 0996aff6..5abc3c5f 100644 --- a/src/image-load-heif.cc +++ b/src/image-load-heif.cc @@ -66,44 +66,42 @@ static gboolean image_loader_heif_load(gpointer loader, const guchar *buf, gsize heif_context_free(ctx); return FALSE; } - else - { - page_total = heif_context_get_number_of_top_level_images(ctx); - ld->page_total = page_total; - std::vector IDs(page_total); + page_total = heif_context_get_number_of_top_level_images(ctx); + ld->page_total = page_total; + + std::vector IDs(page_total); - /* get list of all (top level) image IDs */ - heif_context_get_list_of_top_level_image_IDs(ctx, IDs.data(), page_total); + /* get list of all (top level) image IDs */ + heif_context_get_list_of_top_level_image_IDs(ctx, IDs.data(), page_total); - error_code = heif_context_get_image_handle(ctx, IDs[ld->page_num], &handle); - if (error_code.code) - { - log_printf("warning: heif reader error: %s\n", error_code.message); - heif_context_free(ctx); - return FALSE; - } + error_code = heif_context_get_image_handle(ctx, IDs[ld->page_num], &handle); + if (error_code.code) + { + log_printf("warning: heif reader error: %s\n", error_code.message); + heif_context_free(ctx); + return FALSE; + } - // decode the image and convert colorspace to RGB, saved as 24bit interleaved - error_code = heif_decode_image(handle, &img, heif_colorspace_RGB, heif_chroma_interleaved_24bit, nullptr); - if (error_code.code) - { - log_printf("warning: heif reader error: %s\n", error_code.message); - heif_context_free(ctx); - return FALSE; - } + // decode the image and convert colorspace to RGB, saved as 24bit interleaved + error_code = heif_decode_image(handle, &img, heif_colorspace_RGB, heif_chroma_interleaved_24bit, nullptr); + if (error_code.code) + { + log_printf("warning: heif reader error: %s\n", error_code.message); + heif_context_free(ctx); + return FALSE; + } - data = heif_image_get_plane(img, heif_channel_interleaved, &stride); + data = heif_image_get_plane(img, heif_channel_interleaved, &stride); - height = heif_image_get_height(img,heif_channel_interleaved); - width = heif_image_get_width(img,heif_channel_interleaved); - alpha = heif_image_handle_has_alpha_channel(handle); - heif_image_handle_release(handle); + height = heif_image_get_height(img,heif_channel_interleaved); + width = heif_image_get_width(img,heif_channel_interleaved); + alpha = heif_image_handle_has_alpha_channel(handle); + heif_image_handle_release(handle); - ld->pixbuf = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, alpha, 8, width, height, stride, free_buffer, img); + ld->pixbuf = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, alpha, 8, width, height, stride, free_buffer, img); - ld->area_updated_cb(loader, 0, 0, width, height, ld->data); - } + ld->area_updated_cb(loader, 0, 0, width, height, ld->data); heif_context_free(ctx); diff --git a/src/image-load-psd.cc b/src/image-load-psd.cc index 114f5bd1..a26cef22 100644 --- a/src/image-load-psd.cc +++ b/src/image-load-psd.cc @@ -213,16 +213,18 @@ skip_block (PsdContext* context, const guchar** data, guint* size) return FALSE; } } - if (*size < context->bytes_to_skip) { + + if (*size < context->bytes_to_skip) + { *data += *size; context->bytes_to_skip -= *size; *size = 0; return FALSE; - } else { - *size -= context->bytes_to_skip; - *data += context->bytes_to_skip; - return TRUE; - } + } + + *size -= context->bytes_to_skip; + *data += context->bytes_to_skip; + return TRUE; } /* @@ -233,33 +235,42 @@ decompress_line(const guchar* src, guint line_length, guchar* dest) { guint16 bytes_read = 0; int k; - while (bytes_read < line_length) { + while (bytes_read < line_length) + { gchar byte = src[bytes_read]; ++bytes_read; - if (byte == -128) { + if (byte == -128) + { continue; - } else if (byte > -1) { + } + + if (byte > -1) + { gint count = byte + 1; /* copy next count bytes */ - for (k = 0; k < count; ++k) { + for (k = 0; k < count; ++k) + { *dest = src[bytes_read]; ++dest; ++bytes_read; + } } - } else { + else + { gint count = -byte + 1; /* copy next byte count times */ guchar next_byte = src[bytes_read]; ++bytes_read; - for (k = 0; k < count; ++k) { + for (k = 0; k < count; ++k) + { *dest = next_byte; ++dest; + } } } - } } static void diff --git a/src/image-load-tiff.cc b/src/image-load-tiff.cc index 2148af00..2195fb3c 100644 --- a/src/image-load-tiff.cc +++ b/src/image-load-tiff.cc @@ -163,14 +163,12 @@ static gboolean image_loader_tiff_load (gpointer loader, const guchar *buf, gsiz DEBUG_1("Failed to open TIFF image"); return FALSE; } - else - { - do - { - dircount++; - } while (TIFFReadDirectory(tiff)); - lt->page_total = dircount; - } + + do { + dircount++; + } while (TIFFReadDirectory(tiff)); + + lt->page_total = dircount; if (!TIFFSetDirectory(tiff, lt->page_num)) { diff --git a/src/image-overlay.cc b/src/image-overlay.cc index 83976d8b..1883637f 100644 --- a/src/image-overlay.cc +++ b/src/image-overlay.cc @@ -210,16 +210,14 @@ void image_osd_toggle(ImageWindow *imd) image_osd_set(imd, static_cast(OSD_SHOW_INFO | OSD_SHOW_STATUS)); return; } + + if (show & OSD_SHOW_HISTOGRAM) + { + image_osd_set(imd, OSD_SHOW_NOTHING); + } else { - if (show & OSD_SHOW_HISTOGRAM) - { - image_osd_set(imd, OSD_SHOW_NOTHING); - } - else - { - image_osd_set(imd, static_cast(show | OSD_SHOW_HISTOGRAM)); - } + image_osd_set(imd, static_cast(show | OSD_SHOW_HISTOGRAM)); } } diff --git a/src/image.cc b/src/image.cc index 3bf37dbd..e6682618 100644 --- a/src/image.cc +++ b/src/image.cc @@ -985,7 +985,7 @@ static gboolean image_read_ahead_check(ImageWindow *imd) imd->read_ahead_fd = nullptr; return TRUE; } - else if (imd->read_ahead_fd->pixbuf) + if (imd->read_ahead_fd->pixbuf) { image_change_pixbuf(imd, imd->read_ahead_fd->pixbuf, image_zoom_get(imd), FALSE); @@ -1216,11 +1216,9 @@ static gboolean image_scroll_cb(GtkWidget *, GdkEventScroll *event, gpointer dat } return TRUE; } - else - { - imd->func_scroll(imd, event, imd->data_scroll); - return TRUE; - } + + imd->func_scroll(imd, event, imd->data_scroll); + return TRUE; } return FALSE; diff --git a/src/jpeg-parser.cc b/src/jpeg-parser.cc index f7e8f455..96e0b3d5 100644 --- a/src/jpeg-parser.cc +++ b/src/jpeg-parser.cc @@ -81,8 +81,8 @@ guint16 tiff_byte_get_int16(const guchar *f, TiffByteOrder bo) if (bo == TIFF_BYTE_ORDER_INTEL) return GUINT16_FROM_LE(align_buf); - else - return GUINT16_FROM_BE(align_buf); + + return GUINT16_FROM_BE(align_buf); } guint32 tiff_byte_get_int32(const guchar *f, TiffByteOrder bo) @@ -93,8 +93,8 @@ guint32 tiff_byte_get_int32(const guchar *f, TiffByteOrder bo) if (bo == TIFF_BYTE_ORDER_INTEL) return GUINT32_FROM_LE(align_buf); - else - return GUINT32_FROM_BE(align_buf); + + return GUINT32_FROM_BE(align_buf); } #pragma GCC diagnostic push diff --git a/src/layout.cc b/src/layout.cc index 588ef14c..a3353b59 100644 --- a/src/layout.cc +++ b/src/layout.cc @@ -1860,7 +1860,8 @@ static void layout_grid_setup(LayoutWindow *lw) return; } - else if (lw->tools) + + if (lw->tools) { layout_tools_geometry_sync(lw); gq_gtk_widget_destroy(lw->tools); diff --git a/src/lua.cc b/src/lua.cc index b03b048d..5279a2a6 100644 --- a/src/lua.cc +++ b/src/lua.cc @@ -259,13 +259,12 @@ static int lua_exif_get_datum(lua_State *L) lua_pushnumber(L, datetime); return 1; } - else - { - lua_pushnil(L); - return 1; - } + + lua_pushnil(L); + return 1; } - else if (strcmp(key, "Exif.Photo.DateTimeDigitized") == 0) + + if (strcmp(key, "Exif.Photo.DateTimeDigitized") == 0) { memset(&tm, 0, sizeof(tm)); if (value && strptime(value, "%Y:%m:%d %H:%M:%S", &tm)) @@ -274,11 +273,9 @@ static int lua_exif_get_datum(lua_State *L) lua_pushnumber(L, datetime); return 1; } - else - { - lua_pushnil(L); - return 1; - } + + lua_pushnil(L); + return 1; } lua_pushstring(L, value); return 1; diff --git a/src/metadata.cc b/src/metadata.cc index 84f319fe..06f17931 100644 --- a/src/metadata.cc +++ b/src/metadata.cc @@ -845,14 +845,12 @@ gboolean metadata_append_string(FileData *fd, const gchar *key, const char *valu { return metadata_write_string(fd, key, value); } - else - { - gchar *new_string = g_strconcat(str, value, NULL); - gboolean ret = metadata_write_string(fd, key, new_string); - g_free(str); - g_free(new_string); - return ret; - } + + gchar *new_string = g_strconcat(str, value, NULL); + gboolean ret = metadata_write_string(fd, key, new_string); + g_free(str); + g_free(new_string); + return ret; } gboolean metadata_write_GPS_coord(FileData *fd, const gchar *key, gdouble value) @@ -916,16 +914,14 @@ gboolean metadata_append_list(FileData *fd, const gchar *key, const GList *value { return metadata_write_list(fd, key, values); } - else - { - gboolean ret; - list = g_list_concat(list, string_list_copy(values)); - list = remove_duplicate_strings_from_list(list); - ret = metadata_write_list(fd, key, list); - g_list_free_full(list, g_free); - return ret; - } + gboolean ret; + list = g_list_concat(list, string_list_copy(values)); + list = remove_duplicate_strings_from_list(list); + + ret = metadata_write_list(fd, key, list); + g_list_free_full(list, g_free); + return ret; } /** @@ -997,8 +993,8 @@ gchar *find_string_in_list(GList *list, const gchar *string) { if (options->metadata.keywords_case_sensitive) return find_string_in_list_utf8case(list, string); - else - return find_string_in_list_utf8nocase(list, string); + + return find_string_in_list_utf8nocase(list, string); } #define KEYWORDS_SEPARATOR(c) ((c) == ',' || (c) == ';' || (c) == '\n' || (c) == '\r' || (c) == '\b') @@ -1205,10 +1201,8 @@ gboolean keyword_same_parent(GtkTreeModel *keyword_tree, GtkTreeIter *a, GtkTree { return keyword_compare(keyword_tree, &parent_a, &parent_b) == 0; } - else - { - return (!valid_pa && !valid_pb); /* both are toplevel */ - } + + return (!valid_pa && !valid_pb); /* both are toplevel */ } gboolean keyword_exists(GtkTreeModel *keyword_tree, GtkTreeIter *parent_ptr, GtkTreeIter *sibling, const gchar *name, gboolean exclude_sibling, GtkTreeIter *result) diff --git a/src/misc.cc b/src/misc.cc index cb1dddfd..053efbfc 100644 --- a/src/misc.cc +++ b/src/misc.cc @@ -126,8 +126,8 @@ gchar *expand_tilde(const gchar *filename) if (slash) return g_build_filename(home, G_DIR_SEPARATOR_S, slash + 1, NULL); - else - return g_build_filename(home, G_DIR_SEPARATOR_S, NULL); + + return g_build_filename(home, G_DIR_SEPARATOR_S, NULL); #endif } diff --git a/src/osd.cc b/src/osd.cc index e0074d91..9a03b46e 100644 --- a/src/osd.cc +++ b/src/osd.cc @@ -459,10 +459,8 @@ void osd_template_insert(GHashTable *vars, const gchar *keyword, const gchar *va g_hash_table_insert(vars, const_cast(keyword), const_cast(value)); return; } - else - { - g_hash_table_insert(vars, const_cast(keyword), g_strdup(value)); - } + + g_hash_table_insert(vars, const_cast(keyword), g_strdup(value)); if (flags & OSDT_FREE) g_free(const_cast(value)); } diff --git a/src/pan-view/pan-view-filter.cc b/src/pan-view/pan-view-filter.cc index d715a89d..35ff1958 100644 --- a/src/pan-view/pan-view-filter.cc +++ b/src/pan-view/pan-view-filter.cc @@ -319,13 +319,11 @@ static gboolean pan_view_list_contains_kw_pattern(GList *haystack, PanViewFilter } return FALSE; } - else - { - // regex compile failed; fall back to exact string match. - GList *found_elem = g_list_find_custom(haystack, filter->keyword, reinterpret_cast(g_strcmp0)); - if (found_elem && found_kw) *found_kw = static_cast(found_elem->data); - return !!found_elem; - } + + // regex compile failed; fall back to exact string match. + GList *found_elem = g_list_find_custom(haystack, filter->keyword, reinterpret_cast(g_strcmp0)); + if (found_elem && found_kw) *found_kw = static_cast(found_elem->data); + return !!found_elem; } gboolean pan_filter_fd_list(GList **fd_list, GList *filter_elements, gint filter_classes) diff --git a/src/preferences.cc b/src/preferences.cc index 8dd98fef..ce9b73d6 100644 --- a/src/preferences.cc +++ b/src/preferences.cc @@ -3095,7 +3095,8 @@ static gboolean keywords_find_file(gpointer data) return (G_SOURCE_CONTINUE); } - else if (kfd->list_dir) + + if (kfd->list_dir) { FileData *fd; diff --git a/src/print.cc b/src/print.cc index 323cb63c..90739433 100644 --- a/src/print.cc +++ b/src/print.cc @@ -485,10 +485,8 @@ static gboolean paginate_cb(GtkPrintOperation *, GtkPrintContext *, gpointer dat { return TRUE; } - else - { - return FALSE; - } + + return FALSE; } gchar *form_image_text(const gchar *template_string, FileData *fd, PrintWindow *pw, gint page_nr, gint total) diff --git a/src/remote.cc b/src/remote.cc index d333256a..451b5be4 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -1755,7 +1755,8 @@ static RemoteCommandEntry *remote_command_find(const gchar *text, const gchar ** if (offset) *offset = text + strlen(remote_commands[i].opt_s); return &remote_commands[i]; } - else if (remote_commands[i].opt_l && + + if (remote_commands[i].opt_l && strncmp(remote_commands[i].opt_l, text, strlen(remote_commands[i].opt_l)) == 0) { if (offset) *offset = text + strlen(remote_commands[i].opt_l); diff --git a/src/renderer-tiles.cc b/src/renderer-tiles.cc index 40d8dc0f..9a3fb814 100644 --- a/src/renderer-tiles.cc +++ b/src/renderer-tiles.cc @@ -1928,8 +1928,7 @@ static void rt_scroll(void *renderer, gint x_off, gint y_off) rt_queue(rt, 0, 0, pr->width, pr->height, TRUE, TILE_RENDER_ALL, FALSE, FALSE); return; } - else - { + gint x1, y1; gint x2, y2; cairo_t *cr; @@ -1991,7 +1990,6 @@ static void rt_scroll(void *renderer, gint x_off, gint y_off) rt->x_scroll, y_off > 0 ? rt->y_scroll + (pr->vis_height - h) : rt->y_scroll, pr->vis_width, h, TRUE, TILE_RENDER_ALL, FALSE, FALSE); } - } } static void renderer_area_changed(void *renderer, gint src_x, gint src_y, gint src_w, gint src_h) diff --git a/src/search.cc b/src/search.cc index 4947948b..f35cd431 100644 --- a/src/search.cc +++ b/src/search.cc @@ -1841,11 +1841,9 @@ static gboolean search_file_do_extra(SearchData *sd, FileData *fd, gint *match, { return TRUE; } - else - { - image_loader_free(sd->img_loader); - sd->img_loader = nullptr; - } + + image_loader_free(sd->img_loader); + sd->img_loader = nullptr; } } diff --git a/src/slideshow.cc b/src/slideshow.cc index 0cf242df..924e1c61 100644 --- a/src/slideshow.cc +++ b/src/slideshow.cc @@ -178,8 +178,8 @@ gboolean slideshow_should_continue(SlideShowData *ss) { if (g_list_length(ss->cd->list) == ss->slide_count) return TRUE; - else - return FALSE; + + return FALSE; } dir_fd = ss->lw->dir_fd; diff --git a/src/ui-fileops.cc b/src/ui-fileops.cc index 7e528329..a22b8603 100644 --- a/src/ui-fileops.cc +++ b/src/ui-fileops.cc @@ -887,7 +887,8 @@ void parse_out_relatives(gchar *path) s = p; continue; } - else if (path[p] == '.' && (path[p+1] == G_DIR_SEPARATOR || path[p+1] == '\0')) + + if (path[p] == '.' && (path[p+1] == G_DIR_SEPARATOR || path[p+1] == '\0')) { /* /../ or /.., remove previous part, ie. /a/b/../ becomes /a/ */ s = p + 1; diff --git a/src/ui-misc.cc b/src/ui-misc.cc index 771d3b0f..5c9bb1c2 100644 --- a/src/ui-misc.cc +++ b/src/ui-misc.cc @@ -1388,14 +1388,14 @@ gchar *text_widget_text_pull(GtkWidget *text_widget) return gtk_text_buffer_get_text(buffer, &start, &end, FALSE); } - else if (GTK_IS_ENTRY(text_widget)) + + if (GTK_IS_ENTRY(text_widget)) { return g_strdup(gq_gtk_entry_get_text(GTK_ENTRY(text_widget))); } - else - { - return nullptr; - } + + return nullptr; + } @@ -1417,14 +1417,14 @@ gchar *text_widget_text_pull_selected(GtkWidget *text_widget) return gtk_text_buffer_get_text(buffer, &start, &end, FALSE); } - else if (GTK_IS_ENTRY(text_widget)) + + if (GTK_IS_ENTRY(text_widget)) { return g_strdup(gq_gtk_entry_get_text(GTK_ENTRY(text_widget))); } - else - { - return nullptr; - } + + return nullptr; + } static gint simple_sort_cb(gconstpointer a, gconstpointer b) diff --git a/src/ui-tabcomp.cc b/src/ui-tabcomp.cc index 50b9059f..69ad7beb 100644 --- a/src/ui-tabcomp.cc +++ b/src/ui-tabcomp.cc @@ -405,15 +405,13 @@ static gboolean tab_completion_do(TabCompData *td) g_free(entry_dir); return home_exp; } - else - { - gchar *buf = g_strconcat(entry_dir, G_DIR_SEPARATOR_S, NULL); - gq_gtk_entry_set_text(GTK_ENTRY(td->entry), buf); - gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(buf)); - g_free(buf); - g_free(entry_dir); - return TRUE; - } + + gchar *buf = g_strconcat(entry_dir, G_DIR_SEPARATOR_S, NULL); + gq_gtk_entry_set_text(GTK_ENTRY(td->entry), buf); + gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(buf)); + g_free(buf); + g_free(entry_dir); + return TRUE; } ptr = const_cast(filename_from_path(entry_dir)); @@ -463,52 +461,51 @@ static gboolean tab_completion_do(TabCompData *td) g_free(entry_dir); return TRUE; } - else - { - gsize c = strlen(entry_file); - gboolean done = FALSE; - auto test_file = static_cast(poss->data); - while (!done) + gsize c = strlen(entry_file); + gboolean done = FALSE; + auto test_file = static_cast(poss->data); + + while (!done) + { + list = poss; + if (!list) done = TRUE; + while (list && !done) { - list = poss; - if (!list) done = TRUE; - while (list && !done) + auto file = static_cast(list->data); + if (strlen(file) < c || strncmp(test_file, file, c) != 0) { - auto file = static_cast(list->data); - if (strlen(file) < c || strncmp(test_file, file, c) != 0) - { - done = TRUE; - } - list = list->next; + done = TRUE; } - c++; + list = list->next; } - c -= 2; - if (c > 0) - { - gchar *file; - gchar *buf; - file = g_strdup(test_file); - file[c] = '\0'; - buf = g_build_filename(entry_dir, file, NULL); - gq_gtk_entry_set_text(GTK_ENTRY(td->entry), buf); - gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(buf)); + c++; + } + c -= 2; + if (c > 0) + { + gchar *file; + gchar *buf; + file = g_strdup(test_file); + file[c] = '\0'; + buf = g_build_filename(entry_dir, file, NULL); + gq_gtk_entry_set_text(GTK_ENTRY(td->entry), buf); + gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(buf)); #ifdef TAB_COMPLETION_ENABLE_POPUP_MENU - poss = g_list_sort(poss, simple_sort); - tab_completion_popup_list(td, poss); + poss = g_list_sort(poss, simple_sort); + tab_completion_popup_list(td, poss); #endif - g_free(file); - g_free(buf); - g_list_free(poss); - g_free(entry_dir); - return TRUE; - } + g_free(file); + g_free(buf); + g_list_free(poss); + g_free(entry_dir); + return TRUE; } + g_list_free(poss); } } diff --git a/src/view-dir-tree.cc b/src/view-dir-tree.cc index 662c420b..d30db2ba 100644 --- a/src/view-dir-tree.cc +++ b/src/view-dir-tree.cc @@ -997,28 +997,23 @@ static gint vdtree_sort_cb(GtkTreeModel *store, GtkTreeIter *a, GtkTreeIter *b, { return strcmp(nda->fd->collate_key_name_natural, ndb->fd->collate_key_name_natural); } - else - { - return strcmp(nda->fd->collate_key_name_nocase_natural, ndb->fd->collate_key_name_nocase_natural); - } + + return strcmp(nda->fd->collate_key_name_nocase_natural, ndb->fd->collate_key_name_nocase_natural); } - else if (vd->layout->options.dir_view_list_sort.method == SORT_TIME) + + if (vd->layout->options.dir_view_list_sort.method == SORT_TIME) { if (nda->fd->date < ndb->fd->date) return -1; if (nda->fd->date > ndb->fd->date) return 1; return 0; } - else + + if (vd->layout->options.dir_view_list_sort.case_sensitive == TRUE) { - if (vd->layout->options.dir_view_list_sort.case_sensitive == TRUE) - { - return strcmp(nda->fd->collate_key_name, ndb->fd->collate_key_name); - } - else - { - return strcmp(nda->fd->collate_key_name_nocase, ndb->fd->collate_key_name_nocase); - } + return strcmp(nda->fd->collate_key_name, ndb->fd->collate_key_name); } + + return strcmp(nda->fd->collate_key_name_nocase, ndb->fd->collate_key_name_nocase); } /* diff --git a/src/view-dir.cc b/src/view-dir.cc index 28fd9ceb..5a7cb137 100644 --- a/src/view-dir.cc +++ b/src/view-dir.cc @@ -1085,10 +1085,8 @@ static gboolean vd_dnd_drop_motion(GtkWidget *, GdkDragContext *context, gint x, gdk_drag_status(context, GDK_ACTION_DEFAULT, time); return TRUE; } - else - { - gdk_drag_status(context, gdk_drag_context_get_suggested_action(context), time); - } + + gdk_drag_status(context, gdk_drag_context_get_suggested_action(context), time); vd_dnd_drop_update(vd, x, y); diff --git a/src/view-file/view-file.cc b/src/view-file/view-file.cc index 683245ee..cfc8f243 100644 --- a/src/view-file/view-file.cc +++ b/src/view-file/view-file.cc @@ -1563,12 +1563,10 @@ gboolean vf_stars_cb(gpointer data) { return G_SOURCE_CONTINUE; } - else - { - vf->stars_filedata = nullptr; - vf->stars_id = 0; - return G_SOURCE_REMOVE; - } + + vf->stars_filedata = nullptr; + vf->stars_id = 0; + return G_SOURCE_REMOVE; } return G_SOURCE_REMOVE; diff --git a/src/zonedetect.cc b/src/zonedetect.cc index 6ec9808d..fae1cf61 100644 --- a/src/zonedetect.cc +++ b/src/zonedetect.cc @@ -618,7 +618,7 @@ static ZDLookupResult ZDPointInPolygon(const ZoneDetect *library, uint32_t polyg int result = ZDReaderGetPoint(&reader, &pointLat, &pointLon); if(result < 0) { return ZD_LOOKUP_PARSE_ERROR; - } else if(result == 0) { + } if(result == 0) { break; } @@ -740,9 +740,9 @@ static ZDLookupResult ZDPointInPolygon(const ZoneDetect *library, uint32_t polyg if(winding == -4) { return ZD_LOOKUP_IN_ZONE; - } else if(winding == 4) { + } if(winding == 4) { return ZD_LOOKUP_IN_EXCLUDED_ZONE; - } else if(winding == 0) { + } if(winding == 0) { return ZD_LOOKUP_NOT_IN_ZONE; } @@ -921,7 +921,7 @@ ZoneDetectResult *ZDLookup(const ZoneDetect *library, float lat, float lon, floa const ZDLookupResult lookupResult = ZDPointInPolygon(library, library->dataOffset + polygonIndex, latFixedPoint, lonFixedPoint, (safezone) ? &distanceSqrMin : nullptr); if(lookupResult == ZD_LOOKUP_PARSE_ERROR) { break; - } else if(lookupResult != ZD_LOOKUP_NOT_IN_ZONE) { + } if(lookupResult != ZD_LOOKUP_NOT_IN_ZONE) { auto newResults = static_cast(realloc(results, sizeof(ZoneDetectResult) * (numResults + 2))); if(newResults) { -- 2.20.1