summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortobias <tobias@openbsd.org>2010-09-08 15:13:39 +0000
committertobias <tobias@openbsd.org>2010-09-08 15:13:39 +0000
commit4b4f7720797cf66345b6e46c8d226679c949f21d (patch)
tree64b61a61e960a718fcc3a052811d33181dd00cea
parentSync disklabel_sun_to_bsd() with sparc64/disksubr.c. This gives us access (diff)
downloadwireguard-openbsd-4b4f7720797cf66345b6e46c8d226679c949f21d.tar.xz
wireguard-openbsd-4b4f7720797cf66345b6e46c8d226679c949f21d.zip
Use SIZE_LEFT macro to determine left size instead of calculating with
pointers. ok zinovik
-rw-r--r--usr.bin/cvs/buf.c8
-rw-r--r--usr.bin/rcs/buf.c23
2 files changed, 10 insertions, 21 deletions
diff --git a/usr.bin/cvs/buf.c b/usr.bin/cvs/buf.c
index 9102a5dcab4..c54260be977 100644
--- a/usr.bin/cvs/buf.c
+++ b/usr.bin/cvs/buf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: buf.c,v 1.78 2010/08/01 09:19:29 zinovik Exp $ */
+/* $OpenBSD: buf.c,v 1.79 2010/09/08 15:13:39 tobias Exp $ */
/*
* Copyright (c) 2003 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -127,11 +127,9 @@ buf_putc(BUF *b, int c)
{
u_char *bp;
- bp = b->cb_buf + b->cb_len;
- if (bp == (b->cb_buf + b->cb_size)) {
+ if (SIZE_LEFT(b) == 0)
buf_grow(b, BUF_INCR);
- bp = b->cb_buf + b->cb_len;
- }
+ bp = b->cb_buf + b->cb_len;
*bp = (u_char)c;
b->cb_len++;
}
diff --git a/usr.bin/rcs/buf.c b/usr.bin/rcs/buf.c
index 3e81c55c999..5c0f90f0e84 100644
--- a/usr.bin/rcs/buf.c
+++ b/usr.bin/rcs/buf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: buf.c,v 1.16 2010/07/28 09:07:11 ray Exp $ */
+/* $OpenBSD: buf.c,v 1.17 2010/09/08 15:13:39 tobias Exp $ */
/*
* Copyright (c) 2003 Jean-Francois Brousseau <jfb@openbsd.org>
* All rights reserved.
@@ -194,14 +194,9 @@ buf_putc(BUF *b, int c)
{
u_char *bp;
- bp = b->cb_buf + b->cb_len;
- if (bp == (b->cb_buf + b->cb_size)) {
- /* extend */
+ if (SIZE_LEFT(b) == 0)
buf_grow(b, BUF_INCR);
-
- /* the buffer might have been moved */
- bp = b->cb_buf + b->cb_len;
- }
+ bp = b->cb_buf + b->cb_len;
*bp = (u_char)c;
b->cb_len++;
}
@@ -230,18 +225,14 @@ size_t
buf_append(BUF *b, const void *data, size_t len)
{
size_t left, rlen;
- u_char *bp, *bep;
+ u_char *bp;
- bp = b->cb_buf + b->cb_len;
- bep = b->cb_buf + b->cb_size;
- left = bep - bp;
+ left = SIZE_LEFT(b);
rlen = len;
- if (left < len) {
+ if (left < len)
buf_grow(b, len - left);
- bp = b->cb_buf + b->cb_len;
- }
-
+ bp = b->cb_buf + b->cb_len;
memcpy(bp, data, rlen);
b->cb_len += rlen;