]> granicus.if.org Git - graphviz/commitdiff
work around MinGW’s lack of support for '%zu'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 20 Nov 2021 16:53:21 +0000 (08:53 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 24 Nov 2021 15:47:40 +0000 (07:47 -0800)
MinGW warns:

  plugin/core/gvrender_core_dot.c: In function 'xdot_str_xbuf':
  plugin/core/gvrender_core_dot.c:88:24: error: unknown conversion type
    character 'z' in format [-Werror=format=]
     88 |     agxbprint (xb, "%s%zu -%s ", pfx, strlen(s), s);
        |                        ^
  plugin/core/gvrender_core_dot.c:88:29: error: format '%s' expects argument of
    type 'char *', but argument 4 has type 'size_t' {aka 'unsigned int'}
    [-Werror=format=]
     88 |     agxbprint (xb, "%s%zu -%s ", pfx, strlen(s), s);
        |                            ~^         ~~~~~~~~~
        |                             |         |
        |                             char *    size_t {aka unsigned int}
        |                            %d
  plugin/core/gvrender_core_dot.c:88:20: error: too many arguments for format
    [-Werror=format-extra-args]
     88 |     agxbprint (xb, "%s%zu -%s ", pfx, strlen(s), s);
        |                    ^~~~~~~~~~~~

cmd/gvmap/make_map.c
lib/cgraph/CMakeLists.txt
lib/cgraph/Makefile.am
lib/cgraph/cgraph.vcxproj
lib/cgraph/cgraph.vcxproj.filters
lib/cgraph/prisize_t.h [new file with mode: 0644]
lib/pack/ccomps.c
lib/sparse/BinaryHeap.c
lib/xdot/xdot.c
plugin/core/gvrender_core_dot.c
plugin/visio/VisioGraphic.cpp

index d35aadbae99ffbe6162fb3cfcd0b53b59580225d..a51276374c9bffffd1c6f822eb417c084f2a20b8 100644 (file)
@@ -15,6 +15,7 @@
 #include <sparse/QuadTree.h>
 #include <string.h>
 #include <cgraph/agxbuf.h>
+#include <cgraph/prisize_t.h>
 #include <cgraph/cgraph.h>
 #include "make_map.h"
 #include <sfdpgen/stress_model.h>
@@ -241,14 +242,16 @@ static void dot_polygon(agxbuf *sbuff, int np, float *xp, float *yp, double line
 
   if (np > 0){
     if (fill >= 0){
-      agxbprint(sbuff, " c %zu -%s C %zu -%s P %d ", strlen(cstring), cstring, strlen(cstring), cstring, np);
+      agxbprint(sbuff, " c %" PRISIZE_T " -%s C %" PRISIZE_T " -%s P %d ",
+                strlen(cstring), cstring, strlen(cstring), cstring, np);
     } else {
       if (line_width > 0){
        size_t len_swidth = (size_t)snprintf(NULL, 0, "%f", line_width);
-       agxbprint(sbuff, " c %zu -%s S %zu -setlinewidth(%f) L %d ",
-                 strlen(cstring), cstring, len_swidth + 14, line_width, np);
+       agxbprint(sbuff, " c %" PRISIZE_T " -%s S %" PRISIZE_T
+                 " -setlinewidth(%f) L %d ", strlen(cstring), cstring,
+                 len_swidth + 14, line_width, np);
       } else {
-       agxbprint(sbuff, " c %zu -%s L %d ", strlen(cstring), cstring, np);
+       agxbprint(sbuff, " c %" PRISIZE_T " -%s L %d ", strlen(cstring), cstring, np);
       }
     }
     for (int i = 0; i < np; i++){
index 83b49e3e9feb9c02530d0048667aeeaab97d1a58..580d9a4179cde7ddf389cd3a7d9be64a282e4c9a 100644 (file)
@@ -14,6 +14,7 @@ add_library(cgraph SHARED
     cgraph.h
     itos.h
     likely.h
+    prisize_t.h
     sprint.h
     strcasecmp.h
     unreachable.h
index f5c78e4297660a6584dbe2385449b45102e04b98..835315d2c81d480c2188877e7669f6106466e596 100644 (file)
@@ -8,8 +8,8 @@ pkgconfigdir = $(libdir)/pkgconfig
 AM_CPPFLAGS = -I$(top_srcdir)/lib -I$(top_srcdir)/lib/cdt
 
 pkginclude_HEADERS = cgraph.h
-noinst_HEADERS = agxbuf.h cghdr.h itos.h likely.h sprint.h strcasecmp.h \
-       unreachable.h
+noinst_HEADERS = agxbuf.h cghdr.h itos.h likely.h prisize_t.h sprint.h \
+  strcasecmp.h unreachable.h
 noinst_LTLIBRARIES = libcgraph_C.la
 lib_LTLIBRARIES = libcgraph.la
 pkgconfig_DATA = libcgraph.pc
index 61626ff6de40b287bcbf1dab0db3ed0a922dd9f9..cdae4885122c21f96e42ce8f4a7e9f1ddbfb65e0 100644 (file)
@@ -102,6 +102,7 @@ win_flex -oscan.c scan.l</Command>
     <ClInclude Include="cgraph.h" />
     <ClInclude Include="itos.h" />
     <ClInclude Include="likely.h" />
+    <ClInclude Include="prisize_t.h" />
     <ClInclude Include="sprint.h" />
     <ClInclude Include="strcasecmp.h" />
     <ClInclude Include="unreachable.h" />
index 86f2596279033c3f12bd488e274cc63f46099101..936392590e9cefa3c8eaaa34d12e6b7fccc725ce 100644 (file)
@@ -30,6 +30,9 @@
     <ClInclude Include="likely.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="prisize_t.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
     <ClInclude Include="sprint.h">
       <Filter>Header Files</Filter>
     </ClInclude>
diff --git a/lib/cgraph/prisize_t.h b/lib/cgraph/prisize_t.h
new file mode 100644 (file)
index 0000000..a19c8ef
--- /dev/null
@@ -0,0 +1,13 @@
+#pragma once
+
+// `PRIu64`-alike for printing size_t
+#ifdef __MINGW64__
+  // Microsoft’s Visual C Runtime (msvcrt) ships a printf that does not
+  // understand "%zu". MSVC itself uses a different printf that does not rely on
+  // this, but MinGW uses msvcrt and so cannot handle "%zu".
+#define PRISIZE_T "llu"
+#elif defined(__MINGW32__)
+#define PRISIZE_T "u"
+#else
+#define PRISIZE_T "zu"
+#endif
index 2212f32d16cd45028f21a9e66fde1066184c2a4c..8a7395d6f075c6e46add1e83357a90a62efcc33a 100644 (file)
@@ -12,6 +12,7 @@
 #include <ctype.h>
 #include <limits.h>
 #include <stdlib.h>
+#include <cgraph/prisize_t.h>
 #include <common/render.h>
 #include <pack/pack.h>
 
@@ -227,7 +228,7 @@ Agraph_t **pccomps(Agraph_t * g, int *ncc, char *pfx, boolean * pinned)
        if (MARKED(&stk,n) || !isPinned(n))
            continue;
        if (!out) {
-           sprintf(name + len, "%zu", c_cnt);
+           sprintf(name + len, "%" PRISIZE_T, c_cnt);
            out = agsubg(g, name,1);
            agbindrec(out, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE); //node custom data
            ccs[c_cnt] = out;
@@ -244,7 +245,7 @@ Agraph_t **pccomps(Agraph_t * g, int *ncc, char *pfx, boolean * pinned)
     for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
        if (MARKED(&stk,n))
            continue;
-       sprintf(name + len, "%zu", c_cnt);
+       sprintf(name + len, "%" PRISIZE_T, c_cnt);
        out = agsubg(g, name,1);
        agbindrec(out, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE);     //node custom data
        if (dfs(g, n, out, &stk) == SIZE_MAX) {
@@ -315,7 +316,7 @@ Agraph_t **ccomps(Agraph_t * g, int *ncc, char *pfx)
     for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
        if (MARKED(&stk,n))
            continue;
-       sprintf(name + len, "%zu", c_cnt);
+       sprintf(name + len, "%" PRISIZE_T, c_cnt);
        out = agsubg(g, name,1);
        agbindrec(out, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE);     //node custom data
        if (dfs(g, n, out, &stk) == SIZE_MAX) {
@@ -644,7 +645,7 @@ Agraph_t **cccomps(Agraph_t * g, int *ncc, char *pfx)
     for (dn = agfstnode(dg); dn; dn = agnxtnode(dg, dn)) {
        if (MARKED(&stk,dn))
            continue;
-       sprintf(name + len, "%zu", c_cnt);
+       sprintf(name + len, "%" PRISIZE_T, c_cnt);
        dout = agsubg(dg, name, 1);
        out = agsubg(g, name, 1);
        agbindrec(out, GRECNAME, sizeof(ccgraphinfo_t), FALSE);
@@ -667,13 +668,13 @@ Agraph_t **cccomps(Agraph_t * g, int *ncc, char *pfx)
        ccs[c_cnt] = out;
        agdelete(dg, dout);
        if (Verbose)
-           fprintf(stderr, "(%4zu) %7zu nodes %7zu edges\n",
-                   c_cnt, n_cnt, e_cnt);
+           fprintf(stderr, "(%4" PRISIZE_T ") %7" PRISIZE_T " nodes %7" PRISIZE_T
+                   " edges\n", c_cnt, n_cnt, e_cnt);
        c_cnt++;
     }
 
     if (Verbose)
-       fprintf(stderr, "       %7d nodes %7d edges %7zu components %s\n",
+       fprintf(stderr, "       %7d nodes %7d edges %7" PRISIZE_T " components %s\n",
            agnnodes(g), agnedges(g), c_cnt, agnameof(g));
 
     agclose(dg);
index a710cc66dca5a8f3a7f3a4b94f2996ebf69bd4e6..757845a115fa423c2b4b9a373008b3547996d5d6 100644 (file)
@@ -9,6 +9,7 @@
  *************************************************************************/
 
 #include <assert.h>
+#include <cgraph/prisize_t.h>
 #include <limits.h>
 #include <sparse/BinaryHeap.h>
 #include <stdlib.h>
@@ -282,7 +283,7 @@ void BinaryHeap_print(BinaryHeap h, void (*pnt)(void*)){
   }
   fprintf(stderr, "\nSpare keys =");
   for (size_t i = 0; i <= h->id_stack->last; i++) {
-    fprintf(stderr, "%d(%zu) ", h->id_stack->stack[i],
+    fprintf(stderr, "%d(%" PRISIZE_T ") ", h->id_stack->stack[i],
             h->id_to_pos[h->id_stack->stack[i]]);
   }
   fprintf(stderr, "\n");
index 3cf5f80fd4574ca0027bcda880c76b663e622525..5bb1a59191c92b094f90846d7246937a44c01975 100644 (file)
@@ -8,6 +8,7 @@
  * Contributors: Details at https://graphviz.org
  *************************************************************************/
 
+#include <cgraph/prisize_t.h>
 #include <xdot/xdot.h>
 #include <stdlib.h>
 #include <string.h>
@@ -541,7 +542,7 @@ static void printString(char *p, pf print, void *info)
 {
     char buf[30];
 
-    snprintf(buf, sizeof(buf), " %zu -", strlen(p));
+    snprintf(buf, sizeof(buf), " %" PRISIZE_T " -", strlen(p));
     print(buf, info);
     print(p, info);
 }
index e42492b60121fe1664a4e709b089ac4685c9cb19..e3ac55545b9a8cfaf2d6683bba2f2c19303842d5 100644 (file)
@@ -27,6 +27,7 @@
 #include <gvc/gvplugin_render.h>
 #include <gvc/gvplugin_device.h>
 #include <cgraph/agxbuf.h>
+#include <cgraph/prisize_t.h>
 #include <cgraph/unreachable.h>
 #include <common/utils.h>
 #include <gvc/gvc.h>
@@ -85,7 +86,7 @@ static xdot_state_t* xd;
 
 static void xdot_str_xbuf (agxbuf* xb, char* pfx, const char* s)
 {
-    agxbprint (xb, "%s%zu -%s ", pfx, strlen(s), s);
+    agxbprint (xb, "%s%" PRISIZE_T " -%s ", pfx, strlen(s), s);
 }
 
 static void xdot_str (GVJ_t *job, char* pfx, const char* s)
index cfdda11681c9f29ca3e4649c8864ae7b7e5756d4..9f061ea878c8393efbae96a05e0e1c9b546c6ee1 100644 (file)
@@ -29,6 +29,7 @@
 #include <cstdlib>
 #include "VisioGraphic.h"
 
+#include <cgraph/prisize_t.h>
 #include <gvc/gvcjob.h>
 #include <gvc/gvio.h>
 
@@ -233,7 +234,8 @@ namespace Visio
                                gvprintf(job, "<Y F='Height*%f'/>", (_points.back().y - first.y) * yscale);
                                
                                /* Knot[P-1] */
-                               gvprintf(job, "<A>%zu</A>", _points.size() < 4 ? 0 : (_points.size() - 4));
+                               gvprintf(job, "<A>%" PRISIZE_T "</A>",
+                                        _points.size() < 4 ? 0 : (_points.size() - 4));
                                
                                /* Ctl[P-1].Weight */
                                gvputs(job, "<B>1</B>");        
@@ -245,10 +247,11 @@ namespace Visio
                                gvputs(job, "<D>1</D>");        
                                
                                /* Knot[P], Degree, XType, YType */
-                               gvprintf(job, "<E F='NURBS(%zu, 3, 0, 0", _points.size() < 3 ? 0 : (_points.size() - 3));
+                               gvprintf(job, "<E F='NURBS(%" PRISIZE_T ", 3, 0, 0",
+                                        _points.size() < 3 ? 0 : (_points.size() - 3));
                                for (size_t i = 1; i < _points.size(); ++i)
                                /* Ctl[i].X, Ctl[i].Y, Knot[i], Ctl[i].Weight */
-                                       gvprintf(job, ", %f, %f, %zu, 1",                                       
+                                       gvprintf(job, ", %f, %f, %" PRISIZE_T ", 1",                                    
                                                         (_points[i].x - first.x) * xscale,
                                                         (_points[i].y - first.y) * yscale,
                                                         i < 3 ? 0 : (i - 3));