From a4589237d33eb5ed0858371a668f652651f4bcda Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Mon, 15 May 2006 20:18:32 +0100 Subject: [PATCH] buf: Fix two embarassing bugs found while writing Lisp bindings. Organization: Straylight/Edgeware From: Mark Wooding * 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 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/buf.c b/buf.c index 3dc4996..3223d90 100644 --- 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); \ } -- [mdw]