]> granicus.if.org Git - graphviz/commitdiff
Fix bug which causes gvpack to crash if a graph has not been laid out.
authorerg <devnull@localhost>
Tue, 3 Mar 2009 23:11:04 +0000 (23:11 +0000)
committererg <devnull@localhost>
Tue, 3 Mar 2009 23:11:04 +0000 (23:11 +0000)
It relied on common_init_node to handle the case when there is no node
label attribute. This was changed last September, so gvpack now
explicitly sets the default label to NODENAME_ESC. This just prevents
gvpack from crashing until it can note the lack of pos info and then exit.

cmd/tools/gvpack.c

index ef8262e6f1e0b463e8baa95508aea879758e1fde..659c1395bfa43f0e1f8cf92294788007580ceb23 100644 (file)
@@ -66,7 +66,11 @@ static int verbose = 0;
 static char **myFiles = 0;
 static int nGraphs = 0;                /* Guess as to no. of graphs */
 static FILE *outfp;            /* output; stdout by default */
-static int kind = -1;          /* type of graph; -1 = undefined */
+#ifndef WITH_CGRAPH
+static int kind;               /* type of graph */
+#else
+static Agdesc_t kind;          /* type of graph */
+#endif
 static int G_cnt;              /* No. of -G arguments */
 static int G_sz;               /* Storage size for -G arguments */
 static attr_t *G_args;         /* Storage for -G arguments */
@@ -162,6 +166,7 @@ static void init(int argc, char *argv[])
     int c;
 
     aginit();
+    agnodeattr(NULL, "label", NODENAME_ESC);
     while ((c = getopt(argc, argv, ":ngvum:o:G:?")) != -1) {
        switch (c) {
        case 'n':
@@ -597,7 +602,11 @@ static Agraph_t *cloneGraph(Agraph_t ** gs, int cnt, GVC_t * gvc)
 
     if (verbose)
        fprintf(stderr, "Creating clone graph\n");
+#ifndef WITH_CGRAPH
     root = agopen("root", kind);
+#else
+    root = agopen("root", kind, &AgDefaultDisc);
+#endif
     GD_gvc(root) = gvc;
     initAttrs(root, gs, cnt);
     G_bb = agfindgraphattr(root, "bb");
@@ -695,6 +704,7 @@ static Agraph_t **readGraphs(int *cp, GVC_t* gvc)
     ingraph_state ig;
     int cnt = 0;
     int sz = 0;
+    int kindUnset = 1;
 
     /* set various state values */
     PSinputscale = POINTS_PER_INCH;
@@ -709,23 +719,29 @@ static Agraph_t **readGraphs(int *cp, GVC_t* gvc)
            sz += nGraphs;
            gs = ALLOC(sz, gs, Agraph_t *);
        }
-       if (kind == -1)
-           kind = g->kind;
 #ifndef WITH_CGRAPH
+       if (kindUnset) {
+           kindUnset = 0;
+           kind = g->kind;
+       }
        else if ((kind & AGFLAG_DIRECTED) != AG_IS_DIRECTED(g)) {
-#else
-       else if (!agisdirected(g) || agisdirected(g)) {
-           /* DUH !! - did I lose something in translation ? */
-#endif
            fprintf(stderr,
                    "Error: all graphs must be directed or undirected\n");
            exit(1);
-#ifndef WITH_CGRAPH
        } else if (!AG_IS_STRICT(g))
+           kind = g->kind;
 #else
+       if (kindUnset) {
+           kindUnset = 0;
+           kind = g->desc;
+       }
+       else if (kind.directed != g->desc.directed) {
+           fprintf(stderr,
+                   "Error: all graphs must be directed or undirected\n");
+           exit(1);
        } else if (!agisstrict(g))
+           kind = g->desc;
 #endif
-           kind = g->kind;
        init_graph(g, DOPACK);
        gs[cnt++] = g;
     }