aboutsummaryrefslogtreecommitdiff
path: root/src/base/ftsystem.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/base/ftsystem.c')
-rw-r--r--src/base/ftsystem.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/base/ftsystem.c b/src/base/ftsystem.c
index fcd289d19..61c99e363 100644
--- a/src/base/ftsystem.c
+++ b/src/base/ftsystem.c
@@ -206,7 +206,7 @@
* The number of bytes to read from the stream.
*
* @Return:
- * The number of bytes actually read. If `count' is zero (this is,
+ * The number of bytes actually read. If `count' is zero (that is,
* the function is used for seeking), a non-zero return value
* indicates an error.
*/
@@ -219,7 +219,7 @@
FT_FILE* file;
- if ( !count && offset > stream->size )
+ if ( offset > stream->size && !count )
return 1;
file = STREAM_FILE( stream );
@@ -227,6 +227,11 @@
if ( stream->pos != offset )
ft_fseek( file, (long)offset, SEEK_SET );
+ /* Avoid calling `fread` with `buffer=NULL` and `count=0`, */
+ /* which is undefined behaviour. */
+ if ( !count )
+ return 0;
+
return (unsigned long)ft_fread( buffer, 1, count, file );
}