libevtr: Remove loop with undefined optimized behavior
authorJohn Marino <draco@marino.st>
Tue, 10 Feb 2015 09:00:05 +0000 (10:00 +0100)
committerJohn Marino <draco@marino.st>
Tue, 10 Feb 2015 09:06:05 +0000 (10:06 +0100)
Starting with gcc 4.8 I believe, one particular loop in evtr.c fails to
compile.  The error is "interation 3u involved undefined behavior
[-Werror=aggressive-loop-optimizations]".

No alternative I tried worked, so I finally just removed the loop since
it only iterates 4 times.  It's brute force but the code is correct.

lib/libevtr/evtr.c

index bbee6ad..c85d013 100644 (file)
@@ -1434,8 +1434,21 @@ evtr_close(evtr_t evtr)
 
        if (evtr->flags & EVTRF_WR) {
                hashtab_destroy(&evtr->fmts->tab);
-               for (i = 0; i < EVTR_NS_MAX; ++i)
-                       hashtab_destroy(&evtr->strings[i]->tab);
+               /*
+                * Brute force soluion - the following loop fails to build
+                * with gcc48+ with the error "iteration 3u invokes undefined
+                * behavior [-Werror=aggressive-loop-optimizations]
+                * EVTR_NS_MAX is a constant 4.  Apparently it's the
+                * "strings" field causing the issue, because "maps" below
+                * compiles fine with same compiler.
+                *
+                * for (i = 0; i < EVTR_NS_MAX; ++i)
+                *         hashtab_destroy(&evtr->strings[i]->tab);
+                */
+               hashtab_destroy(&evtr->strings[0]->tab);
+               hashtab_destroy(&evtr->strings[1]->tab);
+               hashtab_destroy(&evtr->strings[2]->tab);
+               hashtab_destroy(&evtr->strings[3]->tab);
        } else {
                id_tree_free(&evtr->fmtmap.root);
                for (i = 0; i < EVTR_NS_MAX - 1; ++i) {