From: Emden R. Gansner Date: Sat, 2 Aug 2014 15:30:15 +0000 (-0400) Subject: Various fixes provided by Robert Hart, with small changes. X-Git-Tag: TRAVIS_CI_BUILD_EXPERIMENTAL~182 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2284749c778f41a315840de2bf393bd41a501d6e;p=graphviz Various fixes provided by Robert Hart, with small changes. 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. --- diff --git a/lib/common/ellipse.c b/lib/common/ellipse.c index 301af0211..538e7ff94 100644 --- a/lib/common/ellipse.c +++ b/lib/common/ellipse.c @@ -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 { diff --git a/lib/common/emit.c b/lib/common/emit.c index 38b4fe4dc..6a6074687 100644 --- a/lib/common/emit.c +++ b/lib/common/emit.c @@ -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; } diff --git a/lib/common/shapes.c b/lib/common/shapes.c index d8b3f2db9..000734f29 100644 --- a/lib/common/shapes.c +++ b/lib/common/shapes.c @@ -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; diff --git a/lib/common/textspan.c b/lib/common/textspan.c index 9abbbb3a5..85dfdfbf2 100644 --- a/lib/common/textspan.c +++ b/lib/common/textspan.c @@ -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), diff --git a/lib/gvc/gvevent.c b/lib/gvc/gvevent.c index 4d0817764..89ffa5b89 100644 --- a/lib/gvc/gvevent.c +++ b/lib/gvc/gvevent.c @@ -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) { diff --git a/lib/neatogen/neatosplines.c b/lib/neatogen/neatosplines.c index 83419762f..7b2a35626 100644 --- a/lib/neatogen/neatosplines.c +++ b/lib/neatogen/neatosplines.c @@ -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); } diff --git a/lib/neatogen/stress.c b/lib/neatogen/stress.c index ba6565783..a543b58e8 100644 --- a/lib/neatogen/stress.c +++ b/lib/neatogen/stress.c @@ -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]; } } diff --git a/plugin/core/gvrender_core_pov.c b/plugin/core/gvrender_core_pov.c index 803becbad..7b253e51e 100644 --- a/plugin/core/gvrender_core_pov.c +++ b/plugin/core/gvrender_core_pov.c @@ -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);