From: Matthew Fernandez Date: Sat, 10 Sep 2022 19:41:51 +0000 (-0700) Subject: cgraph agxblen: de-duplicate some logic that was effectively 'agxblen' X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=86ab682712db9101d7ee93e3072f1a966dfc6a9e;p=graphviz cgraph agxblen: de-duplicate some logic that was effectively 'agxblen' Gitlab: #2302 --- diff --git a/lib/cgraph/agxbuf.h b/lib/cgraph/agxbuf.h index e902ccbda..ae9e3531a 100644 --- a/lib/cgraph/agxbuf.h +++ b/lib/cgraph/agxbuf.h @@ -65,12 +65,13 @@ static inline size_t agxblen(const agxbuf *xb) { * Removes last character added, if any. */ static inline int agxbpop(agxbuf *xb) { - int c; - if (xb->ptr > xb->buf) { - c = *xb->ptr--; - return c; - } else + + if (agxblen(xb) == 0) { return -1; + } + + int c = *xb->ptr--; + return c; } /* agxbmore: @@ -86,7 +87,7 @@ static inline void agxbmore(agxbuf *xb, size_t ssz) { nsize = size == 0 ? BUFSIZ : (2 * size); if (size + ssz > nsize) nsize = size + ssz; - cnt = (size_t)(xb->ptr - xb->buf); + cnt = agxblen(xb); if (!xb->stack_allocated) { nbuf = (char *)gv_recalloc(xb->buf, size, nsize, sizeof(char)); } else {