From: Matthew Fernandez Date: Thu, 18 Aug 2022 00:51:39 +0000 (-0700) Subject: gvc gvprintpointflist: take number of points as a size_t X-Git-Tag: 6.0.1~33^2~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3f9aa0279ebaf34e7c7b1d2e65b3b55f6987a549;p=graphviz gvc gvprintpointflist: take number of points as a size_t This is a more appropriate type for the length of an array. --- diff --git a/lib/gvc/gvdevice.c b/lib/gvc/gvdevice.c index 7a8c6f9b3..aca908f11 100644 --- a/lib/gvc/gvdevice.c +++ b/lib/gvc/gvdevice.c @@ -595,10 +595,9 @@ void gvprintpointf(GVJ_t * job, pointf p) gvwrite(job, buf, len); } -void gvprintpointflist(GVJ_t * job, pointf *p, int n) -{ +void gvprintpointflist(GVJ_t *job, pointf *p, size_t n) { const char *separator = ""; - for (int i = 0; i < n; ++i) { + for (size_t i = 0; i < n; ++i) { gvputs(job, separator); gvprintpointf(job, p[i]); separator = " "; diff --git a/lib/gvc/gvio.h b/lib/gvc/gvio.h index 078e17d07..5a5bcf107 100644 --- a/lib/gvc/gvio.h +++ b/lib/gvc/gvio.h @@ -43,7 +43,7 @@ extern "C" { GVIO_API void gvprintf(GVJ_t * job, const char *format, ...); GVIO_API void gvprintdouble(GVJ_t * job, double num); GVIO_API void gvprintpointf(GVJ_t * job, pointf p); - GVIO_API void gvprintpointflist(GVJ_t * job, pointf *p, int n); + GVIO_API void gvprintpointflist(GVJ_t *job, pointf *p, size_t n); #undef GVIO_API diff --git a/plugin/core/gvrender_core_ps.c b/plugin/core/gvrender_core_ps.c index f51f7c85f..c46f275e6 100644 --- a/plugin/core/gvrender_core_ps.c +++ b/plugin/core/gvrender_core_ps.c @@ -9,7 +9,7 @@ *************************************************************************/ #include "config.h" - +#include #include #include @@ -413,10 +413,11 @@ static void psgen_comment(GVJ_t * job, char *str) static void psgen_library_shape(GVJ_t * job, char *name, pointf * A, int n, int filled) { + assert(n >= 0); if (filled && job->obj->fillcolor.u.HSVA[3] > .5) { ps_set_color(job, &(job->obj->fillcolor)); gvputs(job, "[ "); - gvprintpointflist(job, A, n); + gvprintpointflist(job, A, (size_t)n); gvputs(job, " "); gvprintpointf(job, A[0]); gvprintf(job, " ] %d true %s\n", n, name); @@ -425,7 +426,7 @@ static void psgen_library_shape(GVJ_t * job, char *name, pointf * A, int n, int ps_set_pen_style(job); ps_set_color(job, &(job->obj->pencolor)); gvputs(job, "[ "); - gvprintpointflist(job, A, n); + gvprintpointflist(job, A, (size_t)n); gvputs(job, " "); gvprintpointf(job, A[0]); gvprintf(job, " ] %d false %s\n", n, name); diff --git a/plugin/core/gvrender_core_tk.c b/plugin/core/gvrender_core_tk.c index 17bba9a6f..795f6e9ac 100644 --- a/plugin/core/gvrender_core_tk.c +++ b/plugin/core/gvrender_core_tk.c @@ -9,7 +9,7 @@ *************************************************************************/ #include "config.h" - +#include #include #include #include @@ -263,12 +263,14 @@ tkgen_bezier(GVJ_t * job, pointf * A, int n, int arrow_at_start, (void)arrow_at_end; (void)filled; + assert(n >= 0); + obj_state_t *obj = job->obj; if (obj->pen != PEN_NONE) { tkgen_canvas(job); gvputs(job, " create line "); - gvprintpointflist(job, A, n); + gvprintpointflist(job, A, (size_t)n); gvputs(job, " -fill "); tkgen_print_color(job, obj->pencolor); gvputs(job, " -width "); @@ -285,12 +287,14 @@ tkgen_bezier(GVJ_t * job, pointf * A, int n, int arrow_at_start, static void tkgen_polygon(GVJ_t * job, pointf * A, int n, int filled) { + assert(n >= 0); + obj_state_t *obj = job->obj; if (obj->pen != PEN_NONE) { tkgen_canvas(job); gvputs(job, " create polygon "); - gvprintpointflist(job, A, n); + gvprintpointflist(job, A, (size_t)n); gvputs(job, " -fill "); if (filled) tkgen_print_color(job, obj->fillcolor); @@ -318,12 +322,14 @@ static void tkgen_polygon(GVJ_t * job, pointf * A, int n, int filled) static void tkgen_polyline(GVJ_t * job, pointf * A, int n) { + assert(n >= 0); + obj_state_t *obj = job->obj; if (obj->pen != PEN_NONE) { tkgen_canvas(job); gvputs(job, " create line "); - gvprintpointflist(job, A, n); + gvprintpointflist(job, A, (size_t)n); gvputs(job, " -fill "); tkgen_print_color(job, obj->pencolor); if (obj->pen == PEN_DASHED) diff --git a/plugin/lasi/gvrender_lasi.cpp b/plugin/lasi/gvrender_lasi.cpp index 6cf68e02a..a80eebcb1 100644 --- a/plugin/lasi/gvrender_lasi.cpp +++ b/plugin/lasi/gvrender_lasi.cpp @@ -534,10 +534,11 @@ static void lasi_comment(GVJ_t * job, char *str) static void lasi_library_shape(GVJ_t * job, char *name, pointf * A, int n, int filled) { + assert(n >= 0); if (filled && job->obj->fillcolor.u.HSVA[3] > .5) { ps_set_color(job, &(job->obj->fillcolor)); gvputs(job, "[ "); - gvprintpointflist(job, A, n); + gvprintpointflist(job, A, (size_t)n); gvputs(job, " "); gvprintpointf(job, A[0]); gvprintf(job, " ] %d true %s\n", n, name);