From: erg Date: Wed, 14 Oct 2009 16:47:09 +0000 (+0000) Subject: Adjust appending parse function to take NULL xdot*. X-Git-Tag: LAST_LIBGRAPH~32^2~1655 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ffc245e2da9b7c8bc369e0cab13fa3eb9b253b51;p=graphviz Adjust appending parse function to take NULL xdot*. --- diff --git a/lib/xdot/xdot.c b/lib/xdot/xdot.c index 315dcfe58..551b06cee 100755 --- a/lib/xdot/xdot.c +++ b/lib/xdot/xdot.c @@ -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) diff --git a/lib/xdot/xdot.h b/lib/xdot/xdot.h index 4697ae14b..be14432e8 100755 --- a/lib/xdot/xdot.h +++ b/lib/xdot/xdot.h @@ -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*);