diff options
author | Robin Watts <robin.watts@artifex.com> | 2015-08-14 19:37:59 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2015-08-17 12:36:19 +0100 |
commit | dda017988150901dccd6b9dcb2823d7d8522433b (patch) | |
tree | f6ee6d696c5170ccc686abb77fe0939263b6053e /source | |
parent | 88003e46fa0db666d4cbccdfa81857ca7853e55f (diff) | |
download | mupdf-dda017988150901dccd6b9dcb2823d7d8522433b.tar.xz |
Add fz_read_string function to read a null terminated string
Use that within gproof. The existing use of fz_read_line was broken
and was resulting in bad values for separations.
Diffstat (limited to 'source')
-rw-r--r-- | source/fitz/stream-read.c | 17 | ||||
-rw-r--r-- | source/gprf/gprf-doc.c | 2 |
2 files changed, 18 insertions, 1 deletions
diff --git a/source/fitz/stream-read.c b/source/fitz/stream-read.c index f85b7612..927addb0 100644 --- a/source/fitz/stream-read.c +++ b/source/fitz/stream-read.c @@ -291,3 +291,20 @@ int64_t fz_read_int64(fz_context *ctx, fz_stream *stm) { return (int64_t)fz_read int16_t fz_read_int16_le(fz_context *ctx, fz_stream *stm) { return (int16_t)fz_read_uint16_le(ctx, stm); } int32_t fz_read_int32_le(fz_context *ctx, fz_stream *stm) { return (int32_t)fz_read_uint32_le(ctx, stm); } int64_t fz_read_int64_le(fz_context *ctx, fz_stream *stm) { return (int64_t)fz_read_uint64_le(ctx, stm); } + +void fz_read_string(fz_context *ctx, fz_stream *stm, char *buffer, int len) +{ + int c; + do + { + if (len <= 0) + fz_throw(ctx, FZ_ERROR_GENERIC, "Buffer overrun reading null terminated string"); + + c = fz_read_byte(ctx, stm); + if (c == EOF) + fz_throw(ctx, FZ_ERROR_GENERIC, "EOF reading null terminated string"); + *buffer++ = c; + len--; + } + while (c != 0); +} diff --git a/source/gprf/gprf-doc.c b/source/gprf/gprf-doc.c index 02562ca7..d0551816 100644 --- a/source/gprf/gprf-doc.c +++ b/source/gprf/gprf-doc.c @@ -556,7 +556,7 @@ read_tiles(fz_context *ctx, gprf_page *page) char blatter[4096]; int32_t rgba = fz_read_int32_le(ctx, file); int32_t cmyk = fz_read_int32_le(ctx, file); - fz_read_line(ctx, file, blatter, sizeof(blatter)); + fz_read_string(ctx, file, blatter, sizeof(blatter)); fz_add_separation(ctx, page->separations, rgba, cmyk, blatter); } |