summaryrefslogtreecommitdiffstats
path: root/usr.sbin/syslogd/ringbuf.c
diff options
context:
space:
mode:
authordjm <djm@openbsd.org>2005-09-21 23:25:32 +0000
committerdjm <djm@openbsd.org>2005-09-21 23:25:32 +0000
commit9ab071d17cc4701701d3d5a95c844f6ea40401fc (patch)
treebd4b4fa50cf8ea3b8c4a21b19b50506812d31914 /usr.sbin/syslogd/ringbuf.c
parentSimplify the internal symbol finding API, with some cleanup, prep for (diff)
downloadwireguard-openbsd-9ab071d17cc4701701d3d5a95c844f6ea40401fc.tar.xz
wireguard-openbsd-9ab071d17cc4701701d3d5a95c844f6ea40401fc.zip
rearrange sanity checks to eliminate signed arithmatic, from stevesk@
Diffstat (limited to 'usr.sbin/syslogd/ringbuf.c')
-rw-r--r--usr.sbin/syslogd/ringbuf.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/usr.sbin/syslogd/ringbuf.c b/usr.sbin/syslogd/ringbuf.c
index 80c91e7df56..80f06fe603d 100644
--- a/usr.sbin/syslogd/ringbuf.c
+++ b/usr.sbin/syslogd/ringbuf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ringbuf.c,v 1.6 2005/09/16 04:00:50 djm Exp $ */
+/* $OpenBSD: ringbuf.c,v 1.7 2005/09/21 23:25:32 djm Exp $ */
/*
* Copyright (c) 2004 Damien Miller
@@ -136,14 +136,14 @@ ringbuf_append_line(struct ringbuf *rb, char *line)
ssize_t
ringbuf_to_string(char *buf, size_t len, struct ringbuf *rb)
{
- ssize_t copy_len, n;
+ size_t copy_len, n;
- if (buf == NULL || rb == NULL)
+ if (buf == NULL || rb == NULL || len == 0)
return (-1);
copy_len = MIN(len - 1, ringbuf_used(rb));
- if (copy_len <= 0)
+ if (copy_len == 0)
return (copy_len);
if (rb->start < rb->end)
@@ -152,7 +152,7 @@ ringbuf_to_string(char *buf, size_t len, struct ringbuf *rb)
/* If the buffer is wrapped, copy each hunk separately */
n = rb->len - rb->start;
memcpy(buf, rb->buf + rb->start, MIN(n, copy_len));
- if (copy_len - n > 0)
+ if (copy_len > n)
memcpy(buf + n, rb->buf, MIN(rb->end, copy_len - n));
}
buf[copy_len] = '\0';