chiark / gitweb /
buf: Fix two embarassing bugs found while writing Lisp bindings.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 15 May 2006 19:18:32 +0000 (20:18 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 15 May 2006 19:18:32 +0000 (20:18 +0100)
  * buf_{get,put}memNl never worked.  It always wrote the length
    big-endian.

  * buf_getmemz never worked, because it used the wrong length to find
    the terminator.

buf.c

diff --git a/buf.c b/buf.c
index 3dc4996..3223d90 100644 (file)
--- a/buf.c
+++ b/buf.c
@@ -222,7 +222,7 @@ static int findz(buf *b, size_t *nn)
 {
   octet *p;
 
-  if ((p = memchr(BCUR(b), 0, BLEN(b))) == 0) {
+  if ((p = memchr(BCUR(b), 0, BLEFT(b))) == 0) {
     buf_break(b);
     return (-1);
   }
@@ -246,7 +246,7 @@ static int findz(buf *b, size_t *nn)
   void *buf_getmem##w(buf *b, size_t *nn)                              \
   {                                                                    \
     uint##n sz;                                                                \
-    if (buf_getu##n(b, &sz)) return (0);                               \
+    if (buf_getu##w(b, &sz)) return (0);                               \
     *nn = sz;                                                          \
     return (buf_get(b, sz));                                           \
   }
@@ -275,7 +275,7 @@ void *buf_getmemz(buf *b, size_t *nn)
   int buf_putmem##w(buf *b, const void *p, size_t sz)                  \
   {                                                                    \
     assert(sz <= MASK##W);                                             \
-    if (buf_putu##n(b, sz) || buf_put(b, p, sz))                       \
+    if (buf_putu##w(b, sz) || buf_put(b, p, sz))                       \
       return (-1);                                                     \
     return (0);                                                                \
   }