summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortmm <tmm@FreeBSD.org>2002-11-14 16:11:12 +0000
committertmm <tmm@FreeBSD.org>2002-11-14 16:11:12 +0000
commit6bce41dbe0c44950686bd7b136c004e7130f9dd6 (patch)
tree43c59d20ca303b0c353f058bda38bff242763540
parent7cae989d41cd6a44b2b01619a66c46530c0ede34 (diff)
downloadFreeBSD-src-6bce41dbe0c44950686bd7b136c004e7130f9dd6.zip
FreeBSD-src-6bce41dbe0c44950686bd7b136c004e7130f9dd6.tar.gz
Make the msg_size, msg_bufx and msg_bufr memebers of struct msgbuf
signed, since they describe a ring buffer and signed arithmetic is performed on them. This avoids some evilish casts. Since this changes all but two members of this structure, style(9) those remaining ones, too. Requested by: bde Reviewed by: bde (earlier version)
-rw-r--r--sys/kern/subr_log.c15
-rw-r--r--sys/kern/subr_prf.c5
-rw-r--r--sys/sys/msgbuf.h12
3 files changed, 15 insertions, 17 deletions
diff --git a/sys/kern/subr_log.c b/sys/kern/subr_log.c
index 5588982..7129310 100644
--- a/sys/kern/subr_log.c
+++ b/sys/kern/subr_log.c
@@ -127,9 +127,7 @@ static int
logread(dev_t dev, struct uio *uio, int flag)
{
struct msgbuf *mbp = msgbufp;
- long l;
- int s;
- int error = 0;
+ int error = 0, l, s;
s = splhigh();
while (mbp->msg_bufr == mbp->msg_bufx) {
@@ -147,14 +145,14 @@ logread(dev_t dev, struct uio *uio, int flag)
logsoftc.sc_state &= ~LOG_RDWAIT;
while (uio->uio_resid > 0) {
- l = (long)mbp->msg_bufx - mbp->msg_bufr;
+ l = mbp->msg_bufx - mbp->msg_bufr;
if (l < 0)
l = mbp->msg_size - mbp->msg_bufr;
- l = min(l, uio->uio_resid);
+ l = imin(l, uio->uio_resid);
if (l == 0)
break;
error = uiomove((caddr_t)msgbufp->msg_ptr + mbp->msg_bufr,
- (int)l, uio);
+ l, uio);
if (error)
break;
mbp->msg_bufr += l;
@@ -210,15 +208,14 @@ logtimeout(void *arg)
static int
logioctl(dev_t dev, u_long com, caddr_t data, int flag, struct thread *td)
{
- long l;
- int s;
+ int l, s;
switch (com) {
/* return number of characters immediately available */
case FIONREAD:
s = splhigh();
- l = (long)msgbufp->msg_bufx - msgbufp->msg_bufr;
+ l = msgbufp->msg_bufx - msgbufp->msg_bufr;
splx(s);
if (l < 0)
l += msgbufp->msg_size;
diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c
index b7a818b..e8cef1b 100644
--- a/sys/kern/subr_prf.c
+++ b/sys/kern/subr_prf.c
@@ -820,7 +820,7 @@ msgbufcopy(struct msgbuf *oldp)
}
void
-msgbufinit(void *ptr, size_t size)
+msgbufinit(void *ptr, int size)
{
char *cp;
static struct msgbuf *oldp = NULL;
@@ -829,7 +829,8 @@ msgbufinit(void *ptr, size_t size)
cp = (char *)ptr;
msgbufp = (struct msgbuf *) (cp + size);
if (msgbufp->msg_magic != MSG_MAGIC || msgbufp->msg_size != size ||
- msgbufp->msg_bufx >= size || msgbufp->msg_bufr >= size) {
+ msgbufp->msg_bufx >= size || msgbufp->msg_bufx < 0 ||
+ msgbufp->msg_bufr >= size || msgbufp->msg_bufr < 0) {
bzero(cp, size);
bzero(msgbufp, sizeof(*msgbufp));
msgbufp->msg_magic = MSG_MAGIC;
diff --git a/sys/sys/msgbuf.h b/sys/sys/msgbuf.h
index 7ac13bf..e6f6da2 100644
--- a/sys/sys/msgbuf.h
+++ b/sys/sys/msgbuf.h
@@ -39,17 +39,17 @@
struct msgbuf {
#define MSG_MAGIC 0x063062
- unsigned int msg_magic;
- unsigned int msg_size; /* size of buffer area */
- unsigned int msg_bufx; /* write pointer */
- unsigned int msg_bufr; /* read pointer */
- char * msg_ptr; /* pointer to buffer */
+ u_int msg_magic;
+ int msg_size; /* size of buffer area */
+ int msg_bufx; /* write pointer */
+ int msg_bufr; /* read pointer */
+ char *msg_ptr; /* pointer to buffer */
};
#ifdef _KERNEL
extern int msgbuftrigger;
extern struct msgbuf *msgbufp;
-void msgbufinit(void *ptr, size_t size);
+void msgbufinit(void *ptr, int size);
#if !defined(MSGBUF_SIZE)
#define MSGBUF_SIZE 32768
OpenPOWER on IntegriCloud