[gimp/gimp-2-8] app: disallow a theoretical infinite loop if we run out of ids.



commit a90e9ec5e7fbe5ae08ff0ddd4c8c11c8a01d8e13
Author: Jehan <jehan girinstud io>
Date:   Fri Sep 20 01:54:02 2013 +1200

    app: disallow a theoretical infinite loop if we run out of ids.
    
    In practice, that's likely impossible to ever happen. This was just
    itching my perfectionist self, who enjoys flawless design.
    (cherry picked from commit 951393b34e6a33f862c91d38e5ca387d7c76b158)

 app/core/gimpidtable.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
---
diff --git a/app/core/gimpidtable.c b/app/core/gimpidtable.c
index be5bc5b..afa1d6f 100644
--- a/app/core/gimpidtable.c
+++ b/app/core/gimpidtable.c
@@ -127,15 +127,27 @@ gint
 gimp_id_table_insert (GimpIdTable *id_table, gpointer data)
 {
   gint new_id;
+  gint start_id;
 
   g_return_val_if_fail (GIMP_IS_ID_TABLE (id_table), 0);
 
+  start_id = id_table->priv->next_id;
+
   do
     {
       new_id = id_table->priv->next_id++;
 
       if (id_table->priv->next_id == GIMP_ID_TABLE_END_ID)
         id_table->priv->next_id = GIMP_ID_TABLE_START_ID;
+
+      if (start_id == id_table->priv->next_id)
+        {
+          /* We looped once over all used ids. Very unlikely to happen.
+             And if it does, there is probably not much to be done.
+             It is just good design not to allow a theoretical infinite loop. */
+          g_error ("%s: out of ids!", G_STRFUNC);
+          break;
+        }
     }
   while (gimp_id_table_lookup (id_table, new_id));
 



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