]> granicus.if.org Git - graphviz/commitdiff
swap sprintf for snprintf where straightforward
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 6 Mar 2021 23:35:39 +0000 (15:35 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 16 Mar 2021 03:48:27 +0000 (20:48 -0700)
sprintf has consistently been in the top ten root causes of vulnerabilities in
low level applications and is generally considered unsafe for any use in modern
code bases. This commit removes the instances of it that are straightforward to
convert to snprintf. Related to #1950.

61 files changed:
cmd/dot/dot.c
cmd/dotty/mswin32/dotty.c
cmd/lefty/common.c
cmd/lefty/dot2l/dot2l.c
cmd/lefty/gfxview.c
cmd/lefty/internal.c
cmd/lefty/os/unix/io.c
cmd/lneato/mswin32/lneato.c
cmd/smyrna/gui/frmobjectui.c
cmd/smyrna/gui/topviewsettings.c
cmd/smyrna/gvprpipe.c
cmd/smyrna/viewport.c
cmd/smyrna/viewportcamera.c
cmd/tools/dijkstra.c
cmd/tools/gmlparse.y
cmd/tools/graphml2gv.c
cmd/tools/gv2gxl.c
cmd/tools/gvcolor.c
cmd/tools/gvpack.c
cmd/tools/gxl2gv.c
cmd/tools/mmio.c
cmd/tools/sccmap.c
doc/libgraph/sccmap.c
lib/circogen/blockpath.c
lib/circogen/blocktree.c
lib/circogen/circular.c
lib/common/colxlate.c
lib/common/diagen.c
lib/common/htmltable.c
lib/common/ns.c
lib/common/output.c
lib/common/picgen.c
lib/common/postproc.c
lib/common/routespl.c
lib/common/splines.c
lib/dotgen/dotinit.c
lib/dotgen/fastgr.c
lib/dotgen/mincross.c
lib/dotgen/rank.c
lib/fdpgen/comp.c
lib/gvc/gvc.c
lib/gvc/gvdevice.c
lib/gvpr/actions.c
lib/gvpr/compile.c
lib/inkpot/data/xcolors.c
lib/inkpot/inkpot_scheme.c
lib/neatogen/constraint.c
lib/neatogen/multispline.c
lib/neatogen/neatoinit.c
lib/patchwork/patchwork.c
lib/sfdpgen/post_process.c
lib/sfdpgen/spring_electrical.c
lib/sparse/DotIO.c
plugin/core/gvrender_core_dia.c
plugin/core/gvrender_core_dot.c
plugin/gs/gvloadimage_gs.c
tclpkg/gdtclft/gdtclft.c
tclpkg/tcldot/tcldot-util.c
tclpkg/tclpathplan/tclpathplan.c
tclpkg/tkspline/tkspline.c
tests/unit_tests/lib/common/command_line.c

index 95ad83f38542634c04d701d16697c3ba3286b41d..2ca213402e58cbc33641a902dd30e2e89b203aba 100644 (file)
@@ -71,7 +71,7 @@ static graph_t *create_test_graph(void)
 
     /* Add nodes */
     for (j = 0; j < NUMNODES; j++) {
-       sprintf(name, "%d", j);
+       snprintf(name, sizeof(name), "%d", j);
        node[j] = agnode(g, name, 1);
        agbindrec(node[j], "Agnodeinfo_t", sizeof(Agnodeinfo_t), TRUE); //node custom data
     }
index ee618073a3f5e6793cc0e71345cc952c9146cc87..fec5799fa830af8ebe2ef6136321be609a06414e 100644 (file)
@@ -62,15 +62,13 @@ int APIENTRY WinMain (
         exit(0);
     }
     if (lpCmdLine[0] == 0)
-        sprintf (
-           cmd, "%s -e \"load('dotty.lefty');%sdotty.init();dotty.createviewandgraph(null,'file',null,null);txtview('off');\"",
-           path, lneato
-        );
+        snprintf(cmd, sizeof(cmd), "%s -e \"load('dotty.lefty');%sdotty.init();"
+                 "dotty.createviewandgraph(null,'file',null,null);"
+                 "txtview('off');\"", path, lneato);
     else
-        sprintf (
-           cmd, "%s -e \"load('dotty.lefty');%sdotty.init();dotty.createviewandgraph('%Ns','file',null,null);txtview('off');\"",
-            path, lneato, lpCmdLine
-        );
+        snprintf(cmd, sizeof(cmd), "%s -e \"load('dotty.lefty');%sdotty.init();"
+                 "dotty.createviewandgraph('%Ns','file',null,null);"
+                 "txtview('off');\"", path, lneato, lpCmdLine);
 
     CreateProcess (
         NULL,   // No module name (use command line). 
index 714f9d854a8f7264238df4a245e09fcbbc80bfb9..754c4addac866fa18680c3c13689e0b29ae3c682 100644 (file)
@@ -308,7 +308,7 @@ char *buildcommand (char *path, char *host, int infd, int outfd, char *fmt) {
                 if (infd == -1)
                     buf[0] = '%', buf[1] = 'd', buf[2] = '\000';
                 else
-                    sprintf (buf, "%d", infd);
+                    snprintf(buf, sizeof(buf), "%d", infd);
                 s1++;
                 if (bufi + strlen (buf) >= CMDINCR)
                     return NULL;
@@ -319,7 +319,7 @@ char *buildcommand (char *path, char *host, int infd, int outfd, char *fmt) {
                 if (outfd == -1)
                     buf[0] = '%', buf[1] = 'd', buf[2] = '\000';
                 else
-                    sprintf (buf, "%d", outfd);
+                    snprintf(buf, sizeof(buf), "%d", outfd);
                 s1++;
                 if (bufi + strlen (buf) >= CMDINCR)
                     return NULL;
index 223181ee9838506379aa87dd0bccbaf4cd60bb1d..202c332e085a023ba37ecc048e8beb4e919f0ca0 100644 (file)
@@ -373,7 +373,7 @@ void D2Lwritegraph (int ioi, Tobj graph, int flag) {
             if ((to = Tfinds (edge, "attr")))
                 writeattr (ioi, to, buf);
             if (flag) {
-                sprintf (buf, "\t\tid = %d", i);
+                snprintf(buf, sizeof(buf), "\t\tid = %d", i);
                 IOwriteline (ioi, buf);
             }
             IOwriteline (ioi, "\t]");
index 9401122fb4c29e616390610562e72369a680cdeb..69609fc45974b91e9b430640602f7551f23f9cc7 100644 (file)
@@ -1191,11 +1191,11 @@ int GFXdisplaymenu (int argc, lvar_t *argv) {
             entries[0] = Tgetstring (meo);
             break;
         case T_INTEGER:
-            sprintf (buf, "%d", (int) Tgetnumber (meo));
+            snprintf(buf, sizeof(buf), "%d", (int) Tgetnumber (meo));
             entries[0] = &buf[0];
             break;
         case T_REAL:
-            sprintf (buf, "%f", Tgetnumber (meo));
+            snprintf(buf, sizeof(buf), "%f", Tgetnumber (meo));
             entries[0] = &buf[0];
             break;
         }
index 860acea223d8f3b541ced11dd07aff8b2297c0a3..695e7dba575e0728bc4bfa4659c95020a6e40277 100644 (file)
@@ -485,14 +485,14 @@ int Iconcat (int argc, lvar_t *argv) {
         case T_INTEGER:
             if (bufi + 50 > bufn)
                 growbufp (bufi + 50);
-            sprintf (buf2, "%ld", Tgetinteger (ao));
+            snprintf(buf2, sizeof(buf2), "%ld", Tgetinteger (ao));
             for (s = buf2; *s; s++)
                 bufp[bufi++] = *s;
             break;
         case T_REAL:
             if (bufi + 50 > bufn)
                 growbufp (bufi + 50);
-            sprintf (buf2, "%f", Tgetreal (ao));
+            snprintf(buf2, sizeof(buf2), "%f", Tgetreal (ao));
             for (s = buf2; *s; s++)
                 bufp[bufi++] = *s;
             break;
@@ -520,11 +520,11 @@ int Iquote (int argc, lvar_t *argv) {
         s = Tgetstring (so);
         break;
     case T_INTEGER:
-        sprintf (buf2, "%ld", Tgetinteger (so));
+        snprintf(buf2, sizeof(buf2), "%ld", Tgetinteger (so));
         s = &buf2[0];
         break;
     case T_REAL:
-        sprintf (buf2, "%f", Tgetreal (so));
+        snprintf(buf2, sizeof(buf2), "%f", Tgetreal (so));
         s = &buf2[0];
         break;
     }
index 0e34ee8caec08cfbdec3d76f19c2d9a39f043b69..adca07e34fce3b3a0fd863364384391040cd0c1d 100644 (file)
@@ -382,9 +382,9 @@ static int findpty (int *fd) {
 
     for (majorp = ptymajor; *majorp; majorp++) {
         for (minorp = ptyminor; *minorp; minorp++) {
-            sprintf (pty, "/dev/pty%c%c", *majorp, *minorp);
+            snprintf(pty, sizeof(pty), "/dev/pty%c%c", *majorp, *minorp);
             if ((fd[0] = open (pty, O_RDWR)) >= 0) {
-                sprintf (tty, "/dev/tty%c%c", *majorp, *minorp);
+                snprintf(tty, sizeof(tty), "/dev/tty%c%c", *majorp, *minorp);
                 if ((fd[1] = open (tty, O_RDWR)) >= 0) {
 #ifndef HAVE_TERMIOS_H
                     ioctl (fd[1], TCGETA, &tio);
@@ -420,7 +420,7 @@ static void pipeopen (char *cmd, FILE **ifp, FILE **ofp, int *pidp) {
         close (p1[0]), close (p2[1]);
         for (s = cmd; *s; s++)
             if (strncmp(s, "%d", 2) == 0) {
-                sprintf (cmd2, cmd, p2[0], p1[1]);
+                snprintf(cmd2, sizeof(cmd2), cmd, p2[0], p1[1]);
                 execl (shell, shbname, "-c", cmd2, NULL);
                 panic2 (POS, "pipeopen", "child cannot exec: %s\n", cmd2);
             }
index ea3421add6aac7563990e9a66d711989f8b3010a..512010abbdb208e1d72db469fc86446fdac1ba0d 100644 (file)
@@ -49,9 +49,12 @@ int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
         exit(0);
     }
     if (lpCmdLine[0] == 0)
-        sprintf (cmd, "%s -e \"load('dotty.lefty');dotty.protogt.lserver='neato';dotty.simple(null);\"", path);
+        snprintf(cmd, sizeof(cmd), "%s -e \"load('dotty.lefty');"
+                 "dotty.protogt.lserver='neato';dotty.simple(null);\"", path);
     else
-        sprintf (cmd, "%s -e \"load('dotty.lefty');dotty.protogt.lserver='neato';dotty.simple('%Ns');\"", path, lpCmdLine);
+        snprintf(cmd, sizeof(cmd), "%s -e \"load('dotty.lefty');"
+                 "dotty.protogt.lserver='neato';dotty.simple('%Ns');\"", path,
+                 lpCmdLine);
 
     handle = WinExec (cmd, SW_SHOW);
     exit (0);
index ba52d171b2b4022b92230bb3eb786a6a3620f2c3..a4e1433753ec43a452595b7fbd00a87a706fae0f 100644 (file)
@@ -759,7 +759,8 @@ attr_list *load_attr_list(Agraph_t * g)
     sel_edge = edgeCnt;
     sel_graph = 1;
 
-    sprintf(buf, "%d Nodes and %d edges selected", nodeCnt, edgeCnt);
+    snprintf(buf, sizeof(buf), "%d Nodes and %d edges selected", nodeCnt,
+             edgeCnt);
     gtk_label_set_text((GtkLabel *) glade_xml_get_widget(xml, "label124"),
                       buf);
     gtk_entry_set_text((GtkEntry *) glade_xml_get_widget(xml, "txtAttr"),
index 2766f50e645e25b57320afcde7071aa0cb021640..31486ad1995764b60a37353c98664c5af60d77ba 100644 (file)
@@ -94,7 +94,7 @@ static int get_color_button_widget_to_attribute(char *attribute,
     gtk_color_button_get_color((GtkColorButton *)
                               glade_xml_get_widget(xml, widget_name),
                               &color);
-    sprintf(buf, "#%02x%02x%02x",
+    snprintf(buf, sizeof(buf), "#%02x%02x%02x",
            (int) ((float) color.red / 65535.0 * 255.0),
            (int) ((float) color.green / 65535.0 * 255.0),
            (int) ((float) color.blue / 65535.0 * 255.0));
@@ -171,7 +171,7 @@ static int get_checkbox_widget_to_attribute(char *attribute,
     value = (int) gtk_toggle_button_get_active((GtkToggleButton *)
                                               glade_xml_get_widget(xml,
                                                                    widget_name));
-    sprintf(buf, "%d", value);
+    snprintf(buf, sizeof(buf), "%d", value);
     agattr(g, AGRAPH, attribute, buf);
    return 1;
 }
@@ -207,7 +207,7 @@ static int get_spinbtn_widget_to_attribute(char *attribute,
     value = (float) gtk_spin_button_get_value((GtkSpinButton *)
                                              glade_xml_get_widget(xml,
                                                                   widget_name));
-    sprintf(buf, "%f", value);
+    snprintf(buf, sizeof(buf), "%f", value);
     agattr(g, AGRAPH, attribute, buf);
     return 1;
 }
@@ -222,7 +222,7 @@ static int get_scalebtn_widget_to_attribute(char *attribute,
     value = (float) gtk_range_get_value((GtkRange *)
                                        glade_xml_get_widget(xml,
                                                             widget_name));
-    sprintf(buf, "%f", value);
+    snprintf(buf, sizeof(buf), "%f", value);
     agattr(g, AGRAPH, attribute, buf);
     return 1;
 }
@@ -286,7 +286,7 @@ static int get_combobox_widget_to_attribute(char *attribute,
        gtk_combo_box_get_active((GtkComboBox *)
                                 glade_xml_get_widget(xml, widget_name));
 
-    sprintf(buf, "%d", value);
+    snprintf(buf, sizeof(buf), "%d", value);
     agattr(g, AGRAPH, attribute, buf);
     /* printf ("%s %f \n",attribute,value); */
     return 1;
index da64bc8cf9ca3385221c81bec5ccc6f6715cce99..947c1a42ec997097b77c998dac93c51d6e3f6779 100644 (file)
@@ -107,7 +107,7 @@ int run_gvpr(Agraph_t * srcGraph, int argc, char *argv[])
     } else if (opts.n_outgraphs) 
     {
        refreshViewport(0);
-       sprintf(buf, "<%d>", ++count);
+       snprintf(buf, sizeof(buf), "<%d>", ++count);
        if (opts.outgraphs[0] != view->g[view->activeGraph])
            add_graph_to_viewport(opts.outgraphs[0], buf);
        if (opts.n_outgraphs > 1)
index 91e2fec9fb624671f306ba88269e23eab47c95b4..73a1db7db202fdbb952d8a4a972a731cef212a1a 100644 (file)
@@ -884,7 +884,7 @@ static void movenode(void *obj, float dx, float dy)
 
     if ((AGTYPE(obj) == AGNODE) && (pos = agattrsym(obj, "pos"))) {
        sscanf(agxget(obj, pos), "%lf,%lf", &x, &y);
-       sprintf(buf, "%lf,%lf", x - dx, y - dy);
+       snprintf(buf, sizeof(buf), "%lf,%lf", x - dx, y - dy);
        agxset(obj, pos, buf);
     }
 }
index 12eab7f792ba1aee28fd33f6d3a461e8513c6665..1424e05dd0f00840a58eeb14d7248f2cecc196d3 100644 (file)
@@ -140,7 +140,7 @@ static int show_camera_settings(viewport_camera * c)
 {
 
     char buf[50];
-    sprintf(buf, "Camera:%i", c->index);
+    snprintf(buf, sizeof(buf), "Camera:%i", c->index);
     gtk_label_set_text((GtkLabel *)
                       glade_xml_get_widget(xml, "dlgcameralabel1"), buf);
     gtk_spin_button_set_value((GtkSpinButton *)
@@ -279,7 +279,7 @@ void attach_camera_widget(ViewInfo * view)
                                          (GLfloat) PANEL_PADDING)) -
            (GLfloat) CAMERA_BUTTON_HEIGHT;
        x = PANEL_PADDING;
-       sprintf(buf, "CAM%i", ind + 1);
+       snprintf(buf, sizeof(buf), "CAM%i", ind + 1);
        b = glCompButtonNew((GLfloat) x, (GLfloat) y,
                            (GLfloat) CAMERA_BUTTON_WIDTH,
                            (GLfloat) CAMERA_BUTTON_HEIGHT, buf, '\0', 0,
index 655b4029bdbff0d163fb5844472d87a604348725..1a49585a0468345b5bedb34691e496d3b8efd0c3 100644 (file)
@@ -163,13 +163,13 @@ static void post(Agraph_t * g)
        psym = agattr(g, AGNODE, "prev", "");
 
     if (setall)
-       sprintf(dflt, "%.3lf", HUGE);
+       snprintf(dflt, sizeof(dflt), "%.3lf", HUGE);
 
     for (v = agfstnode(g); v; v = agnxtnode(g, v)) {
        dist = getdist(v);
        if (dist) {
            dist--;
-           sprintf(buf, "%.3lf", dist);
+           snprintf(buf, sizeof(buf), "%.3lf", dist);
            agxset(v, sym, buf);
            if (doPath && (prev = getprev(v)))
                agxset(v, psym, agnameof(prev));
@@ -189,10 +189,10 @@ static void post(Agraph_t * g)
            if (oldmax > maxdist)
                maxdist = oldmax;
        }
-       sprintf(buf, "%.3lf", maxdist);
+       snprintf(buf, sizeof(buf), "%.3lf", maxdist);
        agxset(g, sym, buf);
     } else {
-       sprintf(buf, "%.3lf", maxdist);
+       snprintf(buf, sizeof(buf), "%.3lf", maxdist);
        agattr(g, AGRAPH, "maxdist", buf);
     }
 
index 1192a3355d9f5d14acebce83b2c11a58c3fc75da..ee22c34fa774e7f3c8603a2ffa7e85e377eb2bed 100644 (file)
@@ -569,12 +569,12 @@ addNodeGraphics (Agnode_t* np, Dt_t* alist, agxbuf* xb, agxbuf* unk)
        }
        else if (ap->sort == WVAL) {
            d = atof (ap->u.value);
-           sprintf (buf, "%.04f", d/72.0);
+           snprintf(buf, sizeof(buf), "%.04f", d/72.0);
            agsafeset (np, "width", buf, "");
        }
        else if (ap->sort == HVAL) {
            d = atof (ap->u.value);
-           sprintf (buf, "%.04f", d/72.0);
+           snprintf(buf, sizeof(buf), "%.04f", d/72.0);
            agsafeset (np, "height", buf, "");
        }
        else if (ap->sort == TYPE) {
index adcd69e4843e1c9ff90c0c76cfe6fbda200937b6..2af7d955328a13cac9d9ec1a52d7a96faf0bc751 100644 (file)
@@ -451,7 +451,7 @@ startElementHandler(void *userData, const char *name, const char **atts)
            Agraph_t *subg;
            if (isAnonGraph((char *) id)) {
                static int anon_id = 1;
-               sprintf(buf, "%%%d", anon_id++);
+               snprintf(buf, sizeof(buf), "%%%d", anon_id++);
                id = buf;
            }
            subg = agsubg(G, (char *) id, 1);
index d3f2af36b51bdd40ba79120fca1efd8bf137e246..79671f6cd4e3fb13cd182a23bb2136917b3bf0b4 100644 (file)
@@ -277,7 +277,7 @@ static char *createGraphId(Dt_t * ids)
     char buf[SMALLBUF];
 
     do {
-       sprintf(buf, "G_%d", graphIdCounter++);
+       snprintf(buf, sizeof(buf), "G_%d", graphIdCounter++);
     } while (idexists(ids, buf));
     return addid(ids, buf);
 }
@@ -288,7 +288,7 @@ static char *createNodeId(Dt_t * ids)
     char buf[SMALLBUF];
 
     do {
-       sprintf(buf, "N_%d", nodeIdCounter++);
+       snprintf(buf, sizeof(buf), "N_%d", nodeIdCounter++);
     } while (idexists(ids, buf));
     return addid(ids, buf);
 }
index 07ff741a1297c0bfc34615c05d3185e2af741e48..e32d7bf005a5a4d11749bf4ff9ed48174cdf7625 100644 (file)
@@ -221,7 +221,7 @@ static void color(Agraph_t * g)
            s = Defcolor[1];
            b = Defcolor[2];
        }
-       sprintf(buf, "%f %f %f", h, s, b);
+       snprintf(buf, sizeof(buf), "%f %f %f", h, s, b);
        agset(n, "color", buf);
     }
     free (nlist);
index e32eb21da0a02b7386749468bcecc4abe3cb2d1e..8760a97ec4644a44f93a08f5588c6b7631b83d8e 100644 (file)
@@ -529,7 +529,7 @@ static void redoBB(Agraph_t * g, char *s, Agsym_t * G_bb, point delta)
        bb.LL.y += delta.y;
        bb.UR.x += delta.x;
        bb.UR.y += delta.y;
-       sprintf(buf, "%d,%d,%d,%d", bb.LL.x, bb.LL.y, bb.UR.x, bb.UR.y);
+       snprintf(buf, sizeof(buf), "%d,%d,%d,%d", bb.LL.x, bb.LL.y, bb.UR.x, bb.UR.y);
        agxset(g, G_bb->index, buf);
     }
 }
index ecd884b2205f20a703be860df3e88ab95e880aaa..ed5a3485a6997b7cd9ff71e490ea3469816a33c4 100644 (file)
@@ -446,7 +446,7 @@ startElementHandler(void *userData, const char *name, const char **atts)
            Agraph_t *subg;
            if (isAnonGraph((char *) id)) {
                static int anon_id = 1;
-               sprintf(buf, "%%%d", anon_id++);
+               snprintf(buf, sizeof(buf), "%%%d", anon_id++);
                id = buf;
            }
            subg = agsubg(G, (char *) id, 1);
index 9786c465d88c1557f4fb431a205a81e55e592efe..8da974018911724652e1a8b61e6607dab58ddc22 100644 (file)
@@ -482,7 +482,8 @@ char *mm_typecode_to_str(MM_typecode matcode)
     else
        return NULL;
 
-    sprintf(buffer, "%s %s %s %s", types[0], types[1], types[2], types[3]);
+    snprintf(buffer, sizeof(buffer), "%s %s %s %s", types[0], types[1],
+             types[2], types[3]);
     return strdup(buffer);
 
 }
index 0529602c7e01109e84b20c2b5524714679f0c27d..1a0039b4db56858f5469739c5884ffb734ba0e16 100644 (file)
@@ -184,7 +184,7 @@ static int visit(Agnode_t * n, Agraph_t * map, Stack * sp, sccstate * st)
        } else {
            char name[32];
            Agraph_t *G = agraphof(n);;
-           sprintf(name, "cluster_%d", (st->Comp)++);
+           snprintf(name, sizeof(name), "cluster_%d", (st->Comp)++);
            subg = agsubg(G, name, TRUE);
            agbindrec(subg, "scc_graph", sizeof(Agraphinfo_t), TRUE);
            setrep(subg, agnode(map, name, TRUE));
index d8d91f34dd176aed163e71e38b2bc5c69177f228..4d042e30597565d10a22f6e9075dfe581c86351d 100644 (file)
@@ -139,7 +139,7 @@ static int visit(Agnode_t * n, Agraph_t * map, Stack * sp, sccstate * st)
                } else {
                        char name[32];
                        Agraph_t *G = agraphof(n);;
-                       sprintf(name, "cluster_%d", (st->Comp)++);
+                       snprintf(name, sizeof(name), "cluster_%d", (st->Comp)++);
                        subg = agsubg(G, name, TRUE);
                        agbindrec(subg, "scc_graph", sizeof(Agraphinfo_t), TRUE);
                        setrep(subg, agnode(map, name, TRUE));
index 8ed625359b2633dd19add4ce927171bc74c7855e..33fc7080dad94dcdacfc9d8643b1df1bd63d710d 100644 (file)
@@ -38,10 +38,10 @@ static Agraph_t *clone_graph(Agraph_t * ing, Agraph_t ** xg)
     char gname[SMALLBUF];
     static int id = 0;
 
-    sprintf(gname, "_clone_%d", id++);
+    snprintf(gname, sizeof(gname), "_clone_%d", id++);
     clone = agsubg(ing, gname,1);
     agbindrec(clone, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE);      //node custom data
-    sprintf(gname, "_clone_%d", id++);
+    snprintf(gname, sizeof(gname), "_clone_%d", id++);
     xclone = agopen(gname, ing->desc,NULL);
     for (n = agfstnode(ing); n; n = agnxtnode(ing, n)) {
        agsubnode(clone,n,1);
@@ -360,7 +360,7 @@ static Agraph_t *spanning_tree(Agraph_t * g)
     char gname[SMALLBUF];
     static int id = 0;
 
-    sprintf(gname, "_span_%d", id++);
+    snprintf(gname, sizeof(gname), "_span_%d", id++);
     tree = agsubg(g, gname,1);
     agbindrec(tree, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE);       //node custom data
 
index 20d4d8ec43dc46a81582ec81068839629bb1fb9d..6adae54790b214b4e60d066e9137ba3c5669e81e 100644 (file)
@@ -22,7 +22,7 @@ static Agraph_t *makeBlockGraph(Agraph_t * g, circ_state * state)
     char name[SMALLBUF];
     Agraph_t *subg;
 
-    sprintf(name, "_block_%d", state->blockCount++);
+    snprintf(name, sizeof(name), "_block_%d", state->blockCount++);
     subg = agsubg(g, name,1);
     agbindrec(subg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE);       //node custom data
     return subg;
index 2032b136e9da123e86d0243382886704c5dbe933..dedbc1a3aaf1008157359c7f7da84c320f7a2340 100644 (file)
@@ -66,7 +66,7 @@ createOneBlock(Agraph_t * g, circ_state * state)
     block_t *bp;
     Agnode_t* n;
 
-    sprintf(name, "_block_%d", state->blockCount++);
+    snprintf(name, sizeof(name), "_block_%d", state->blockCount++);
     subg = agsubg(g, name, 1);
     bp = mkBlock(subg);
 
index b83373223448df3fa06248e78f1832b9b4604a19..0ebe55b28a63db0a7654405b1f3d5df8168c45bb 100644 (file)
@@ -507,20 +507,22 @@ int colorCvt(gvcolor_t *ocolor, gvcolor_t *ncolor)
     s = buf;
     switch (ocolor->type) {
     case HSVA_DOUBLE :
-       sprintf (buf, "%.03f %.03f %.03f %.03f", 
+       snprintf(buf, sizeof(buf), "%.03f %.03f %.03f %.03f",
            ocolor->u.HSVA[0], ocolor->u.HSVA[1], ocolor->u.HSVA[2], ocolor->u.HSVA[3]);
        break;
     case RGBA_BYTE :
-       sprintf (buf, "#%02x%02x%02x%02x", 
+       snprintf(buf, sizeof(buf), "#%02x%02x%02x%02x",
            ocolor->u.rgba[0], ocolor->u.rgba[1], ocolor->u.rgba[2], ocolor->u.rgba[3]);
        break;
     case RGBA_WORD:
        rgba_wordToByte (ocolor->u.rrggbbaa, rgba);
-       sprintf (buf, "#%02x%02x%02x%02x", rgba[0], rgba[1], rgba[2], rgba[3]);
+       snprintf(buf, sizeof(buf), "#%02x%02x%02x%02x", rgba[0], rgba[1], rgba[2],
+                rgba[3]);
        break;
     case RGBA_DOUBLE:
        rgba_dblToByte (ocolor->u.RGBA, rgba);
-       sprintf (buf, "#%02x%02x%02x%02x", rgba[0], rgba[1], rgba[2], rgba[3]);
+       snprintf(buf, sizeof(buf), "#%02x%02x%02x%02x", rgba[0], rgba[1], rgba[2],
+                rgba[3]);
        break;
     case COLOR_STRING:
        s = ocolor->u.string;
index dbe2d9812e4c991515c324af3e4d6e8a90bf2626..3f5016ab8a95e602bf90357465ac116535b387cb 100644 (file)
@@ -188,8 +188,8 @@ static char *dia_resolve_color(char *name)
             tok = "none";
         } else {
             colorxlate(name, &color, RGBA_BYTE);
-            sprintf(buf, "#%02x%02x%02x",
-                    color.u.rgba[0], color.u.rgba[1], color.u.rgba[2]);
+            snprintf(buf, sizeof(buf), "#%02x%02x%02x",
+                     color.u.rgba[0], color.u.rgba[1], color.u.rgba[2]);
             tok = buf;
         }
     }
index 555e9b6646f6354c4da13ac7d853729b6e78a7bc..2377f2629680a03e594c25605635e3e2b551f990 100644 (file)
@@ -1376,7 +1376,7 @@ static char *nToName(int c)
     if (c < sizeof(nnames) / sizeof(char *))
        return nnames[c];
 
-    sprintf(name, "%d", c);
+    snprintf(name, sizeof(name), "%d", c);
     return name;
 }
 
index 1a71490cb985e2c5c57f2a09c84e0c30117041c5..6793792f91959ffe2c03bde9dcfe1d7cf6748cf8 100644 (file)
@@ -1103,7 +1103,7 @@ static char* dump_node (node_t* n)
     static char buf[50];
 
     if (ND_node_type(n)) {
-       sprintf(buf, "%p", n);
+       snprintf(buf, sizeof(buf), "%p", n);
        return buf;
     }
     else
index 249c418f5aeabadbb9cd0d861e78fa7dad6f7fe8..71c7bc7b682db7a2f1ad2763efc79a44526adc27 100644 (file)
@@ -49,7 +49,7 @@ static void printint(FILE * f, char *prefix, int i)
     char buf[BUFSIZ];
     
     if (prefix) agputs(prefix, f);
-    sprintf(buf, "%d", i);
+    snprintf(buf, sizeof(buf), "%d", i);
     agputs(buf, f);
 }
 
@@ -58,7 +58,7 @@ static void printdouble(FILE * f, char *prefix, double v)
     char buf[BUFSIZ];
     
     if (prefix) agputs(prefix, f);
-    sprintf(buf, "%.5g", v);
+    snprintf(buf, sizeof(buf), "%.5g", v);
     agputs(buf, f);
 }
 
@@ -192,7 +192,7 @@ static void set_record_rects(node_t * n, field_t * f, agxbuf * xb)
     char buf[BUFSIZ];
 
     if (f->n_flds == 0) {
-       sprintf(buf, "%.5g,%.5g,%.5g,%.5g ",
+       snprintf(buf, sizeof(buf), "%.5g,%.5g,%.5g,%.5g ",
                f->b.LL.x + ND_coord(n).x,
                YDIR(f->b.LL.y + ND_coord(n).y),
                f->b.UR.x + ND_coord(n).x,
@@ -209,17 +209,17 @@ static void rec_attach_bb(graph_t * g, Agsym_t* bbsym, Agsym_t* lpsym, Agsym_t*
     char buf[BUFSIZ];
     pointf pt;
 
-    sprintf(buf, "%.5g,%.5g,%.5g,%.5g", GD_bb(g).LL.x, YDIR(GD_bb(g).LL.y),
-           GD_bb(g).UR.x, YDIR(GD_bb(g).UR.y));
+    snprintf(buf, sizeof(buf), "%.5g,%.5g,%.5g,%.5g", GD_bb(g).LL.x,
+             YDIR(GD_bb(g).LL.y), GD_bb(g).UR.x, YDIR(GD_bb(g).UR.y));
     agxset(g, bbsym, buf);
     if (GD_label(g) && GD_label(g)->text[0]) {
        pt = GD_label(g)->pos;
-       sprintf(buf, "%.5g,%.5g", pt.x, YDIR(pt.y));
+       snprintf(buf, sizeof(buf), "%.5g,%.5g", pt.x, YDIR(pt.y));
        agxset(g, lpsym, buf);
        pt = GD_label(g)->dimen;
-       sprintf(buf, "%.2f", PS2INCH(pt.x));
+       snprintf(buf, sizeof(buf), "%.2f", PS2INCH(pt.x));
        agxset (g, lwsym, buf);
-       sprintf(buf, "%.2f", PS2INCH(pt.y));
+       snprintf(buf, sizeof(buf), "%.2f", PS2INCH(pt.y));
        agxset (g, lhsym, buf);
     }
     for (c = 1; c <= GD_n_cluster(g); c++)
@@ -278,16 +278,17 @@ void attach_attrs_and_arrows(graph_t* g, int* sp, int* ep)
            }
            agset(n, "pos", agxbuse(&xb));
        } else {
-           sprintf(buf, "%.5g,%.5g", ND_coord(n).x, YDIR(ND_coord(n).y));
+           snprintf(buf, sizeof(buf), "%.5g,%.5g", ND_coord(n).x,
+                    YDIR(ND_coord(n).y));
            agset(n, "pos", buf);
        }
-       sprintf(buf, "%.5g", PS2INCH(ND_ht(n)));
+       snprintf(buf, sizeof(buf), "%.5g", PS2INCH(ND_ht(n)));
        agxset(n, N_height, buf);
-       sprintf(buf, "%.5g", PS2INCH(ND_lw(n) + ND_rw(n)));
+       snprintf(buf, sizeof(buf), "%.5g", PS2INCH(ND_lw(n) + ND_rw(n)));
        agxset(n, N_width, buf);
        if (ND_xlabel(n) && ND_xlabel(n)->set) {
            ptf = ND_xlabel(n)->pos;
-           sprintf(buf, "%.5g,%.5g", ptf.x, YDIR(ptf.y));
+           snprintf(buf, sizeof(buf), "%.5g,%.5g", ptf.x, YDIR(ptf.y));
            agset(n, "xlp", buf);
        }
        if (strcmp(ND_shape(n)->name, "record") == 0) {
@@ -335,14 +336,14 @@ void attach_attrs_and_arrows(graph_t* g, int* sp, int* ep)
                        agxbputc(&xb, ';');
                    if (ED_spl(e)->list[i].sflag) {
                        s_arrows = 1;
-                       sprintf(buf, "s,%.5g,%.5g ",
+                       snprintf(buf, sizeof(buf), "s,%.5g,%.5g ",
                                ED_spl(e)->list[i].sp.x,
                                YDIR(ED_spl(e)->list[i].sp.y));
                        agxbput(&xb, buf);
                    }
                    if (ED_spl(e)->list[i].eflag) {
                        e_arrows = 1;
-                       sprintf(buf, "e,%.5g,%.5g ",
+                       snprintf(buf, sizeof(buf), "e,%.5g,%.5g ",
                                ED_spl(e)->list[i].ep.x,
                                YDIR(ED_spl(e)->list[i].ep.y));
                        agxbput(&xb, buf);
@@ -357,22 +358,22 @@ void attach_attrs_and_arrows(graph_t* g, int* sp, int* ep)
                agset(e, "pos", agxbuse(&xb));
                if (ED_label(e)) {
                    ptf = ED_label(e)->pos;
-                   sprintf(buf, "%.5g,%.5g", ptf.x, YDIR(ptf.y));
+                   snprintf(buf, sizeof(buf), "%.5g,%.5g", ptf.x, YDIR(ptf.y));
                    agset(e, "lp", buf);
                }
                if (ED_xlabel(e) && ED_xlabel(e)->set) {
                    ptf = ED_xlabel(e)->pos;
-                   sprintf(buf, "%.5g,%.5g", ptf.x, YDIR(ptf.y));
+                   snprintf(buf, sizeof(buf), "%.5g,%.5g", ptf.x, YDIR(ptf.y));
                    agset(e, "xlp", buf);
                }
                if (ED_head_label(e)) {
                    ptf = ED_head_label(e)->pos;
-                   sprintf(buf, "%.5g,%.5g", ptf.x, YDIR(ptf.y));
+                   snprintf(buf, sizeof(buf), "%.5g,%.5g", ptf.x, YDIR(ptf.y));
                    agset(e, "head_lp", buf);
                }
                if (ED_tail_label(e)) {
                    ptf = ED_tail_label(e)->pos;
-                   sprintf(buf, "%.5g,%.5g", ptf.x, YDIR(ptf.y));
+                   snprintf(buf, sizeof(buf), "%.5g,%.5g", ptf.x, YDIR(ptf.y));
                    agset(e, "tail_lp", buf);
                }
            }
index f0cc06e3f0fff12361816a7a8e1ad3972e0c70ab..638b29b23dd9cc27aedd6919f7429bb49137d003 100644 (file)
@@ -466,7 +466,7 @@ static void pic_set_style(char **s)
            if (!strcmp(line, "setlinewidth")) {        /* a hack to handle the user-defined (PS) style spec in proc3d.dot */
                long n = atol(p);
 
-               sprintf(buf,
+               snprintf(buf, sizeof(buf),
                        "oldlinethick = linethick;linethick = %ld * scalethickness / %.0f\n",
                        n, Fontscale / Scale);
                skip = 1;
index 8bef78a3e7ef0e45eb4a8bf12d56aa7d20c58e7f..51fb5215bb4f2da76d2b0f55c36200bf80e42c4a 100644 (file)
@@ -677,9 +677,9 @@ void gv_postprocess(Agraph_t * g, int allowTranslation)
     if (Show_boxes) {
        char buf[BUFSIZ];
        if (Flip)
-           sprintf(buf, M2, Offset.x, Offset.y, Offset.x, Offset.y);
+           snprintf(buf, sizeof(buf), M2, Offset.x, Offset.y, Offset.x, Offset.y);
        else
-           sprintf(buf, M1, Offset.y, Offset.x, Offset.y, Offset.x,
+           snprintf(buf, sizeof(buf), M1, Offset.y, Offset.x, Offset.y, Offset.x,
                    -Offset.x, -Offset.y);
        Show_boxes[0] = strdup(buf);
     }
index b7c07c70b41b3894a59c7590f7c42c8358b7f607..6b1456c4c7de00acaba2e681a712ff84c9f7d1b5 100644 (file)
@@ -47,7 +47,8 @@ static void printboxes(int boxn, boxf* boxes)
     Show_boxes = ALLOC(newcnt+2,Show_boxes,char*);
     for (bi = 0; bi < boxn; bi++) {
        ll = boxes[bi].LL, ur = boxes[bi].UR;
-       sprintf(buf, "%d %d %d %d pathbox", (int)ll.x, (int)ll.y, (int)ur.x, (int)ur.y);
+       snprintf(buf, sizeof(buf), "%d %d %d %d pathbox", (int)ll.x, (int)ll.y,
+                (int)ur.x, (int)ur.y);
        Show_boxes[bi+1+Show_cnt] = strdup (buf);
     }
     Show_cnt = newcnt;
@@ -103,7 +104,7 @@ static void psprintspline(Ppolyline_t spl)
     Show_boxes[li++] = strdup ("%% spline");
     Show_boxes[li++] = strdup ("gsave 1 0 0 setrgbcolor newpath");
     for (i = 0; i < spl.pn; i++) {
-       sprintf(buf, "%f %f %s", spl.ps[i].x, spl.ps[i].y,
+       snprintf(buf, sizeof(buf), "%f %f %s", spl.ps[i].x, spl.ps[i].y,
          (i == 0) ?  "moveto" : ((i % 3 == 0) ? "curveto" : ""));
        Show_boxes[li++] = strdup (buf);
     }
@@ -124,7 +125,7 @@ static void psprintline(Ppolyline_t pl)
     Show_boxes[li++] = strdup ("%% line");
     Show_boxes[li++] = strdup ("gsave 0 0 1 setrgbcolor newpath");
     for (i = 0; i < pl.pn; i++) {
-       sprintf(buf, "%f %f %s", pl.ps[i].x, pl.ps[i].y,
+       snprintf(buf, sizeof(buf), "%f %f %s", pl.ps[i].x, pl.ps[i].y,
                (i == 0 ? "moveto" : "lineto"));
        Show_boxes[li++] = strdup (buf);
     }
@@ -152,7 +153,8 @@ static void psprintpoly(Ppoly_t p)
        hd.y = (int)p.ps[(bi+1) % p.pn].y;
        if ((tl.x == hd.x) && (tl.y == hd.y)) pfx = "%%";
        else pfx ="";
-       sprintf(buf, "%s%d %d %d %d makevec", pfx, tl.x, tl.y, hd.x, hd.y);
+       snprintf(buf, sizeof(buf), "%s%d %d %d %d makevec", pfx, tl.x, tl.y, hd.x,
+                hd.y);
        Show_boxes[li++] = strdup (buf);
     }
     Show_boxes[li++] = strdup ("grestore");
@@ -174,13 +176,13 @@ static void psprintboxes(int boxn, boxf* boxes)
     Show_boxes[li++] = strdup ("gsave 0 1 0 setrgbcolor");
     for (bi = 0; bi < boxn; bi++) {
        ll = boxes[bi].LL, ur = boxes[bi].UR;
-       sprintf(buf, "newpath\n%d %d moveto", (int)ll.x, (int)ll.y);
+       snprintf(buf, sizeof(buf), "newpath\n%d %d moveto", (int)ll.x, (int)ll.y);
        Show_boxes[li++] = strdup (buf);
-       sprintf(buf, "%d %d lineto", (int)ll.x, (int)ur.y);
+       snprintf(buf, sizeof(buf), "%d %d lineto", (int)ll.x, (int)ur.y);
        Show_boxes[li++] = strdup (buf);
-       sprintf(buf, "%d %d lineto", (int)ur.x, (int)ur.y);
+       snprintf(buf, sizeof(buf), "%d %d lineto", (int)ur.x, (int)ur.y);
        Show_boxes[li++] = strdup (buf);
-       sprintf(buf, "%d %d lineto", (int)ur.x, (int)ll.y);
+       snprintf(buf, sizeof(buf), "%d %d lineto", (int)ur.x, (int)ll.y);
        Show_boxes[li++] = strdup (buf);
        Show_boxes[li++] = strdup ("closepath stroke");
     }
index fbbc2228018ea04138a7a162d75907c445ed79b9..c262494b977c5e1bed7d757d24cc16400b4a653d 100644 (file)
@@ -37,7 +37,7 @@ static void showPoints(pointf ps[], int pn)
     Show_boxes[li++] = strdup ("%% self list");
     Show_boxes[li++] = strdup ("dbgstart");
     for (bi = 0; bi < pn; bi++) {
-       sprintf(buf, "%.5g %.5g point", ps[bi].x, ps[bi].y);
+       snprintf(buf, sizeof(buf), "%.5g %.5g point", ps[bi].x, ps[bi].y);
        Show_boxes[li++] = strdup (buf);
     }
     Show_boxes[li++] = strdup ("grestore");
index 1e5d94bb4bdecd4c5ae469aa8a538a64b41fe7b0..4ca9288902915041c993820b794418679d244b40 100644 (file)
@@ -269,11 +269,11 @@ attach_phase_attrs (Agraph_t * g, int maxphase)
 
     for (n = agfstnode(g); n; n = agnxtnode(g,n)) {
        if (maxphase >= 1) {
-           sprintf(buf, "%d", ND_rank(n));
+           snprintf(buf, sizeof(buf), "%d", ND_rank(n));
            ag_xset(n,rk,buf);
        }
        if (maxphase >= 2) {
-           sprintf(buf, "%d", ND_order(n));
+           snprintf(buf, sizeof(buf), "%d", ND_order(n));
            ag_xset(n,order,buf);
        }
     }
index 3f2c52357cbb8db74a7bc4a3e67193cd9a892e36..9177ea2622b1bcf4648208322e3fc5e89e5eb077 100644 (file)
@@ -281,7 +281,7 @@ static char *NAME(node_t * n)
     static char buf[20];
     if (ND_node_type(n) == NORMAL)
        return agnameof(n);
-    sprintf(buf, "V%p", n);
+    snprintf(buf, sizeof(buf), "V%p", n);
     return buf;
 }
 
index f1aa29a98d611459fc645c1c80a4e5ecd4e203e6..a532122c914e86331b1f6a1064ad808d2b9f19f7 100644 (file)
@@ -86,11 +86,11 @@ static char* nname(node_t* v)
         static char buf[1000];
        if (ND_node_type(v)) {
                if (ND_ranktype(v) == CLUSTER)
-                       sprintf (buf, "v%s_%p", agnameof(ND_clust(v)), v);
+                       snprintf(buf, sizeof(buf), "v%s_%p", agnameof(ND_clust(v)), v);
                else
-                       sprintf (buf, "v_%p", v);
+                       snprintf(buf, sizeof(buf), "v_%p", v);
        } else
-               sprintf (buf, "%s", agnameof(v));
+               snprintf(buf, sizeof(buf), "%s", agnameof(v));
        return buf;
 }
 static void dumpg (graph_t* g)
@@ -302,7 +302,7 @@ checkLabelOrder (graph_t* g)
            u = rk->v[j];
            if ((e = (edge_t*)ND_alg(u))) {
                if (!lg) lg = agopen ("lg", Agstrictdirected, 0);
-               sprintf (buf, "%d", j);
+               snprintf(buf, sizeof(buf), "%d", j);
                n = agnode(lg, buf, 1);
                agbindrec(n, "info", sizeof(info_t), 1);
                lo = ND_order(aghead(ND_out(u).list[0]));
index e98d437e1c8f1e62cea13eb7584f9ab3b6cf6180..9ab55d5459924589fc0593eb33427911ffa262a6 100644 (file)
@@ -845,7 +845,7 @@ static void weak(graph_t * g, node_t * t, node_t * h, edge_t * orig)
        }
     }
     if (!e) {
-       sprintf (buf, "_weak_%d", id++);
+       snprintf(buf, sizeof(buf), "_weak_%d", id++);
        v = makeXnode(g, buf);
        e = agedge(g, v, t, 0, 1);
        f = agedge(g, v, h, 0, 1);
index 00b072b877e5779a639f9ffbe52423d3c3097024..a192d61f920f4d8349fb6a4b39a5557f5250dba9 100644 (file)
@@ -72,7 +72,7 @@ graph_t **findCComp(graph_t * g, int *cnt, int *pinned)
     /* Create component based on port nodes */
     subg = 0;
     if ((pp = PORTS(g))) {
-       sprintf(name, "cc%s_%d", agnameof(g), c_cnt++ + C_cnt);
+       snprintf(name, sizeof(name), "cc%s_%d", agnameof(g), c_cnt++ + C_cnt);
        subg = agsubg(g, name,1);
        agbindrec(subg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE);
        GD_alg(subg) = NEW(gdata);
@@ -93,7 +93,7 @@ graph_t **findCComp(graph_t * g, int *cnt, int *pinned)
        if (ND_pinned(n) != P_PIN)
            continue;
        if (!subg) {
-           sprintf(name, "cc%s_%d", agnameof(g), c_cnt++ + C_cnt);
+           snprintf(name, sizeof(name), "cc%s_%d", agnameof(g), c_cnt++ + C_cnt);
            subg = agsubg(g, name,1);
                agbindrec(subg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE);
            GD_alg(subg) = NEW(gdata);
@@ -108,7 +108,7 @@ graph_t **findCComp(graph_t * g, int *cnt, int *pinned)
     for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
        if (MARK(n))
            continue;
-       sprintf(name, "cc%s+%d", agnameof(g), c_cnt++ + C_cnt);
+       snprintf(name, sizeof(name), "cc%s+%d", agnameof(g), c_cnt++ + C_cnt);
        subg = agsubg(g, name,1);
        agbindrec(subg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE);    //node custom data
        GD_alg(subg) = NEW(gdata);
index 7428815853b8c2888241702c059dc0eccb5eca49..e9810f135f6ce6c40ae4c8a0629c279b01b00e52 100644 (file)
@@ -66,13 +66,13 @@ int gvLayout(GVC_t *gvc, graph_t *g, const char *engine)
  * doesn't yet include margins, scaling or page sizes because
  * those depend on the renderer being used. */
     if (GD_drawing(g)->landscape)
-        sprintf(buf, "%d %d %d %d",
-                ROUND(GD_bb(g).LL.y), ROUND(GD_bb(g).LL.x),
-                ROUND(GD_bb(g).UR.y), ROUND(GD_bb(g).UR.x));
+        snprintf(buf, sizeof(buf), "%d %d %d %d",
+                 ROUND(GD_bb(g).LL.y), ROUND(GD_bb(g).LL.x),
+                 ROUND(GD_bb(g).UR.y), ROUND(GD_bb(g).UR.x));
     else
-        sprintf(buf, "%d %d %d %d",
-                ROUND(GD_bb(g).LL.x), ROUND(GD_bb(g).LL.y),
-                ROUND(GD_bb(g).UR.x), ROUND(GD_bb(g).UR.y));
+        snprintf(buf, sizeof(buf), "%d %d %d %d",
+                 ROUND(GD_bb(g).LL.x), ROUND(GD_bb(g).LL.y),
+                 ROUND(GD_bb(g).UR.x), ROUND(GD_bb(g).UR.y));
     agsafeset(g, "bb", buf, "");
 
     return 0;
index fdade3b455646dee9c402d7be8c1bd77cc21ce44..c811a7d71b1ac50d515dfd06a73bb3c7ea799bc8 100644 (file)
@@ -90,7 +90,7 @@ static void auto_output_filename(GVJ_t *job)
     size_t len;
 
     if (job->graph_index)
-        sprintf(gidx, ".%d", job->graph_index + 1);
+        snprintf(gidx, sizeof(gidx), ".%d", job->graph_index + 1);
     else
         gidx[0] = '\0';
     if (!(fn = job->input_filename))
index 0f939dbab3e13f56ac2363ddb03ba9b9a8d1a51e..6e48fd65be01fd403f63a070fd1dab35c7e18ab3 100644 (file)
@@ -450,7 +450,7 @@ Agraph_t *compOf(Agraph_t * g, Agnode_t * n)
     for (np = agfstnode(g); np; np = agnxtnode(g, np))
        CCUNMARK(np);
 
-    sprintf(name, "_cc_%d", id++);
+    snprintf(name, sizeof(name), "_cc_%d", id++);
     cg = openSubg(g, name);
     cc_dfs(g, cg, n);
 
index 155900a453c812fbd37df16f3665bcb20e2701d2..c4c50a816c3b47b29af6aaccb8d41ff6644dca0e 100644 (file)
@@ -2394,7 +2394,7 @@ static int mkBlock(comp_block* bp, Expr_t * prog, char *src, parse_block *inp, S
        symbols[0].type = T_node;
        tchk[V_this][1] = Y(V);
        bp->n_nstmts = inp->n_nstmts;
-       sprintf (label, "_nd%d", i);
+       snprintf(label, sizeof(label), "_nd%d", i);
        bp->node_stmts = mkStmts(prog, src, inp->node_stmts,
                                inp->n_nstmts, label, tmps);
        if (getErrorErrors())
@@ -2407,7 +2407,7 @@ static int mkBlock(comp_block* bp, Expr_t * prog, char *src, parse_block *inp, S
        symbols[0].type = T_edge;
        tchk[V_this][1] = Y(E);
        bp->n_estmts = inp->n_estmts;
-       sprintf (label, "_eg%d", i);
+       snprintf(label, sizeof(label), "_eg%d", i);
        bp->edge_stmts = mkStmts(prog, src, inp->edge_stmts,
                                inp->n_estmts, label, tmps);
        if (getErrorErrors())
index 0617da0f5d5ae541b9c55f615a220e5659fb5df7..88f7cee2cd724de7c8a945489be1cf21624275fd 100644 (file)
@@ -890,7 +890,7 @@ XParseColor(
        }
        i /= 3;
 
-       sprintf(fmt, "%%%dx%%%dx%%%dx", i, i, i);
+       snprintf(fmt, sizeof(fmt), "%%%dx%%%dx%%%dx", i, i, i);
        if (sscanf(spec+1, fmt, &red, &green, &blue) != 3) {
            return 0;
        }
index 61a0bbb773d210676c3d3114f84b1dfab8f553d4..5454bf22f322c0da45f9d3cd9506fcdf40bca1ca 100644 (file)
@@ -640,7 +640,8 @@ inkpot_status_t inkpot_write_rgba16 ( inkpot_t *inkpot )
 
     rc = inkpot_get_rgba_i ( inkpot, rgba );
     if (rc == INKPOT_SUCCESS) {
-        len = sprintf(buf, "%04x%04x%04x%04x", rgba[0], rgba[1], rgba[2], rgba[3]);
+        len = snprintf(buf, sizeof(buf), "%04x%04x%04x%04x", rgba[0], rgba[1],
+                       rgba[2], rgba[3]);
        assert(len==16);
         inkpot->write_disc.writer(inkpot->write_closure, buf, len);
     }
@@ -656,7 +657,8 @@ inkpot_status_t inkpot_write_rgb16 ( inkpot_t *inkpot )
 
     rc = inkpot_get_rgba_i ( inkpot, rgba );
     if (rc == INKPOT_SUCCESS) {
-        len = sprintf(buf, "%04x%04x%04x", rgba[0], rgba[1], rgba[2]);
+        len = snprintf(buf, sizeof(buf), "%04x%04x%04x", rgba[0], rgba[1],
+                       rgba[2]);
        assert(len==12);
         inkpot->write_disc.writer(inkpot->write_closure, buf, len);
     }
@@ -672,7 +674,8 @@ inkpot_status_t inkpot_write_rgba8 ( inkpot_t *inkpot )
 
     rc = inkpot_get_rgba_i ( inkpot, rgba );
     if (rc == INKPOT_SUCCESS) {
-        len = sprintf(buf, "%02x%02x%02x%02x", rgba[0]>>8, rgba[1]>>8, rgba[2]>>8, rgba[3]>>8);
+        len = snprintf(buf, sizeof(buf), "%02x%02x%02x%02x", rgba[0]>>8,
+                       rgba[1]>>8, rgba[2]>>8, rgba[3]>>8);
        assert(len==8);
         inkpot->write_disc.writer(inkpot->write_closure, buf, len);
     }
@@ -688,7 +691,7 @@ inkpot_status_t inkpot_write_rgb8 ( inkpot_t *inkpot )
 
     rc = inkpot_get_rgba_i ( inkpot, rgba );
     if (rc == INKPOT_SUCCESS) {
-        len = sprintf(buf, "%02x%02x%02x", rgba[0]>>8, rgba[1]>>8, rgba[2]>>8);
+        len = snprintf(buf, "%02x%02x%02x", rgba[0]>>8, rgba[1]>>8, rgba[2]>>8);
        assert(len==6);
         inkpot->write_disc.writer(inkpot->write_closure, buf, len);
     }
index e4fd24a87a67ef2c0ee83074d3fde24df4ce7941..766d27e6c426d740ea27aa96a391eecf81b86b38 100644 (file)
@@ -467,10 +467,10 @@ static void constrainY(graph_t* g, nitem* nlist, int nnodes, intersectfn ifn,
        node_t *n;
        edge_t *e;
        for (n = agfstnode(cg); n; n = agnxtnode(cg, n)) {
-           sprintf(buf, "%d", ND_rank(n));
+           snprintf(buf, sizeof(buf), "%d", ND_rank(n));
            agxset(n, rksym, buf);
            for (e = agfstedge(cg, n); e; e = agnxtedge(cg, e, n)) {
-               sprintf(buf, "%d", ED_minlen(e));
+               snprintf(buf, sizeof(buf), "%d", ED_minlen(e));
                agxset(e, mlsym, buf);
            }
        }
index 6503b02c3956d9cb66ef9ff8c7f624895d5f06ce..9b7e89309e26f1881c8c7b1f00f072986b51b2b7 100644 (file)
@@ -671,11 +671,11 @@ prTriGraph (router_t* rtr, int n)
         pointf b = pts[rtr->tris[3*i+1]];
         pointf c = pts[rtr->tris[3*i+2]];
        psTri (a, b,c);
-       sprintf (buf, "%d", i);
+       snprintf(buf, sizeof(buf), "%d", i);
         psTxt (buf, nodes[i].ctr);
     }
     for (i=rtr->tn;i < n; i++) {
-       sprintf (buf, "%d", i);
+       snprintf(buf, sizeof(buf), "%d", i);
         psTxt (buf, nodes[i].ctr);
     }
     psColor ("1 0 0");
index 30e14544533b470f849bd035935d9675e8b46e33..bb714aa5ae91bff2dbd7a697d52b3aa9ce99997e 100644 (file)
@@ -989,7 +989,7 @@ setSeed (graph_t * G, int dflt, long* seedp)
 #else
            seed = (unsigned) getpid() ^ (unsigned) time(NULL);
 #endif
-           sprintf(smallbuf, "%ld", seed);
+           snprintf(smallbuf, sizeof(smallbuf), "%ld", seed);
            agset(G, "start", smallbuf);
        }
        *seedp = seed;
@@ -1376,7 +1376,7 @@ static void addZ (Agraph_t* g)
 
     if ((Ndim >= 3) && N_z) {
        for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
-           sprintf(buf, "%lf", POINTS_PER_INCH * (ND_pos(n)[2]));
+           snprintf(buf, sizeof(buf), "%lf", POINTS_PER_INCH * (ND_pos(n)[2]));
            agxset(n, N_z, buf);
        }
     }
index 6ac3a8ab65e16bc3ca6811e76785cf5cf856e32b..95ce3e0b87ee3689f621ac1a5a5951eb826fbe27 100644 (file)
@@ -207,7 +207,7 @@ static void finishNode(node_t * n)
     if (N_fontsize) {
        char* str = agxget(n, N_fontsize);
        if (*str == '\0') {
-           sprintf (buf, "%.03f", ND_ht(n)*0.7); 
+           snprintf(buf, sizeof(buf), "%.03f", ND_ht(n)*0.7);
            agxset(n, N_fontsize, buf);
        }
     }
index bb6eb8e1d51c46a54354ecb8b32d9112c972f0c7..04c43cecd090f6e878bfa46b309fa3ffbacd5118 100644 (file)
@@ -934,7 +934,8 @@ real StressMajorizationSmoother_smooth(StressMajorizationSmoother sm, int dim, r
 #ifdef GVIEWER
       if (Gviewer){
        char lab[100];
-       sprintf(lab,"maxent. alpha=%10.2g, iter=%d",stress_maxent_data_get_alpha(sm->data), iter);
+       snprintf(lab, sizeof(lab), "maxent. alpha=%10.2g, iter=%d",
+                stress_maxent_data_get_alpha(sm->data), iter);
        gviewer_set_label(lab);
       }
 #endif
@@ -951,7 +952,7 @@ real StressMajorizationSmoother_smooth(StressMajorizationSmoother sm, int dim, r
 #ifdef GVIEWER
       if (Gviewer){
        char lab[100];
-       sprintf(lab,"pmds(k), iter=%d", iter);
+       snprintf(lab, sizeof(lab), "pmds(k), iter=%d", iter);
        gviewer_set_label(lab);
       }
 #endif
index 9913504be95abccad6fc18d6809e6080fb75bf6b..a88969db014835e68325ea378d4a1f5be4f724d3 100644 (file)
@@ -544,7 +544,7 @@ void spring_electrical_embedding_fast(int dim, SparseMatrix A0, spring_electrica
 #ifdef GVIEWER
     if (Gviewer){
       char lab[100];
-      sprintf(lab,"sfdp, iter=%d", iter);
+      snprintf(lab, sizeof(lab), "sfdp, iter=%d", iter);
       gviewer_set_label(lab);
       gviewer_reset_graph_coord(A, dim, x);
       drawScene();
@@ -1029,7 +1029,8 @@ void spring_electrical_embedding(int dim, SparseMatrix A0, spring_electrical_con
 #ifdef GVIEWER
     if (Gviewer){
       char lab[100];
-      sprintf(lab,"sfdp, adaptive_cooling = %d iter=%d", adaptive_cooling, iter);
+      snprintf(lab, sizeof(lab), "sfdp, adaptive_cooling = %d iter=%d",
+               adaptive_cooling, iter);
       gviewer_set_label(lab);
       gviewer_reset_graph_coord(A, dim, x);
       drawScene();
index ee73fc1242725fa280a3635e4e46607fc02992ea..36d4547945f5c60fd483e698c020edb17db28340 100644 (file)
@@ -437,14 +437,14 @@ makeDotGraph (SparseMatrix A, char *name, int dim, real *x, int with_color, int
   } else {
     g = agopen ("G", Agdirected, 0);
   }
-  sprintf (buf, "%f", 1.0);
+  snprintf(buf, sizeof(buf), "%f", 1.0);
 
   label_string = strcpy(label_string, name);
   label_string = strcat(label_string, ". ");
-  sprintf (buf, "%d", A->m);
+  snprintf(buf, sizeof(buf), "%d", A->m);
   label_string = strcat(label_string, buf);
   label_string = strcat(label_string, " nodes, ");
-  sprintf (buf, "%d", A->nz);
+  snprintf(buf, sizeof(buf), "%d", A->nz);
   label_string = strcat(label_string, buf);
   /*  label_string = strcat(label_string, " edges. Created by Yifan Hu");*/
   label_string = strcat(label_string, " edges.");
@@ -492,7 +492,7 @@ makeDotGraph (SparseMatrix A, char *name, int dim, real *x, int with_color, int
     sym3 = agattr(g, AGEDGE, "wt", ""); 
   }
   for (i = 0; i < A->m; i++) {
-    sprintf (buf, "%d", i);
+    snprintf(buf, sizeof(buf), "%d", i);
     n = mkNode (g, buf);
     ND_id(n) = i;
     arr[i] = n;
@@ -552,36 +552,36 @@ makeDotGraph (SparseMatrix A, char *name, int dim, real *x, int with_color, int
       if (val){
        switch (A->type){
        case MATRIX_TYPE_REAL:
-         sprintf (buf, "%f", ((real*)A->a)[j]);
+         snprintf(buf, sizeof(buf), "%f", ((real*)A->a)[j]);
          break;
        case MATRIX_TYPE_INTEGER:
-         sprintf (buf, "%d", ((int*)A->a)[j]);
+         snprintf(buf, sizeof(buf), "%d", ((int*)A->a)[j]);
          break;
        case MATRIX_TYPE_COMPLEX:/* take real part as weight */
-         sprintf (buf, "%f", ((real*)A->a)[2*j]);
+         snprintf(buf, sizeof(buf), "%f", ((real*)A->a)[2*j]);
          break;
        }
        if (with_color) {
           if (i != ja[j]){
-            sprintf (buf2, "%s", hue2rgb(.65*color[j], cstring));
+            snprintf(buf2, sizeof(buf2), "%s", hue2rgb(.65*color[j], cstring));
           } else {
-            sprintf (buf2, "#000000");
+            snprintf(buf2, sizeof(buf2), "#000000");
           }
         }
       } else {
-       sprintf (buf, "%f", 1.);
+       snprintf(buf, sizeof(buf), "%f", 1.);
         if (with_color) {
           if (i != ja[j]){
-            sprintf (buf2, "%s", hue2rgb(.65*color[j], cstring));
+            snprintf(buf2, sizeof(buf2), "%s", hue2rgb(.65*color[j], cstring));
           } else {
-            sprintf (buf2, "#000000");
+            snprintf(buf2, sizeof(buf2), "#000000");
           }
         }
      }
       e = agedge (g, n, h, NULL, 1);
       if (with_color) {
        agxset (e, sym2, buf2);
-       sprintf (buf2, "%f", color[j]);
+       snprintf(buf2, sizeof(buf2), "%f", color[j]);
        agxset (e, sym3, buf2);
       }
     }
@@ -693,7 +693,7 @@ Agraph_t* assign_random_edge_color(Agraph_t* g){
   sym2 = agattr(g, AGEDGE, "color", ""); 
   for (n = agfstnode (g); n; n = agnxtnode (g, n)) {
     for (ep = agfstedge(g, n); ep; ep = agnxtedge(g, ep, n)) {
-      sprintf (buf2, "%s", hue2rgb(0.65*drand(), cstring));
+      snprintf(buf2, sizeof(buf2), "%s", hue2rgb(0.65*drand(), cstring));
       agxset (ep, sym2, buf2);
     }
   }
@@ -901,7 +901,7 @@ SparseMatrix Import_coord_clusters_from_dot(Agraph_t* g, int maxcluster, int dim
     for (i = 0; i < nnodes; i++) (*clusters)[i]++;/* make into 1 based */
     for (n = agfstnode (g); n; n = agnxtnode (g, n)) {
       i = ND_id(n);
-      sprintf(scluster,"%d",(*clusters)[i]);
+      snprintf(scluster, sizeof(scluster), "%d", (*clusters)[i]);
       agxset(n,clust_sym,scluster);
     }
     MIN_GRPS = 1;
index 56b34f23078174f1f849bd7b96237420131cdaa1..288a22e46efc9c738e4a9c462e88c01fff0fe39b 100644 (file)
@@ -131,8 +131,8 @@ tok = name;
             tok = "none";
         } else {
 //            colorxlate(name, &color, RGBA_BYTE);
-            sprintf(buf, "#%02x%02x%02x",
-                    color.u.rgba[0], color.u.rgba[1], color.u.rgba[2]);
+            snprintf(buf, sizeof(buf), "#%02x%02x%02x",
+                     color.u.rgba[0], color.u.rgba[1], color.u.rgba[2]);
             tok = buf;
         }
     }
index 2a783969a0c2b42ca69dc715057561896eb54605..dfcc28d7f0b5fd5c4a340cbb2cac3c0e94d6ecf2 100644 (file)
@@ -165,9 +165,10 @@ color2str (unsigned char rgba[4])
     static char buf [10];
 
     if (rgba[3] == 0xFF)
-       sprintf (buf, "#%02x%02x%02x", rgba[0], rgba[1],  rgba[2]);
+       snprintf(buf, sizeof(buf), "#%02x%02x%02x", rgba[0], rgba[1],  rgba[2]);
     else
-       sprintf (buf, "#%02x%02x%02x%02x", rgba[0], rgba[1],  rgba[2], rgba[3]);
+       snprintf(buf, sizeof(buf), "#%02x%02x%02x%02x", rgba[0], rgba[1],  rgba[2],
+                rgba[3]);
     return buf;
 }
 
@@ -195,7 +196,7 @@ static void xdot_style (GVJ_t *job)
     if (job->obj->penwidth != penwidth[job->obj->emit_state]) {
        penwidth[job->obj->emit_state] = job->obj->penwidth;
        agxbput (&xbuf, "setlinewidth(");
-       sprintf (buf, "%.3f", job->obj->penwidth);
+       snprintf(buf, sizeof(buf), "%.3f", job->obj->penwidth);
        xdot_trim_zeros (buf, 0);
        agxbprint(&xbuf, "%s)", buf);
         xdot_str (job, "S ", agxbuse(&xbuf));
@@ -605,7 +606,7 @@ static void xdot_color_stop (agxbuf* xb, float v, gvcolor_t* clr)
 {
     char buf[BUFSIZ];
 
-    sprintf (buf, "%.03f", v);
+    snprintf(buf, sizeof(buf), "%.03f", v);
     xdot_trim_zeros (buf, 1);
     xdot_str_xbuf (xb, buf, color2str (clr->u.rgba));
 }
index 300493b612268cbcbebaafb405e9c763a36961f2..4ca11e69841fffcdfcab6f2b44abeee7177cce0b 100644 (file)
@@ -127,9 +127,10 @@ static int gvloadimage_process_surface(GVJ_t *job, usershape_t *us, gs_t *gs, vo
 
     cr = cairo_create(gs->surface);  /* temp context for gs */
 
-    sprintf(width_height, "-g%dx%d", us->x + us->w, us->y + us->h);
-    sprintf(dpi, "-r%d", us->dpi);
-    sprintf(cairo_context, "-sCairoContext=%p", cr);
+    snprintf(width_height, sizeof(width_height), "-g%dx%d", us->x + us->w,
+             us->y + us->h);
+    snprintf(dpi, sizeof(dpi), "-r%d", us->dpi);
+    snprintf(cairo_context, sizeof(cairo_context), "-sCairoContext=%p", cr);
 
     rc = gsapi_init_with_args(instance, GS_ARGC, gs_args);
 
index baefbbd82abc2a3a2c8d6dd608929116254cfd1a..8937185453de143a2fb0437fcf77a30c77407406 100644 (file)
@@ -428,7 +428,7 @@ tclGdCreateCmd(Tcl_Interp * interp, int argc, Tcl_Obj * CONST objv[])
            im = gdImageCreate(w, h);
        if (im == NULL) {
            char buf[255];
-           sprintf(buf, "GD unable to allocate %d X %d image", w, h);
+           snprintf(buf, sizeof(buf), "GD unable to allocate %d X %d image", w, h);
            Tcl_SetResult(interp, buf, TCL_VOLATILE);
            return TCL_ERROR;
        }
@@ -440,7 +440,7 @@ tclGdCreateCmd(Tcl_Interp * interp, int argc, Tcl_Obj * CONST objv[])
        im = gdImageCreateTrueColor(w, h);
        if (im == NULL) {
            char buf[255];
-           sprintf(buf, "GD unable to allocate %d X %d image", w, h);
+           snprintf(buf, sizeof(buf), "GD unable to allocate %d X %d image", w, h);
            Tcl_SetResult(interp, buf, TCL_VOLATILE);
            return TCL_ERROR;
        }
index 6f2f5d2ac40c4c4600817dc9dfa32382abc77223..b2542edaf3ac6a4afe0ba4fc8329fdd1e608f19f 100644 (file)
@@ -54,10 +54,10 @@ char *obj2cmd (void *obj) {
     static char buf[32];
 
     switch (AGTYPE(obj)) {
-        case AGRAPH: sprintf(buf,"graph%p",obj); break;
-        case AGNODE: sprintf(buf,"node%p",obj); break;
+        case AGRAPH:    snprintf(buf, sizeof(buf), "graph%p", obj); break;
+        case AGNODE:    snprintf(buf, sizeof(buf), "node%p",  obj); break;
         case AGINEDGE: 
-        case AGOUTEDGE: sprintf(buf,"edge%p",obj); break;
+        case AGOUTEDGE: snprintf(buf, sizeof(buf), "edge%p",  obj); break;
     }
     return buf;
 }
@@ -251,11 +251,11 @@ void tcldot_layout(GVC_t *gvc, Agraph_t * g, char *engine)
  * doesn't yet include margins, scaling or page sizes because
  * those depend on the renderer being used. */
     if (GD_drawing(g)->landscape)
-       sprintf(buf, "%d %d %d %d",
+       snprintf(buf, sizeof(buf), "%d %d %d %d",
                ROUND(GD_bb(g).LL.y), ROUND(GD_bb(g).LL.x),
                ROUND(GD_bb(g).UR.y), ROUND(GD_bb(g).UR.x));
     else
-       sprintf(buf, "%d %d %d %d",
+       snprintf(buf, sizeof(buf), "%d %d %d %d",
                ROUND(GD_bb(g).LL.x), ROUND(GD_bb(g).LL.y),
                ROUND(GD_bb(g).UR.x), ROUND(GD_bb(g).UR.y));
     if (!(a = agattr(g, AGRAPH, "bb", NULL))) 
index 17fbbd22c66db66d19851ae83d8f239a0fc32a64..10029b202716552c6aad3707b8e00bcaca2c0148 100644 (file)
@@ -126,9 +126,9 @@ static void dgsprintxy(Tcl_DString * result, int npts, point p[])
     if (npts != 1)
        Tcl_DStringStartSublist(result);
     for (i = 0; i < npts; i++) {
-       sprintf(buf, "%g", p[i].x);
+       snprintf(buf, sizeof(buf), "%g", p[i].x);
        Tcl_DStringAppendElement(result, buf);
-       sprintf(buf, "%g", p[i].y);
+       snprintf(buf, sizeof(buf), "%g", p[i].y);
        Tcl_DStringAppendElement(result, buf);
     }
     if (npts != 1)
@@ -195,7 +195,7 @@ void triangle_callback(void *vgparg, point pqr[])
 /*         TBL_ENTRY((tblHeader_pt)vgpaneTable, (ubyte_pt)vgp));*/
 
     if (vgp->triangle_cmd) {
-       sprintf(vbuf, "vgpane%lu",
+       snprintf(vbuf, sizeof(vbuf), "vgpane%lu",
                (uint64_t) (((ubyte_pt) vgp - (vgpaneTable->bodyPtr))
                                 / (vgpaneTable->entrySize)));
        expandPercentsEval(vgp->interp, vgp->triangle_cmd, vbuf, 3, pqr);
@@ -391,9 +391,9 @@ static void appendpoint(Tcl_Interp * interp, point p)
 {
     char buf[30];
 
-    sprintf(buf, "%g", p.x);
+    snprintf(buf, sizeof(buf), "%g", p.x);
     Tcl_AppendElement(interp, buf);
-    sprintf(buf, "%g", p.y);
+    snprintf(buf, sizeof(buf), "%g", p.y);
     Tcl_AppendElement(interp, buf);
 }
 
@@ -527,7 +527,7 @@ vgpanecmd(ClientData clientData, Tcl_Interp * interp, int argc,
        /* determine the polygons (if any) that contain the point */
        for (i = 0; i < vgp->Npoly; i++) {
            if (in_poly(vgp->poly[i].boundary, p)) {
-               sprintf(vbuf, "%d", vgp->poly[i].id);
+               snprintf(vbuf, sizeof(vbuf), "%d", vgp->poly[i].id);
                Tcl_AppendElement(interp, vbuf);
            }
        }
@@ -568,14 +568,14 @@ vgpanecmd(ClientData clientData, Tcl_Interp * interp, int argc,
        if (result != TCL_OK)
            return result;
 
-       sprintf(vbuf, "%d", polyid);
+       snprintf(vbuf, sizeof(vbuf), "%d", polyid);
        Tcl_AppendResult(interp, vbuf, (char *) NULL);
        return TCL_OK;
 
     } else if ((c == 'l') && (strncmp(argv[1], "list", length) == 0)) {
        /* return list of polygon ids */
        for (i = 0; i < vgp->Npoly; i++) {
-           sprintf(vbuf, "%d", vgp->poly[i].id);
+           snprintf(vbuf, sizeof(vbuf), "%d", vgp->poly[i].id);
            Tcl_AppendElement(interp, vbuf);
        }
        return TCL_OK;
index c45be7c76949502c1a0ecae3ca043e3c4f198be9..37b66d26076483a052fe8ad71218747cb763e150 100644 (file)
@@ -185,7 +185,7 @@ int numSteps;                       /* Not Used */
        return;
     }
 
-    sprintf(buffer, "%.15g %.15g moveto\n",
+    snprintf(buffer, sizeof(buffer), "%.15g %.15g moveto\n",
            pointPtr[0], Tk_CanvasPsY(canvas, pointPtr[1]));
     Tcl_AppendResult(interp, buffer, (char *) NULL);
 
@@ -195,7 +195,8 @@ int numSteps;                       /* Not Used */
      */
 
     for (i = numPoints - 2, pointPtr += 2; i > 0; i -= 3, pointPtr += 6) {
-       sprintf(buffer, "%.15g %.15g %.15g %.15g %.15g %.15g curveto\n",
+       snprintf(buffer, sizeof(buffer),
+               "%.15g %.15g %.15g %.15g %.15g %.15g curveto\n",
                pointPtr[0], Tk_CanvasPsY(canvas, pointPtr[1]),
                pointPtr[2], Tk_CanvasPsY(canvas, pointPtr[3]),
                pointPtr[4], Tk_CanvasPsY(canvas, pointPtr[5]));
index 30d070cd06190d4bea2967afaf41b8e343ab2680..c1328c0cfd1c77399dc4d0dd2e0d4ad525c935ba 100644 (file)
@@ -84,8 +84,8 @@ Test(command_line, dash_V_output,
        gvParseArgs(Gvc, argc, argv);
 
        char expected_stderr[100];
-       sprintf(expected_stderr, "dot - graphviz version %s (%s)\n",
-                               PACKAGE_VERSION, BUILDDATE);
+       snprintf(expected_stderr, sizeof(expected_stderr),
+                "dot - graphviz version %s (%s)\n", PACKAGE_VERSION, BUILDDATE);
 
        cr_assert_stderr_eq_str(expected_stderr);
 }
@@ -119,8 +119,8 @@ Test(command_line, dash_Vrandom_output,
        gvParseArgs(Gvc, argc, argv);
 
        char expected_stderr[100];
-       sprintf(expected_stderr, "dot - graphviz version %s (%s)\n",
-                               PACKAGE_VERSION, BUILDDATE);
+       snprintf(expected_stderr, sizeof(expected_stderr),
+                "dot - graphviz version %s (%s)\n", PACKAGE_VERSION, BUILDDATE);
 
        cr_assert_stderr_eq_str(expected_stderr);
 }
@@ -154,9 +154,8 @@ Test(command_line, dash_randomV_output,
        gvParseArgs(Gvc, argc, argv);
 
        char expected_stderr[2000];
-               sprintf(expected_stderr, "Error: dot: option -r unrecognized\n"
-                               "\n"
-                               "%s", usage_info);
+       snprintf(expected_stderr, sizeof(expected_stderr),
+                "Error: dot: option -r unrecognized\n\n%s", usage_info);
 
        cr_assert_stderr_eq_str(expected_stderr);
 }
@@ -222,8 +221,8 @@ Test(command_line, dash_V_questionmark_output,
        gvParseArgs(Gvc, argc, argv);
 
        char expected_stderr[100];
-       sprintf(expected_stderr, "dot - graphviz version %s (%s)\n",
-                               PACKAGE_VERSION, BUILDDATE);
+       snprintf(expected_stderr, sizeof(expected_stderr),
+                "dot - graphviz version %s (%s)\n", PACKAGE_VERSION, BUILDDATE);
 
        cr_assert_stderr_eq_str(expected_stderr);
 }