]> granicus.if.org Git - graphviz/commitdiff
Various fixes provided by Robert Hart, with small changes.
authorEmden R. Gansner <erg@alum.mit.edu>
Sat, 2 Aug 2014 15:30:15 +0000 (11:30 -0400)
committerEmden R. Gansner <erg@alum.mit.edu>
Sat, 2 Aug 2014 15:30:15 +0000 (11:30 -0400)
Some of the absolute value tests aren't necessary; we just want
a test for being non-zero. In addition, freeing the result of parseSegs
is a little more delicate.

lib/common/ellipse.c
lib/common/emit.c
lib/common/shapes.c
lib/common/textspan.c
lib/gvc/gvevent.c
lib/neatogen/neatosplines.c
lib/neatogen/stress.c
plugin/core/gvrender_core_pov.c

index 301af0211184a3ec8af6fc73809579ab66467889..538e7ff94c7f7694aa14adea6c058bd00942e7a8 100644 (file)
@@ -146,7 +146,7 @@ static void computeBounds(ellipse_t * ep)
     double bOnA = ep->b / ep->a;
     double etaXMin, etaXMax, etaYMin, etaYMax;
 
-    if (abs(ep->sinTheta) < 0.1) {
+    if (fabs(ep->sinTheta) < 0.1) {
        double tanTheta = ep->sinTheta / ep->cosTheta;
        if (ep->cosTheta < 0) {
            etaXMin = -atan(tanTheta * bOnA);
@@ -365,7 +365,7 @@ estimateError(ellipse_t * ep, int degree, double etaA, double etaB)
        double dx = xB - xA;
        double dy = yB - yA;
 
-       return abs(x * dy - y * dx + xB * yA - xA * yB)
+       return fabs(x * dy - y * dx + xB * yA - xA * yB)
            / sqrt(dx * dx + dy * dy);
 
     } else {
index 38b4fe4dcba5bddb29cbb7d8165afa391e71a363..6a60746876805067e393cd1086dcd2247cede220 100644 (file)
@@ -397,6 +397,10 @@ static double getSegLen (char* s)
  *  3 => warning message
  * There is a last sentinel segment with color == NULL; it will always follow
  * the last segment with t > 0.
+ *
+ * Note that psegs is only assigned to if the return value is 0 or 3.
+ * Otherwise, psegs is left unchanged and the allocated memory is
+ * freed before returning.
  */
 static int
 parseSegs (char* clrs, int nseg, colorsegs_t** psegs)
@@ -2151,7 +2155,7 @@ static int multicolor (GVJ_t * job, edge_t * e, char** styles, char* colors, int
        if ((ED_spl(e)->size>1) && (bz.sflag||bz.eflag) && styles) 
            gvrender_set_style(job, styles);
     }
-    free (segs);
+    freeSegs (segs);
     return 0;
 }
 
@@ -4129,12 +4133,13 @@ int gvRenderJobs (GVC_t * gvc, graph_t * g)
  */
 boolean findStopColor (char* colorlist, char* clrs[2], float* frac)
 {
-    colorsegs_t* segs;
+    colorsegs_t* segs = NULL;
     int rv;
 
     rv = parseSegs (colorlist, 0, &segs);
     if (rv || (segs->numc < 2) || (segs->segs[0].color == NULL)) {
        clrs[0] = NULL;
+       freeSegs (segs);
        return FALSE;
     }
 
index d8b3f2db91fbbeac15c8a43063d7389f79ff788c..000734f29511296fe3acad2dd0e3e6f7730374cc 100644 (file)
@@ -1873,7 +1873,7 @@ static void poly_init(node_t * n)
     dimen = ND_label(n)->dimen;
 
     /* minimal whitespace around label */
-    if (ROUND(abs(dimen.x)) || ROUND(abs(dimen.y))) {
+    if ((dimen.x > 0) || (dimen.y > 0)) {
        /* padding */
        if ((p = agget(n, "margin"))) {
            marginx = marginy = 0;
index 9abbbb3a58ce37d03a5006ebd4fbf6d6adcf179f..85dfdfbf266a080fe04cddf54286de089ffed95a 100644 (file)
@@ -184,7 +184,8 @@ static PostscriptAlias* translate_postscript_fontname(char* fontname)
     static PostscriptAlias *result;
 
     if (key.name == NULL || strcasecmp(key.name, fontname)) {
-        key.name = fontname;
+       free(key.name);
+        key.name = strdup(fontname);
         result = (PostscriptAlias *) bsearch((void *) &key,
                        (void *) postscript_alias,
                        sizeof(postscript_alias) / sizeof(PostscriptAlias),
index 4d081776468285a2ff227303014e3d792c643abe..89ffa5b898569ffb4f544871d8a3d3ee4219665a 100644 (file)
@@ -455,7 +455,7 @@ static void gvevent_motion(GVJ_t * job, pointf pointer)
     double dx = (pointer.x - job->oldpointer.x) / job->devscale.x;
     double dy = (pointer.y - job->oldpointer.y) / job->devscale.y;
 
-    if (abs(dx) < EPSILON && abs(dy) < EPSILON)  /* ignore motion events with no motion */
+    if (fabs(dx) < EPSILON && fabs(dy) < EPSILON)  /* ignore motion events with no motion */
        return;
 
     switch (job->button) {
index 83419762f1279017162338a24540d6a418e49bbb..7b2a35626ef47840e8c75752401609298701e3b5 100644 (file)
@@ -1007,7 +1007,7 @@ static boolean _neato_set_aspect(graph_t * g)
 
     /* compute_bb(g); */
     if (GD_drawing(g)->ratio_kind) {
-       if ((abs(GD_bb(g).LL.x)) || (abs(GD_bb(g).LL.y))) {
+       if (GD_bb(g).LL.x || GD_bb(g).LL.y) {
            translated = TRUE;
            neato_translate (g);
        }
index ba6565783adea73dce8964a2765379988c6778d0..a543b58e8e78e921fb411ed97b5362c73b920094 100644 (file)
@@ -756,7 +756,7 @@ float *mdsModel(vtx_data * graph, int nG)
            j = graph[i].edges[e];
            if (j < i)
                continue;
-           delta += abs(Dij[i * nG + j - shift] - graph[i].ewgts[e]);
+           delta += fabsf(Dij[i * nG + j - shift] - graph[i].ewgts[e]);
            Dij[i * nG + j - shift] = graph[i].ewgts[e];
        }
     }
index 803becbad1952defe28ab2c19dac1db73132a555..7b253e51e36eda6596673ea68d99a5c03b79ef17 100644 (file)
@@ -508,8 +508,8 @@ static void pov_begin_graph(GVJ_t * job)
        x = job->view.x / 2.0 * job->scale.x;
        y = job->view.y / 2.0 * job->scale.y;
        d = -500;
-       px = atanf(x / abs(d)) * 180 / M_PI * 2;
-       py = atanf(y / abs(d)) * 180 / M_PI * 2;
+       px = atanf(x / fabsf(d)) * 180 / M_PI * 2;
+       py = atanf(y / fabsf(d)) * 180 / M_PI * 2;
        gvprintf(job, POV_CAMERA, x, y, d, x, y, 0.0,
                 (px > py ? px : py) * 1.2);
        gvputs(job, POV_SKY_AND_GND);