summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/freetype/src/base/ftstream.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/freetype/src/base/ftstream.c')
-rw-r--r--src/3rdparty/freetype/src/base/ftstream.c131
1 files changed, 68 insertions, 63 deletions
diff --git a/src/3rdparty/freetype/src/base/ftstream.c b/src/3rdparty/freetype/src/base/ftstream.c
index d940254d8b..64826acebe 100644
--- a/src/3rdparty/freetype/src/base/ftstream.c
+++ b/src/3rdparty/freetype/src/base/ftstream.c
@@ -4,7 +4,7 @@
*
* I/O stream support (body).
*
- * Copyright (C) 2000-2020 by
+ * Copyright (C) 2000-2023 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used,
@@ -61,7 +61,7 @@
if ( stream->read )
{
- if ( stream->read( stream, pos, 0, 0 ) )
+ if ( stream->read( stream, pos, NULL, 0 ) )
{
FT_ERROR(( "FT_Stream_Seek:"
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
@@ -141,7 +141,9 @@
if ( read_bytes > count )
read_bytes = count;
- FT_MEM_COPY( buffer, stream->base + pos, read_bytes );
+ /* Allow "reading" zero bytes without UB even if buffer is NULL */
+ if ( count )
+ FT_MEM_COPY( buffer, stream->base + pos, read_bytes );
}
stream->pos = pos + read_bytes;
@@ -178,7 +180,9 @@
if ( read_bytes > count )
read_bytes = count;
- FT_MEM_COPY( buffer, stream->base + stream->pos, read_bytes );
+ /* Allow "reading" zero bytes without UB even if buffer is NULL */
+ if ( count )
+ FT_MEM_COPY( buffer, stream->base + stream->pos, read_bytes );
}
stream->pos += read_bytes;
@@ -261,7 +265,7 @@
}
#ifdef FT_DEBUG_MEMORY
- /* assume _ft_debug_file and _ft_debug_lineno are already set */
+ /* assume `ft_debug_file_` and `ft_debug_lineno_` are already set */
stream->base = (unsigned char*)ft_mem_qalloc( memory,
(FT_Long)count,
&error );
@@ -347,27 +351,27 @@
}
- FT_BASE_DEF( FT_Char )
- FT_Stream_GetChar( FT_Stream stream )
+ FT_BASE_DEF( FT_Byte )
+ FT_Stream_GetByte( FT_Stream stream )
{
- FT_Char result;
+ FT_Byte result;
FT_ASSERT( stream && stream->cursor );
result = 0;
if ( stream->cursor < stream->limit )
- result = (FT_Char)*stream->cursor++;
+ result = *stream->cursor++;
return result;
}
- FT_BASE_DEF( FT_UShort )
+ FT_BASE_DEF( FT_UInt16 )
FT_Stream_GetUShort( FT_Stream stream )
{
FT_Byte* p;
- FT_UShort result;
+ FT_UInt16 result;
FT_ASSERT( stream && stream->cursor );
@@ -382,11 +386,11 @@
}
- FT_BASE_DEF( FT_UShort )
+ FT_BASE_DEF( FT_UInt16 )
FT_Stream_GetUShortLE( FT_Stream stream )
{
FT_Byte* p;
- FT_UShort result;
+ FT_UInt16 result;
FT_ASSERT( stream && stream->cursor );
@@ -401,11 +405,11 @@
}
- FT_BASE_DEF( FT_ULong )
+ FT_BASE_DEF( FT_UInt32 )
FT_Stream_GetUOffset( FT_Stream stream )
{
FT_Byte* p;
- FT_ULong result;
+ FT_UInt32 result;
FT_ASSERT( stream && stream->cursor );
@@ -419,11 +423,11 @@
}
- FT_BASE_DEF( FT_ULong )
+ FT_BASE_DEF( FT_UInt32 )
FT_Stream_GetULong( FT_Stream stream )
{
FT_Byte* p;
- FT_ULong result;
+ FT_UInt32 result;
FT_ASSERT( stream && stream->cursor );
@@ -437,11 +441,11 @@
}
- FT_BASE_DEF( FT_ULong )
+ FT_BASE_DEF( FT_UInt32 )
FT_Stream_GetULongLE( FT_Stream stream )
{
FT_Byte* p;
- FT_ULong result;
+ FT_UInt32 result;
FT_ASSERT( stream && stream->cursor );
@@ -455,8 +459,8 @@
}
- FT_BASE_DEF( FT_Char )
- FT_Stream_ReadChar( FT_Stream stream,
+ FT_BASE_DEF( FT_Byte )
+ FT_Stream_ReadByte( FT_Stream stream,
FT_Error* error )
{
FT_Byte result = 0;
@@ -464,47 +468,46 @@
FT_ASSERT( stream );
- *error = FT_Err_Ok;
-
- if ( stream->read )
- {
- if ( stream->read( stream, stream->pos, &result, 1L ) != 1L )
- goto Fail;
- }
- else
+ if ( stream->pos < stream->size )
{
- if ( stream->pos < stream->size )
- result = stream->base[stream->pos];
+ if ( stream->read )
+ {
+ if ( stream->read( stream, stream->pos, &result, 1L ) != 1L )
+ goto Fail;
+ }
else
- goto Fail;
+ result = stream->base[stream->pos];
}
+ else
+ goto Fail;
+
stream->pos++;
- return (FT_Char)result;
+ *error = FT_Err_Ok;
+
+ return result;
Fail:
*error = FT_THROW( Invalid_Stream_Operation );
- FT_ERROR(( "FT_Stream_ReadChar:"
+ FT_ERROR(( "FT_Stream_ReadByte:"
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
- return 0;
+ return result;
}
- FT_BASE_DEF( FT_UShort )
+ FT_BASE_DEF( FT_UInt16 )
FT_Stream_ReadUShort( FT_Stream stream,
FT_Error* error )
{
FT_Byte reads[2];
- FT_Byte* p = 0;
- FT_UShort result = 0;
+ FT_Byte* p;
+ FT_UInt16 result = 0;
FT_ASSERT( stream );
- *error = FT_Err_Ok;
-
if ( stream->pos + 1 < stream->size )
{
if ( stream->read )
@@ -525,6 +528,8 @@
stream->pos += 2;
+ *error = FT_Err_Ok;
+
return result;
Fail:
@@ -533,23 +538,21 @@
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
- return 0;
+ return result;
}
- FT_BASE_DEF( FT_UShort )
+ FT_BASE_DEF( FT_UInt16 )
FT_Stream_ReadUShortLE( FT_Stream stream,
FT_Error* error )
{
FT_Byte reads[2];
- FT_Byte* p = 0;
- FT_UShort result = 0;
+ FT_Byte* p;
+ FT_UInt16 result = 0;
FT_ASSERT( stream );
- *error = FT_Err_Ok;
-
if ( stream->pos + 1 < stream->size )
{
if ( stream->read )
@@ -570,6 +573,8 @@
stream->pos += 2;
+ *error = FT_Err_Ok;
+
return result;
Fail:
@@ -578,7 +583,7 @@
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
- return 0;
+ return result;
}
@@ -587,14 +592,12 @@
FT_Error* error )
{
FT_Byte reads[3];
- FT_Byte* p = 0;
+ FT_Byte* p;
FT_ULong result = 0;
FT_ASSERT( stream );
- *error = FT_Err_Ok;
-
if ( stream->pos + 2 < stream->size )
{
if ( stream->read )
@@ -615,6 +618,8 @@
stream->pos += 3;
+ *error = FT_Err_Ok;
+
return result;
Fail:
@@ -623,23 +628,21 @@
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
- return 0;
+ return result;
}
- FT_BASE_DEF( FT_ULong )
+ FT_BASE_DEF( FT_UInt32 )
FT_Stream_ReadULong( FT_Stream stream,
FT_Error* error )
{
FT_Byte reads[4];
- FT_Byte* p = 0;
- FT_ULong result = 0;
+ FT_Byte* p;
+ FT_UInt32 result = 0;
FT_ASSERT( stream );
- *error = FT_Err_Ok;
-
if ( stream->pos + 3 < stream->size )
{
if ( stream->read )
@@ -660,6 +663,8 @@
stream->pos += 4;
+ *error = FT_Err_Ok;
+
return result;
Fail:
@@ -668,23 +673,21 @@
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
- return 0;
+ return result;
}
- FT_BASE_DEF( FT_ULong )
+ FT_BASE_DEF( FT_UInt32 )
FT_Stream_ReadULongLE( FT_Stream stream,
FT_Error* error )
{
FT_Byte reads[4];
- FT_Byte* p = 0;
- FT_ULong result = 0;
+ FT_Byte* p;
+ FT_UInt32 result = 0;
FT_ASSERT( stream );
- *error = FT_Err_Ok;
-
if ( stream->pos + 3 < stream->size )
{
if ( stream->read )
@@ -705,6 +708,8 @@
stream->pos += 4;
+ *error = FT_Err_Ok;
+
return result;
Fail:
@@ -713,7 +718,7 @@
" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
stream->pos, stream->size ));
- return 0;
+ return result;
}