From dda017988150901dccd6b9dcb2823d7d8522433b Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Fri, 14 Aug 2015 19:37:59 +0100 Subject: 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. --- source/fitz/stream-read.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'source/fitz') 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); +} -- cgit v1.2.3