[nautilus] directory: Use finite amount of tries for self check



commit b151025d3eb1ae6608a2d2fc70855d548626f2d6
Author: Peter <650-p3732 users noreply gitlab gnome org>
Date:   Sat Feb 13 22:57:21 2021 +0100

    directory: Use finite amount of tries for self check
    
    Turn potentially infinite while loops into for loops with finite
    amount of repetitions. In general 1000 tries should be sufficient,
    so the chosen amount of 100.000 serves as an upper limit.
    
    See https://gitlab.gnome.org/GNOME/nautilus/-/issues/1290

 src/nautilus-directory.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
---
diff --git a/src/nautilus-directory.c b/src/nautilus-directory.c
index f54ad5aac..d95880e08 100644
--- a/src/nautilus-directory.c
+++ b/src/nautilus-directory.c
@@ -2028,7 +2028,7 @@ nautilus_self_check_directory (void)
 
     nautilus_directory_unref (directory);
 
-    while (g_hash_table_size (directories) != 0)
+    for (guint i = 0; g_hash_table_size (directories) != 0 && i < 100000; i++)
     {
         gtk_main_iteration ();
     }
@@ -2045,11 +2045,13 @@ nautilus_self_check_directory (void)
                                         TRUE,
                                         got_files_callback, &data_dummy);
 
-    while (!got_files_flag)
+    for (guint i = 0; !got_files_flag && i < 100000; i++)
     {
         gtk_main_iteration ();
     }
 
+    EEL_CHECK_BOOLEAN_RESULT (got_files_flag, TRUE);
+
     EEL_CHECK_BOOLEAN_RESULT (directory->details->file_list == NULL, TRUE);
 
     EEL_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 1);


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