[esnacc-dev] [PATCH 6/7] exp-buf: Simply get byte

Aaron Conole aconole at bytheb.org
Tue Dec 20 17:14:13 UTC 2016


The logic here was crazy;  too much cargo-cult.

Signed-off-by: Aaron Conole <aconole at bytheb.org>
---
 c-lib/src/exp-buf.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/c-lib/src/exp-buf.c b/c-lib/src/exp-buf.c
index 2062087..3fc701d 100644
--- a/c-lib/src/exp-buf.c
+++ b/c-lib/src/exp-buf.c
@@ -900,28 +900,25 @@ ExpBufGetByte PARAMS ((b),
 {
     unsigned char retVal;
 
-
-    if (ExpBufAtEod (*b))
-    {
-        (*b)->readError = 1;
-        return (unsigned char)0;
+    while (((*b)->next != NULL) && ExpBufHasNoData (*b)) {
+        *b = (*b)->next;
     }
 
-    retVal = *(*b)->curr++;
-
     /* "buffer fault" - if end of this buf, go on to next, if any */
-    if (ExpBufAtEod (*b) && ((*b)->next != NULL))
-    {
+    if (ExpBufAtEod (*b) && ((*b)->next != NULL)) {
         *b = (*b)->next;
 
         /* get next buffer with valid data */
-        while (((*b)->next != NULL) && ExpBufHasNoData (*b))
-            *b = (*b)->next;
-
         /* reset current pointer to beggining of data if nec */
         (*b)->curr = (*b)->dataStart;
     }
 
+    if (ExpBufAtEod (*b)) {
+        (*b)->readError = 1;
+        return (unsigned char)0;
+    }
+
+    retVal = *(*b)->curr++;
     return retVal;
 
 }  /* ExpBufGetByte */
-- 
2.7.4




More information about the dev mailing list