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)
This commit is contained in:
parent
443f70e31a
commit
01ee43955c
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user