summaryrefslogtreecommitdiff
path: root/fitz/stm_read.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2011-12-08 15:32:03 +0100
committerTor Andersson <tor.andersson@artifex.com>2011-12-08 21:46:55 +0100
commit34c971b594bad41fa6c2ad4a9798e5a18de129b5 (patch)
tree0c3956c35f827d1649e0520abf18974a4e0ec8e2 /fitz/stm_read.c
parente64a57b1e9c2ba6c6f54eff73c414be9e78dafbe (diff)
downloadmupdf-34c971b594bad41fa6c2ad4a9798e5a18de129b5.tar.xz
Throw exceptions for read errors.
Diffstat (limited to 'fitz/stm_read.c')
-rw-r--r--fitz/stm_read.c46
1 files changed, 17 insertions, 29 deletions
diff --git a/fitz/stm_read.c b/fitz/stm_read.c
index 5622a24f..9f9fc302 100644
--- a/fitz/stm_read.c
+++ b/fitz/stm_read.c
@@ -20,12 +20,7 @@ fz_read(fz_stream *stm, unsigned char *buf, int len)
if (len - count < stm->ep - stm->bp)
{
n = stm->read(stm, stm->bp, stm->ep - stm->bp);
- if (n < 0)
- {
- stm->error = 1;
- return fz_error_note(n, "read error");
- }
- else if (n == 0)
+ if (n == 0)
{
stm->eof = 1;
}
@@ -47,12 +42,7 @@ fz_read(fz_stream *stm, unsigned char *buf, int len)
else
{
n = stm->read(stm, buf + count, len - count);
- if (n < 0)
- {
- stm->error = 1;
- return fz_error_note(n, "read error");
- }
- else if (n == 0)
+ if (n == 0)
{
stm->eof = 1;
}
@@ -76,21 +66,24 @@ fz_fill_buffer(fz_stream *stm)
if (stm->error || stm->eof)
return;
- n = stm->read(stm, stm->bp, stm->ep - stm->bp);
- if (n < 0)
+ fz_try(stm->ctx)
{
- stm->error = 1;
- fz_error_handle(n, "read error; treating as end of file");
- }
- else if (n == 0)
- {
- stm->eof = 1;
+ n = stm->read(stm, stm->bp, stm->ep - stm->bp);
+ if (n == 0)
+ {
+ stm->eof = 1;
+ }
+ else if (n > 0)
+ {
+ stm->rp = stm->bp;
+ stm->wp = stm->bp + n;
+ stm->pos += n;
+ }
}
- else if (n > 0)
+ fz_catch(stm->ctx)
{
- stm->rp = stm->bp;
- stm->wp = stm->bp + n;
- stm->pos += n;
+ fz_warn(stm->ctx, "read error; treating as end of file");
+ stm->error = 1;
}
}
@@ -118,11 +111,6 @@ fz_read_all(fz_stream *stm, int initial)
}
n = fz_read(stm, buf->data + buf->len, buf->cap - buf->len);
- if (n < 0)
- {
- fz_drop_buffer(ctx, buf);
- fz_throw(ctx, "read error");
- }
if (n == 0)
break;