summaryrefslogtreecommitdiff
path: root/libbio/bseek.c
diff options
context:
space:
mode:
authorCharles Forsyth <charles.forsyth@gmail.com>2013-06-06 20:59:23 +0000
committerCharles Forsyth <charles.forsyth@gmail.com>2013-06-06 20:59:23 +0000
commit72335078034e3cd7edcb1739556b405a3e1e9bf8 (patch)
tree9e1baa8ea80bfab1885cfcf224a62040a417fa74 /libbio/bseek.c
parent3a0400887de9df81e4d4fb3bc3dec52af2d49f80 (diff)
sync with plan 9
Diffstat (limited to 'libbio/bseek.c')
-rw-r--r--libbio/bseek.c21
1 files changed, 11 insertions, 10 deletions
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 <bio.h>
-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;
}
/*