summaryrefslogtreecommitdiff
path: root/source/fitz
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2015-08-14 19:37:59 +0100
committerRobin Watts <robin.watts@artifex.com>2015-08-17 12:36:19 +0100
commitdda017988150901dccd6b9dcb2823d7d8522433b (patch)
treef6ee6d696c5170ccc686abb77fe0939263b6053e /source/fitz
parent88003e46fa0db666d4cbccdfa81857ca7853e55f (diff)
downloadmupdf-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/fitz')
-rw-r--r--source/fitz/stream-read.c17
1 files changed, 17 insertions, 0 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);
+}