1 /****************************************************************************
2 *
3 * ftstream.c
4 *
5 * I/O stream support (body).
6 *
7 * Copyright (C) 2000-2019 by
8 * David Turner, Robert Wilhelm, and Werner Lemberg.
9 *
10 * This file is part of the FreeType project, and may only be used,
11 * modified, and distributed under the terms of the FreeType project
12 * license, LICENSE.TXT. By continuing to use, modify, or distribute
13 * this file you indicate that you have read the license and
14 * understand and accept it fully.
15 *
16 */
17
18
19 #include <ft2build.h>
20 #include FT_INTERNAL_STREAM_H
21 #include FT_INTERNAL_DEBUG_H
22
23
24 /**************************************************************************
25 *
26 * The macro FT_COMPONENT is used in trace mode. It is an implicit
27 * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
269 if ( error )
270 goto Exit;
271 #else
272 if ( FT_QALLOC( stream->base, count ) )
273 goto Exit;
274 #endif
275 /* read it */
276 read_bytes = stream->read( stream, stream->pos,
277 stream->base, count );
278 if ( read_bytes < count )
279 {
280 FT_ERROR(( "FT_Stream_EnterFrame:"
281 " invalid read; expected %lu bytes, got %lu\n",
282 count, read_bytes ));
283
284 FT_FREE( stream->base );
285 error = FT_THROW( Invalid_Stream_Operation );
286 }
287
288 stream->cursor = stream->base;
289 stream->limit = stream->cursor + count;
290 stream->pos += read_bytes;
291 }
292 else
293 {
294 /* check current and new position */
295 if ( stream->pos >= stream->size ||
296 stream->size - stream->pos < count )
297 {
298 FT_ERROR(( "FT_Stream_EnterFrame:"
299 " invalid i/o; pos = 0x%lx, count = %lu, size = 0x%lx\n",
300 stream->pos, count, stream->size ));
301
302 error = FT_THROW( Invalid_Stream_Operation );
303 goto Exit;
304 }
305
306 /* set cursor */
307 stream->cursor = stream->base + stream->pos;
308 stream->limit = stream->cursor + count;
309 stream->pos += count;
|
1 /****************************************************************************
2 *
3 * ftstream.c
4 *
5 * I/O stream support (body).
6 *
7 * Copyright (C) 2000-2020 by
8 * David Turner, Robert Wilhelm, and Werner Lemberg.
9 *
10 * This file is part of the FreeType project, and may only be used,
11 * modified, and distributed under the terms of the FreeType project
12 * license, LICENSE.TXT. By continuing to use, modify, or distribute
13 * this file you indicate that you have read the license and
14 * understand and accept it fully.
15 *
16 */
17
18
19 #include <ft2build.h>
20 #include FT_INTERNAL_STREAM_H
21 #include FT_INTERNAL_DEBUG_H
22
23
24 /**************************************************************************
25 *
26 * The macro FT_COMPONENT is used in trace mode. It is an implicit
27 * parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log
269 if ( error )
270 goto Exit;
271 #else
272 if ( FT_QALLOC( stream->base, count ) )
273 goto Exit;
274 #endif
275 /* read it */
276 read_bytes = stream->read( stream, stream->pos,
277 stream->base, count );
278 if ( read_bytes < count )
279 {
280 FT_ERROR(( "FT_Stream_EnterFrame:"
281 " invalid read; expected %lu bytes, got %lu\n",
282 count, read_bytes ));
283
284 FT_FREE( stream->base );
285 error = FT_THROW( Invalid_Stream_Operation );
286 }
287
288 stream->cursor = stream->base;
289 stream->limit = FT_OFFSET( stream->cursor, count );
290 stream->pos += read_bytes;
291 }
292 else
293 {
294 /* check current and new position */
295 if ( stream->pos >= stream->size ||
296 stream->size - stream->pos < count )
297 {
298 FT_ERROR(( "FT_Stream_EnterFrame:"
299 " invalid i/o; pos = 0x%lx, count = %lu, size = 0x%lx\n",
300 stream->pos, count, stream->size ));
301
302 error = FT_THROW( Invalid_Stream_Operation );
303 goto Exit;
304 }
305
306 /* set cursor */
307 stream->cursor = stream->base + stream->pos;
308 stream->limit = stream->cursor + count;
309 stream->pos += count;
|