From 45c4e5e9bef4581a50690bdf86e9b72a43ed65e3 Mon Sep 17 00:00:00 2001 From: Omari Stephens Date: Mon, 30 May 2022 08:15:58 +0000 Subject: [PATCH] Creates a more-explicitly-type-unsafe value reader for enums. This code relies on our ability to read a guint into an enum address. C++ forbids this being done implicitly, so we do it explicitly. --- src/filefilter.c | 2 +- src/layout.c | 8 ++++---- src/rcfile.c | 8 ++++---- src/rcfile.h | 2 ++ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/filefilter.c b/src/filefilter.c index 1efdd498..c1430d30 100644 --- a/src/filefilter.c +++ b/src/filefilter.c @@ -547,7 +547,7 @@ void filter_load_file_type(const gchar **attribute_names, const gchar **attribut if (READ_BOOL(fe, enabled)) continue; if (READ_CHAR(fe, extensions)) continue; if (READ_CHAR(fe, description)) continue; - if (READ_UINT(fe, file_class)) continue; + if (READ_UINT_ENUM(fe, file_class)) continue; if (READ_BOOL(fe, writable)) continue; if (READ_BOOL(fe, allow_sidecar)) continue; diff --git a/src/layout.c b/src/layout.c index dc0482bb..16626440 100644 --- a/src/layout.c +++ b/src/layout.c @@ -2859,16 +2859,16 @@ void layout_load_attributes(LayoutOptions *layout, const gchar **attribute_names if (READ_INT(*layout, style)) continue; if (READ_CHAR(*layout, order)) continue; - if (READ_UINT(*layout, dir_view_type)) continue; - if (READ_UINT(*layout, file_view_type)) continue; - if (READ_UINT(*layout, dir_view_list_sort.method)) continue; + if (READ_UINT_ENUM(*layout, dir_view_type)) continue; + if (READ_UINT_ENUM(*layout, file_view_type)) continue; + if (READ_UINT_ENUM(*layout, dir_view_list_sort.method)) continue; if (READ_BOOL(*layout, dir_view_list_sort.ascend)) continue; if (READ_BOOL(*layout, show_marks)) continue; if (READ_BOOL(*layout, show_file_filter)) continue; if (READ_BOOL(*layout, show_thumbnails)) continue; if (READ_BOOL(*layout, show_directory_date)) continue; if (READ_CHAR(*layout, home_path)) continue; - if (READ_UINT_CLAMP(*layout, startup_path, 0, STARTUP_PATH_HOME)) continue; + if (READ_UINT_ENUM_CLAMP(*layout, startup_path, 0, STARTUP_PATH_HOME)) continue; /* window positions */ diff --git a/src/rcfile.c b/src/rcfile.c index 23e64c37..125bf1e2 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -837,7 +837,7 @@ static gboolean load_global_params(const gchar **attribute_names, const gchar ** if (READ_INT(*options, open_recent_list_maxsize)) continue; if (READ_INT(*options, recent_folder_image_list_maxsize)) continue; if (READ_INT(*options, dnd_icon_size)) continue; - if (READ_UINT(*options, dnd_default_action)) continue; + if (READ_UINT_ENUM(*options, dnd_default_action)) continue; if (READ_BOOL(*options, place_dialogs_under_mouse)) continue; if (READ_INT(*options, clipboard_selection)) continue; @@ -868,8 +868,8 @@ static gboolean load_global_params(const gchar **attribute_names, const gchar ** if (READ_BOOL(*options, with_rename)) continue; /* Image options */ - if (READ_UINT_CLAMP(*options, image.zoom_mode, 0, ZOOM_RESET_NONE)) continue; - if (READ_UINT_CLAMP(*options, image.zoom_style, 0, ZOOM_ARITHMETIC)) continue; + if (READ_UINT_ENUM_CLAMP(*options, image.zoom_mode, 0, ZOOM_RESET_NONE)) continue; + if (READ_UINT_ENUM_CLAMP(*options, image.zoom_style, 0, ZOOM_ARITHMETIC)) continue; if (READ_BOOL(*options, image.zoom_2pass)) continue; if (READ_BOOL(*options, image.zoom_to_fit_allow_expand)) continue; if (READ_BOOL(*options, image.fit_window_to_image)) continue; @@ -909,7 +909,7 @@ static gboolean load_global_params(const gchar **attribute_names, const gchar ** // if (READ_BOOL(*options, thumbnails.use_ft_metadata_small)) continue; /* File sorting options */ - if (READ_UINT(*options, file_sort.method)) continue; + if (READ_UINT_ENUM(*options, file_sort.method)) continue; if (READ_BOOL(*options, file_sort.ascending)) continue; if (READ_BOOL(*options, file_sort.case_sensitive)) continue; if (READ_BOOL(*options, file_sort.natural)) continue; diff --git a/src/rcfile.h b/src/rcfile.h index 4d873ba8..7aa1bf92 100644 --- a/src/rcfile.h +++ b/src/rcfile.h @@ -56,9 +56,11 @@ gboolean read_bool_option(const gchar *option, const gchar *label, const gchar * #define READ_BOOL(_target_, _name_) read_bool_option(option, #_name_, value, &(_target_)._name_) #define READ_INT(_target_, _name_) read_int_option(option, #_name_, value, &(_target_)._name_) #define READ_UINT(_target_, _name_) read_uint_option(option, #_name_, value, &(_target_)._name_) +#define READ_UINT_ENUM(_target_, _name_) read_uint_option(option, #_name_, value, (guint*)&(_target_)._name_) #define READ_USHORT(_target_, _name_) read_ushort_option(option, #_name_, value, &(_target_)._name_) #define READ_INT_CLAMP(_target_, _name_, _min_, _max_) read_int_option_clamp(option, #_name_, value, &(_target_)._name_, _min_, _max_) #define READ_UINT_CLAMP(_target_, _name_, _min_, _max_) read_uint_option_clamp(option, #_name_, value, &(_target_)._name_, _min_, _max_) +#define READ_UINT_ENUM_CLAMP(_target_, _name_, _min_, _max_) read_uint_option_clamp(option, #_name_, value, (guint*)&(_target_)._name_, _min_, _max_) #define READ_INT_UNIT(_target_, _name_, _unit_) read_int_unit_option(option, #_name_, value, &(_target_)._name_, _unit_) #define READ_CHAR(_target_, _name_) read_char_option(option, #_name_, value, &(_target_)._name_) #define READ_COLOR(_target_, _name_) read_color_option(option, #_name_, value, &(_target_)._name_) -- 2.20.1