eina_safepointer: Fix coverity warning
authorJean-Philippe Andre <jp.andre@samsung.com>
Wed, 13 Jul 2016 07:22:00 +0000 (16:22 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Wed, 13 Jul 2016 07:25:01 +0000 (16:25 +0900)
I guess the overflow was badly handled. Fixing it by using
explicit int intermediate value.

Fixes CID 1356616 and 1356619:

Operands don't affect result
Logically dead code

src/lib/eina/eina_safepointer.c

index 42433ea..94ec1ab 100644 (file)
@@ -239,6 +239,7 @@ eina_safepointer_register(const void *target)
    Eina_Memory_Table *table;
    Eina_Memory_Entry *entry = NULL;
    Eina_Sp_Id id = 0;
+   unsigned int gen;
 
    // We silently handle NULL
    if (!target) return NULL;
@@ -254,9 +255,8 @@ eina_safepointer_register(const void *target)
 
    entry->ptr = (void*) target;
    entry->active = 1;
-   entry->generation++;
-   if (entry->generation == EINA_MAX_GENERATIONS)
-     entry->generation = 1;
+   gen = entry->generation + 1;
+   entry->generation = (gen == EINA_MAX_GENERATIONS) ? 1 : gen;
 
    id = SP_COMPOSE_FINAL_ID(table->partial_id,
                             (entry - table->entries),