diff options
author | tmm <tmm@FreeBSD.org> | 2002-10-20 23:13:05 +0000 |
---|---|---|
committer | tmm <tmm@FreeBSD.org> | 2002-10-20 23:13:05 +0000 |
commit | f70d2339384264994949fcacf0bb4b036c6a9b3a (patch) | |
tree | e565d4978f804d6d1f0e5dfe9870ecd6abc74d8c /sys/kern | |
parent | 372039cd6ff7cd063901f2520a41ee3a37345668 (diff) | |
download | FreeBSD-src-f70d2339384264994949fcacf0bb4b036c6a9b3a.zip FreeBSD-src-f70d2339384264994949fcacf0bb4b036c6a9b3a.tar.gz |
Fix the calculations of the length of the unread message buffer
contents. The code was subtracting two unsigned ints, stored the
result in a log and expected it to be the same as of a signed
subtraction; this does only work on platforms where int and long
have the same size (due to overflows).
Instead, cast to long before the subtraction; the numbers are
guaranteed to be small enough so that there will be no overflows
because of that.
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/subr_log.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/sys/kern/subr_log.c b/sys/kern/subr_log.c index 4caa153..5588982 100644 --- a/sys/kern/subr_log.c +++ b/sys/kern/subr_log.c @@ -147,7 +147,7 @@ logread(dev_t dev, struct uio *uio, int flag) logsoftc.sc_state &= ~LOG_RDWAIT; while (uio->uio_resid > 0) { - l = mbp->msg_bufx - mbp->msg_bufr; + l = (long)mbp->msg_bufx - mbp->msg_bufr; if (l < 0) l = mbp->msg_size - mbp->msg_bufr; l = min(l, uio->uio_resid); @@ -218,7 +218,7 @@ logioctl(dev_t dev, u_long com, caddr_t data, int flag, struct thread *td) /* return number of characters immediately available */ case FIONREAD: s = splhigh(); - l = msgbufp->msg_bufx - msgbufp->msg_bufr; + l = (long)msgbufp->msg_bufx - msgbufp->msg_bufr; splx(s); if (l < 0) l += msgbufp->msg_size; |