]> granicus.if.org Git - graphviz/commitdiff
cgraph agxblen: de-duplicate some logic that was effectively 'agxblen'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 10 Sep 2022 19:41:51 +0000 (12:41 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 10 Sep 2022 19:41:51 +0000 (12:41 -0700)
lib/cgraph/agxbuf.h

index f7066eef39e46bb707005b2b519cbf9ae77339e6..4a6590f577957730f7366d520fd4969731d359e0 100644 (file)
@@ -71,12 +71,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:
@@ -92,7 +93,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->located == AGXBUF_ON_HEAP) {
     nbuf = (char *)gv_recalloc(xb->buf, size, nsize, sizeof(char));
   } else {