Skip to content

Commit

Permalink
app: disallow a theoretical infinite loop if we run out of ids.
Browse files Browse the repository at this point in the history
In practice, that's likely impossible to ever happen. This was just
itching my perfectionist self, who enjoys flawless design.
  • Loading branch information
Jehan committed Sep 19, 2013
1 parent b7afb81 commit 951393b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/core/gimpidtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down

0 comments on commit 951393b

Please sign in to comment.