]> granicus.if.org Git - graphviz/commitdiff
neatogen: replace 'MAXFLOAT' in clamping logic with 'FLT_MAX'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 12 Feb 2022 03:13:49 +0000 (14:13 +1100)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 15 Feb 2022 07:30:11 +0000 (18:30 +1100)
This seems a more accurate definition of what overflow would mean under C99.
Though as far as I can tell, it is not possible to reach this code with negative
values in the array, so the `< 0` check is always false. The `>= FLT_MAX` is
true for both `FLT_MAX` itself as well as positive infinity.

lib/neatogen/stress.c

index baa2d8c268b68b8d4d5cdb5fa74e4277333dcf3e..cb3996b273da353808824126f5be6b83ee158375 100644 (file)
@@ -8,7 +8,7 @@
  * Contributors: Details at https://graphviz.org
  *************************************************************************/
 
-
+#include <float.h>
 #include <neatogen/neato.h>
 #include <neatogen/dijkstra.h>
 #include <neatogen/bfs.h>
@@ -1118,8 +1118,7 @@ int stress_majorization_kD_mkernel(vtx_data * graph,      /* Input graph in sparse re
            invert_sqrt_vec(len, dist_accumulator);
            /* detect overflows */
            for (j = 0; j < len; j++) {
-               if (dist_accumulator[j] >= MAXFLOAT
-                   || dist_accumulator[j] < 0) {
+               if (dist_accumulator[j] >= FLT_MAX || dist_accumulator[j] < 0) {
                    dist_accumulator[j] = 0;
                }
            }