### Changed
-- **Breaking**: libxdot fields for the size and number of operations are now
- `size_t` values instead of `int` values
+- **Breaking**: libxdot fields for the size and number of operations, the
+ statistics counts, and polygon line points are now `size_t` values instead of
+ `int` values
### Removed
static void DrawBeziers(sdot_op* o, int param)
{
int filled;
- int i = 0;
xdot_op * op=&o->op;
xdot_point* ps = op->u.bezier.pts;
view->Topview->global_z = view->Topview->global_z + o->layer*LAYER_DIFF;
else
filled = 0;
- for (i = 1; i < op->u.bezier.cnt; i += 3) {
+ for (size_t i = 1; i < op->u.bezier.cnt; i += 3) {
DrawBezier(ps, filled, param);
ps += 3;
}
static void DrawPolyline(sdot_op* o, int param)
{
- int i = 0;
xdot_op * op=&o->op;
view->Topview->global_z=view->Topview->global_z+o->layer*LAYER_DIFF;
set_options(param);
glLineWidth(view->LineWidth);
glBegin(GL_LINE_STRIP);
- for (i = 0; i < op->u.polyline.cnt; i = i + 1) {
+ for (size_t i = 0; i < op->u.polyline.cnt; ++i) {
glVertex3f((GLfloat) op->u.polyline.pts[i].x - dx,
(GLfloat) op->u.polyline.pts[i].y - dy,
(GLfloat) op->u.polyline.pts[i].z + view->Topview->global_z);
*************************************************************************/
#include "polytess.h"
+#include <stddef.h>
#include <xdot/xdot.h>
tessPoly TP;
static void Render_Contour2(GLUtesselator *tobj, sdot_op* p)
{
- int x=0;
-
GLdouble* d = calloc(p->op.u.polygon.cnt * 3, sizeof(GLdouble));
- for (x=0;x < p->op.u.polygon.cnt; x++)
+ for (size_t x = 0; x < p->op.u.polygon.cnt; x++)
{
d[x * 3] = p->op.u.polygon.pts[x].x;
d[x * 3 + 1] = p->op.u.polygon.pts[x].y;
d[x * 3 + 2] = p->op.u.polygon.pts[x].z + view->Topview->global_z;
}
- for (x = 0; x < p->op.u.polygon.cnt; x++) //loop through the vertices
+ for (size_t x = 0; x < p->op.u.polygon.cnt; x++) //loop through the vertices
{
gluTessVertex(tobj, &d[x * 3], &d[x * 3]); //store the vertex
}
* return start of point list (skip over e and s points).
* return NULL on failure
*/
-static char* countPoints (char* pos, int* have_sp, xdot_point* sp, int* have_ep, xdot_point* ep, int* cntp)
-{
- int cnt = 0;
+static char *countPoints(char *pos, int *have_sp, xdot_point *sp, int *have_ep,
+ xdot_point *ep, size_t *cntp) {
+ size_t cnt = 0;
char* p;
pos = skipWS (pos);
static xdot* makeXDotSpline (char* pos)
{
xdot_point s, e;
- int v, have_s, have_e, cnt;
+ int v, have_s, have_e;
+ size_t cnt;
static const size_t sz = sizeof(sdot_op);
xdot* xd;
xdot_op* op;
#include <stddef.h>
#include <string.h>
#include <ctype.h>
+#include <limits.h>
#include <locale.h>
#include <math.h>
#include <common/render.h>
#define INITPTS 1000
-static pointf*
-copyPts (pointf* pts, int* ptsize, xdot_point* inpts, int numpts)
-{
- int i, sz = *ptsize;
+static pointf *copyPts(pointf *pts, size_t *ptsize, xdot_point *inpts,
+ size_t numpts) {
+ size_t sz = *ptsize;
if (numpts > sz) {
sz = MAX(2*sz, numpts);
*ptsize = sz;
}
- for (i = 0; i < numpts; i++) {
+ for (size_t i = 0; i < numpts; i++) {
pts[i].x = inpts[i].x;
pts[i].y = inpts[i].y;
}
static void emit_xdot (GVJ_t * job, xdot* xd)
{
int image_warn = 1;
- int ptsize = INITPTS;
+ size_t ptsize = INITPTS;
pointf* pts = N_GNEW(INITPTS, pointf);
exdot_op* op;
int angle;
case xd_unfilled_polygon :
if (boxf_overlap(op->bb, job->clip)) {
pts = copyPts (pts, &ptsize, op->op.u.polygon.pts, op->op.u.polygon.cnt);
- gvrender_polygon(job, pts, op->op.u.polygon.cnt,
+ assert(op->op.u.polygon.cnt <= INT_MAX &&
+ "polygon count exceeds gvrender_polygon support");
+ gvrender_polygon(job, pts, (int)op->op.u.polygon.cnt,
op->op.kind == xd_filled_polygon ? filled : 0);
}
break;
case xd_unfilled_bezier :
if (boxf_overlap(op->bb, job->clip)) {
pts = copyPts (pts, &ptsize, op->op.u.bezier.pts, op->op.u.bezier.cnt);
- gvrender_beziercurve(job, pts, op->op.u.bezier.cnt, 0, 0,
+ assert(op->op.u.bezier.cnt <= INT_MAX &&
+ "polygon count exceeds gvrender_beizercurve support");
+ gvrender_beziercurve(job, pts, (int)op->op.u.bezier.cnt, 0, 0,
op->op.kind == xd_filled_bezier ? filled : 0);
}
break;
case xd_polyline :
if (boxf_overlap(op->bb, job->clip)) {
pts = copyPts (pts, &ptsize, op->op.u.polyline.pts, op->op.u.polyline.cnt);
- gvrender_polyline(job, pts, op->op.u.polyline.cnt);
+ assert(op->op.u.polyline.cnt <= INT_MAX &&
+ "polygon count exceeds gvrender_polyline support");
+ gvrender_polyline(job, pts, (int)op->op.u.polyline.cnt);
}
break;
case xd_text :
bb->LL.y = fmin(bb->LL.y, p.y);
}
-static boxf
-ptsBB (xdot_point* inpts, int numpts, boxf* bb)
-{
+static boxf ptsBB(xdot_point *inpts, size_t numpts, boxf *bb) {
boxf opbb;
- int i;
opbb.LL.x = opbb.UR.x = inpts->x;
opbb.LL.y = opbb.UR.y = inpts->y;
- for (i = 1; i < numpts; i++) {
+ for (size_t i = 1; i < numpts; i++) {
inpts++;
if (inpts->x < opbb.LL.x)
opbb.LL.x = inpts->x;
static char *parsePolyline(char *s, xdot_polyline * pp)
{
- int i;
+ unsigned i;
xdot_point *pts;
xdot_point *ps;
char* endp;
- s = parseInt(s, &i);
+ s = parseUInt(s, &i);
if (!s) return NULL;
- if (i < 0) return NULL;
- pts = ps = gv_calloc((size_t)i, sizeof(ps[0]));
+ pts = ps = gv_calloc(i, sizeof(ps[0]));
pp->cnt = i;
for (i = 0; i < pp->cnt; i++) {
ps->x = strtod (s, &endp);
static void printPolyline(xdot_polyline * p, pf print, void *info)
{
- int i;
char buf[512];
- print(info, " %d", p->cnt);
- for (i = 0; i < p->cnt; i++) {
+ print(info, " %" PRISIZE_T, p->cnt);
+ for (size_t i = 0; i < p->cnt; i++) {
snprintf(buf, sizeof(buf), " %.02f", p->pts[i].x);
trim(buf);
print(info, "%s", buf);
static void jsonPolyline(xdot_polyline * p, pf print, void *info)
{
- int i;
-
print(info, "[");
- for (i = 0; i < p->cnt; i++) {
+ for (size_t i = 0; i < p->cnt; i++) {
print(info, "%.06f,%.06f", p->pts[i].x, p->pts[i].y);
if (i < p->cnt-1) print(info, ",");
}
} xdot_rect;
typedef struct {
- int cnt;
+ size_t cnt;
xdot_point* pts;
} xdot_polyline;
typedef struct {
size_t cnt; /* no. of xdot ops */
- int n_ellipse;
- int n_polygon;
- int n_polygon_pts;
- int n_polyline;
- int n_polyline_pts;
- int n_bezier;
- int n_bezier_pts;
- int n_text;
- int n_font;
- int n_style;
- int n_color;
- int n_image;
- int n_gradcolor;
- int n_fontchar;
+ size_t n_ellipse;
+ size_t n_polygon;
+ size_t n_polygon_pts;
+ size_t n_polyline;
+ size_t n_polyline_pts;
+ size_t n_bezier;
+ size_t n_bezier_pts;
+ size_t n_text;
+ size_t n_font;
+ size_t n_style;
+ size_t n_color;
+ size_t n_image;
+ size_t n_gradcolor;
+ size_t n_fontchar;
} xdot_stats;
/* ops are indexed by xop_kind */
static void write_polyline (GVJ_t * job, xdot_polyline* polyline)
{
- int i;
- int cnt = polyline->cnt;
+ const size_t cnt = polyline->cnt;
xdot_point* pts = polyline->pts;
gvprintf(job, "\"points\": [");
- for (i = 0; i < cnt; i++) {
+ for (size_t i = 0; i < cnt; i++) {
if (i > 0) gvprintf(job, ",");
gvprintf(job, "[%.03f,%.03f]", pts[i].x, pts[i].y);
}