]> granicus.if.org Git - graphviz/commitdiff
Adjust appending parse function to take NULL xdot*.
authorerg <devnull@localhost>
Wed, 14 Oct 2009 16:47:09 +0000 (16:47 +0000)
committererg <devnull@localhost>
Wed, 14 Oct 2009 16:47:09 +0000 (16:47 +0000)
lib/xdot/xdot.c
lib/xdot/xdot.h

index 315dcfe5871f4a2762b44e1efddf3278d93a7bcc..551b06cee0f26bc2dd1344e42896cec5cc991880 100755 (executable)
@@ -263,22 +263,30 @@ static char *parseOp(xdot_op * op, char *s, drawfunc_t ops[], int* error)
 
 /* parseXDotFOn:
  * Parse and append additional xops onto a given xdot object.
- * Assume x != NULL.
  * Return x.
  */ 
-xdot *parseXDotFOn (char *s, drawfunc_t fns[], xdot* x)
+xdot *parseXDotFOn (char *s, drawfunc_t fns[], int sz, xdot* x)
 {
     xdot_op op;
     char *ops;
     int oldsz, bufsz;
     int error;
-    int initcnt, sz;
+    int initcnt;
 
-    if (!s || !x)
+    if (!s)
        return x;
 
+    if (!x) {
+       x = NEW(xdot);
+       if (sz <= sizeof(xdot_op))
+           sz = sizeof(xdot_op);
+
+       /* cnt, freefunc, ops, flags zeroed by NEW */
+       x->sz = sz;
+    }
     initcnt = x->cnt;
     sz = x->sz;
+
     if (initcnt == 0) {
        bufsz = XDBSIZE;
        ops = (char *) calloc(XDBSIZE, sz);
@@ -307,6 +315,8 @@ xdot *parseXDotFOn (char *s, drawfunc_t fns[], xdot* x)
     }
     else {
        free (ops);
+       free (x);
+       x = NULL;
     }
 
     return x;
@@ -315,23 +325,7 @@ xdot *parseXDotFOn (char *s, drawfunc_t fns[], xdot* x)
 
 xdot *parseXDotF(char *s, drawfunc_t fns[], int sz)
 {
-    xdot *x;
-
-    if (!s)
-       return NULL;
-    x = NEW(xdot);
-    if (sz <= sizeof(xdot_op))
-       sz = sizeof(xdot_op);
-
-    /* cnt, freefunc, ops, flags zeroed by NEW */
-    x->sz = sz;
-
-    x = parseXDotFOn (s, fns, x);
-    if (x->cnt == 0) {
-       free(x);
-       x = NULL;
-    }
-    return x;
+    return parseXDotFOn (s, fns, sz, NULL);
 }
 
 xdot *parseXDot(char *s)
index 4697ae14bb7ad0c7ffbac527e9e37dba1881ceef..be14432e832ab927f33980aabf584f1785bf614f 100755 (executable)
@@ -103,7 +103,7 @@ typedef struct {
 
 /* ops are indexed by xop_kind */
 extern xdot* parseXDotF (char*, drawfunc_t opfns[], int sz);
-extern xdot* parseXDotFOn (char*, drawfunc_t opfns[], xdot*);
+extern xdot* parseXDotFOn (char*, drawfunc_t opfns[], int sz, xdot*);
 extern xdot* parseXDot (char*);
 extern char* sprintXDot (xdot*);
 extern void fprintXDot (FILE*, xdot*);