[glom] get_unused_database_name(): Don't retry forever.



commit b30173210f4ec7c1ded6c7c6ef2e4bbb6367dde1
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Mar 15 08:28:40 2016 +0100

    get_unused_database_name(): Don't retry forever.
    
    Noticed by the IntelliJ CLion inspections.

 glom/libglom/db_utils.cc |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/glom/libglom/db_utils.cc b/glom/libglom/db_utils.cc
index c0586e7..48c780a 100644
--- a/glom/libglom/db_utils.cc
+++ b/glom/libglom/db_utils.cc
@@ -1906,10 +1906,17 @@ Glib::ustring get_unused_database_name(const Glib::ustring& base_name)
   if(!connection_pool)
     return Glib::ustring();
 
-  bool keep_trying = true;
+  int count_tries = 0;
   size_t extra_num = 0;
-  while(keep_trying)
+  while(true)
   {
+    if (count_tries > 200) {
+      std::cerr << G_STRFUNC << ": Too many attempts failed.\n";
+      return Glib::ustring();
+    }
+
+    count_tries++;
+
     Glib::ustring database_name_possible;
     if(extra_num == 0)
     {
@@ -1934,6 +1941,8 @@ Glib::ustring get_unused_database_name(const Glib::ustring& base_name)
 
     std::shared_ptr<Glom::SharedConnection> connection;
 
+    //We try this until it fails,
+    //knowing that it will fail eventually.
     try
     {
       connection = ConnectionPool::get_and_connect();


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