diff options
author | brian <brian@FreeBSD.org> | 1999-05-09 20:02:29 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 1999-05-09 20:02:29 +0000 |
commit | 00d71de444cebd8e8fb9f1a6f538b0e25756fcbd (patch) | |
tree | 35a86aa77f33435584f120d89d51596207ec30c1 /usr.sbin/ppp/mbuf.c | |
parent | 81c1d3f4c6f3f0dcb719616e43e48c3b8d72888e (diff) | |
download | FreeBSD-src-00d71de444cebd8e8fb9f1a6f538b0e25756fcbd.zip FreeBSD-src-00d71de444cebd8e8fb9f1a6f538b0e25756fcbd.tar.gz |
Deal with the fact that as we now mbuf_Read the fsm
header in fsm_Input() we often end up with a NULL mbuf.
Deal with a possible NULL mbuf being passed into
mbuf_Prepend().
Adjust some spacing to make things more consistent.
Diffstat (limited to 'usr.sbin/ppp/mbuf.c')
-rw-r--r-- | usr.sbin/ppp/mbuf.c | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/usr.sbin/ppp/mbuf.c b/usr.sbin/ppp/mbuf.c index e9096aa..1dea2e2 100644 --- a/usr.sbin/ppp/mbuf.c +++ b/usr.sbin/ppp/mbuf.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: mbuf.c,v 1.24 1999/03/29 08:21:28 brian Exp $ + * $Id: mbuf.c,v 1.25 1999/05/08 11:07:07 brian Exp $ * */ #include <sys/types.h> @@ -45,13 +45,13 @@ static int totalalloced; static unsigned long long mbuf_Mallocs, mbuf_Frees; int -mbuf_Length(struct mbuf * bp) +mbuf_Length(struct mbuf *bp) { int len; for (len = 0; bp; bp = bp->next) len += bp->cnt; - return (len); + return len; } struct mbuf * @@ -155,7 +155,7 @@ mbuf_Prepend(struct mbuf *bp, const void *ptr, size_t len, size_t extra) { struct mbuf *head; - if (bp->offset) { + if (bp && bp->offset) { if (bp->offset >= len) { bp->offset -= len; bp->cnt += len; @@ -168,7 +168,7 @@ mbuf_Prepend(struct mbuf *bp, const void *ptr, size_t len, size_t extra) bp->offset = 0; } - head = mbuf_Alloc(len + extra, bp->type); + head = mbuf_Alloc(len + extra, bp ? bp->type : MB_FSM); head->offset = extra; head->cnt -= extra; memcpy(MBUF_CTOP(head), ptr, len); @@ -274,13 +274,15 @@ mbuf_Dequeue(struct mqueue *q) void mbuf_Enqueue(struct mqueue *queue, struct mbuf *bp) { - if (queue->last) { - queue->last->pnext = bp; - queue->last = bp; - } else - queue->last = queue->top = bp; - queue->qlen++; - log_Printf(LogDEBUG, "mbuf_Enqueue: len = %d\n", queue->qlen); + if (bp != NULL) { + if (queue->last) { + queue->last->pnext = bp; + queue->last = bp; + } else + queue->last = queue->top = bp; + queue->qlen++; + log_Printf(LogDEBUG, "mbuf_Enqueue: len = %d\n", queue->qlen); + } } struct mbuf * @@ -288,24 +290,26 @@ mbuf_Contiguous(struct mbuf *bp) { /* Put it all in one contigous (aligned) mbuf */ - if (bp->next != NULL) { - struct mbuf *nbp; - u_char *cp; + if (bp != NULL) { + if (bp->next != NULL) { + struct mbuf *nbp; + u_char *cp; - nbp = mbuf_Alloc(mbuf_Length(bp), bp->type); + nbp = mbuf_Alloc(mbuf_Length(bp), bp->type); - for (cp = MBUF_CTOP(nbp); bp; bp = mbuf_FreeSeg(bp)) { - memcpy(cp, MBUF_CTOP(bp), bp->cnt); - cp += bp->cnt; + for (cp = MBUF_CTOP(nbp); bp; bp = mbuf_FreeSeg(bp)) { + memcpy(cp, MBUF_CTOP(bp), bp->cnt); + cp += bp->cnt; + } + bp = nbp; } - bp = nbp; - } #ifndef __i386__ /* Do any other archs not care about alignment ? */ - else if ((bp->offset & 0x03) != 0) { - bcopy(MBUF_CTOP(bp), bp + 1, bp->cnt); - bp->offset = 0; - } + else if ((bp->offset & 0x03) != 0) { + bcopy(MBUF_CTOP(bp), bp + 1, bp->cnt); + bp->offset = 0; + } #endif + } return bp; } |