[nautilus/wip/oholy/search-engine-fixes: 7/7] nautilus-search-engine: Explicitely initialize variables




commit 79851b3279a96d7f1b4fa02f946f5e5feb9be1e3
Author: Ondrej Holy <oholy redhat com>
Date:   Tue Feb 15 10:04:17 2022 +0100

    nautilus-search-engine: Explicitely initialize variables
    
    Currently, build warning is shown about the potential usage of
    uninitalized variable. This is false-positive, but let's explicitly
    initialize the variables using switch to get rid of the warning.
    
    Fixes: https://gitlab.gnome.org/GNOME/nautilus/-/issues/2152

 src/nautilus-search-engine-model.c  | 33 +++++++++++++++++++++++----------
 src/nautilus-search-engine-recent.c | 33 +++++++++++++++++++++++----------
 src/nautilus-search-engine-simple.c | 33 +++++++++++++++++++++++----------
 3 files changed, 69 insertions(+), 30 deletions(-)
---
diff --git a/src/nautilus-search-engine-model.c b/src/nautilus-search-engine-model.c
index 1205873fe..46f2a0b24 100644
--- a/src/nautilus-search-engine-model.c
+++ b/src/nautilus-search-engine-model.c
@@ -185,17 +185,30 @@ model_directory_ready_cb (NautilusDirectory *directory,
             initial_date = g_ptr_array_index (date_range, 0);
             end_date = g_ptr_array_index (date_range, 1);
 
-            if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS)
+            switch (type)
             {
-                target_date = atime;
-            }
-            else if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED)
-            {
-                target_date = mtime;
-            }
-            else
-            {
-                target_date = ctime;
+                case NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS:
+                {
+                    target_date = atime;
+                }
+                break;
+
+                case NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED:
+                {
+                    target_date = mtime;
+                }
+                break;
+
+                case NAUTILUS_QUERY_SEARCH_TYPE_CREATED:
+                {
+                    target_date = ctime;
+                }
+                break;
+
+                default:
+                {
+                    target_date = NULL;
+                }
             }
 
             found = nautilus_date_time_is_between_dates (target_date,
diff --git a/src/nautilus-search-engine-recent.c b/src/nautilus-search-engine-recent.c
index 1c69b2a93..a31b9d88f 100644
--- a/src/nautilus-search-engine-recent.c
+++ b/src/nautilus-search-engine-recent.c
@@ -302,17 +302,30 @@ recent_thread_func (gpointer user_data)
                 end_date = g_ptr_array_index (date_range, 1);
                 type = nautilus_query_get_search_type (self->query);
 
-                if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS)
+                switch (type)
                 {
-                    target_date = atime;
-                }
-                else if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED)
-                {
-                    target_date = mtime;
-                }
-                else if (type == NAUTILUS_QUERY_SEARCH_TYPE_CREATED)
-                {
-                    target_date = ctime;
+                    case NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS:
+                    {
+                        target_date = atime;
+                    }
+                    break;
+
+                    case NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED:
+                    {
+                        target_date = mtime;
+                    }
+                    break;
+
+                    case NAUTILUS_QUERY_SEARCH_TYPE_CREATED:
+                    {
+                        target_date = ctime;
+                    }
+                    break;
+
+                    default:
+                    {
+                        target_date = NULL;
+                    }
                 }
 
                 if (!nautilus_date_time_is_between_dates (target_date,
diff --git a/src/nautilus-search-engine-simple.c b/src/nautilus-search-engine-simple.c
index ec2433d5f..4fa1a0787 100644
--- a/src/nautilus-search-engine-simple.c
+++ b/src/nautilus-search-engine-simple.c
@@ -366,17 +366,30 @@ visit_directory (GFile            *dir,
             initial_date = g_ptr_array_index (date_range, 0);
             end_date = g_ptr_array_index (date_range, 1);
 
-            if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS)
+            switch (type)
             {
-                target_date = atime;
-            }
-            else if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED)
-            {
-                target_date = mtime;
-            }
-            else
-            {
-                target_date = ctime;
+                case NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS:
+                {
+                    target_date = atime;
+                }
+                break;
+
+                case NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED:
+                {
+                    target_date = mtime;
+                }
+                break;
+
+                case NAUTILUS_QUERY_SEARCH_TYPE_CREATED:
+                {
+                    target_date = ctime;
+                }
+                break;
+
+                default:
+                {
+                    target_date = NULL;
+                }
             }
 
             found = nautilus_date_time_is_between_dates (target_date,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]