summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_sbuf.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2001-03-06 17:48:26 +0000
committerdes <des@FreeBSD.org>2001-03-06 17:48:26 +0000
commit7781e1edf7e86663e1b7939f63056453696cba18 (patch)
tree75c77a055502e6e72d295c5889a9dc88d6d0732e /sys/kern/subr_sbuf.c
parent171a68d94e414871c4132341ec09c0d725614399 (diff)
downloadFreeBSD-src-7781e1edf7e86663e1b7939f63056453696cba18.zip
FreeBSD-src-7781e1edf7e86663e1b7939f63056453696cba18.tar.gz
Make the KASSERTs report the correct function names.
Fix two off-by-one errors that would sometimes cause the final length of the sbuf to include the trailing zero.
Diffstat (limited to 'sys/kern/subr_sbuf.c')
-rw-r--r--sys/kern/subr_sbuf.c29
1 files changed, 11 insertions, 18 deletions
diff --git a/sys/kern/subr_sbuf.c b/sys/kern/subr_sbuf.c
index 247ecac..ffe73f8 100644
--- a/sys/kern/subr_sbuf.c
+++ b/sys/kern/subr_sbuf.c
@@ -57,23 +57,25 @@ MALLOC_DEFINE(M_SBUF, "sbuf", "string buffers");
*/
#ifdef INVARIANTS
static void
-assert_sbuf_integrity(struct sbuf *s)
+_assert_sbuf_integrity(char *fun, struct sbuf *s)
{
KASSERT(s != NULL,
- (__FUNCTION__ " called with a NULL sbuf pointer"));
+ ("%s called with a NULL sbuf pointer", fun));
KASSERT(s->s_buf != NULL,
- (__FUNCTION__ " called with unitialized or corrupt sbuf"));
+ ("%s called with unitialized or corrupt sbuf", fun));
KASSERT(s->s_len < s->s_size,
("wrote past end of sbuf (%d >= %d)", s->s_len, s->s_size));
}
static void
-assert_sbuf_state(struct sbuf *s, int state)
+_assert_sbuf_state(char *fun, struct sbuf *s, int state)
{
KASSERT((s->s_flags & SBUF_FINISHED) == state,
- (__FUNCTION__ " called with %sfinished or corrupt sbuf",
+ ("%s called with %sfinished or corrupt sbuf", fun,
(state ? "un" : "")));
}
+#define assert_sbuf_integrity(s) _assert_sbuf_integrity(__FUNCTION__, (s))
+#define assert_sbuf_state(s, i) _assert_sbuf_state(__FUNCTION__, (s), (i))
#else
#define assert_sbuf_integrity(s) do { } while (0)
#define assert_sbuf_state(s, i) do { } while (0)
@@ -181,17 +183,7 @@ sbuf_cpy(struct sbuf *s, char *str)
static void
_sbuf_pchar(int c, void *v)
{
- struct sbuf *s = (struct sbuf *)v;
-
- assert_sbuf_integrity(s);
- assert_sbuf_state(s, 0);
-
- if (SBUF_HASOVERFLOWED(s))
- return;
- if (SBUF_HASROOM(s))
- s->s_buf[s->s_len++] = c;
- else
- SBUF_SETFLAG(s, SBUF_OVERFLOWED);
+ sbuf_putc((struct sbuf *)v, c);
}
/*
@@ -240,7 +232,8 @@ sbuf_putc(struct sbuf *s, int c)
SBUF_SETFLAG(s, SBUF_OVERFLOWED);
return (-1);
}
- s->s_buf[s->s_len++] = c;
+ if (c != '\0')
+ s->s_buf[s->s_len++] = c;
return (0);
}
@@ -262,7 +255,7 @@ sbuf_finish(struct sbuf *s)
assert_sbuf_integrity(s);
assert_sbuf_state(s, 0);
- s->s_buf[s->s_len++] = '\0';
+ s->s_buf[s->s_len] = '\0';
SBUF_CLEARFLAG(s, SBUF_OVERFLOWED);
SBUF_SETFLAG(s, SBUF_FINISHED);
}
OpenPOWER on IntegriCloud