From 72335078034e3cd7edcb1739556b405a3e1e9bf8 Mon Sep 17 00:00:00 2001 From: Charles Forsyth Date: Thu, 6 Jun 2013 20:59:23 +0000 Subject: sync with plan 9 --- libbio/bseek.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'libbio/bseek.c') diff --git a/libbio/bseek.c b/libbio/bseek.c index 9e68f5ea..32e8dda4 100644 --- a/libbio/bseek.c +++ b/libbio/bseek.c @@ -1,10 +1,10 @@ #include "lib9.h" #include -long -Bseek(Biobuf *bp, long offset, int base) +vlong +Bseek(Biobuf *bp, vlong offset, int base) { - long n, d; + vlong n, d; switch(bp->state) { default: @@ -27,15 +27,16 @@ Bseek(Biobuf *bp, long offset, int base) * try to seek within buffer */ if(base == 0) { + /* + * if d is too large for an int, icount may wrap, + * so we need to ensure that icount hasn't wrapped + * and points within the buffer's valid data. + */ d = n - Boffset(bp); bp->icount += d; - if(d >= 0) { - if(bp->icount <= 0) - return n; - } else { - if(bp->ebuf - bp->gbuf >= -bp->icount) - return n; - } + if(d <= bp->bsize && bp->icount <= 0 && + bp->ebuf - bp->gbuf >= -bp->icount) + return n; } /* -- cgit v1.2.3