summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/freetype/src/gzip/ftgzip.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/freetype/src/gzip/ftgzip.c')
-rw-r--r--src/3rdparty/freetype/src/gzip/ftgzip.c147
1 files changed, 125 insertions, 22 deletions
diff --git a/src/3rdparty/freetype/src/gzip/ftgzip.c b/src/3rdparty/freetype/src/gzip/ftgzip.c
index 6f0c515723..2d4200d9fa 100644
--- a/src/3rdparty/freetype/src/gzip/ftgzip.c
+++ b/src/3rdparty/freetype/src/gzip/ftgzip.c
@@ -8,7 +8,7 @@
/* parse compressed PCF fonts, as found with many X11 server */
/* distributions. */
/* */
-/* Copyright 2002, 2003, 2004, 2005, 2006, 2009 by */
+/* Copyright 2002-2006, 2009-2014 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -32,6 +32,7 @@
#undef __FTERRORS_H__
+#undef FT_ERR_PREFIX
#define FT_ERR_PREFIX Gzip_Err_
#define FT_ERR_BASE FT_Mod_Err_Gzip
@@ -42,7 +43,7 @@
#ifdef FT_CONFIG_OPTION_PIC
#error "gzip code does not support PIC yet"
-#endif
+#endif
#ifdef FT_CONFIG_OPTION_SYSTEM_ZLIB
@@ -67,6 +68,15 @@
#undef SLOW
#define SLOW 1 /* we can't use asm-optimized sources here! */
+#if defined( _MSC_VER ) /* Visual C++ (and Intel C++) */
+ /* We disable the warning `conversion from XXX to YYY, */
+ /* possible loss of data' in order to compile cleanly with */
+ /* the maximum level of warnings: zlib is non-FreeType */
+ /* code. */
+#pragma warning( push )
+#pragma warning( disable : 4244 )
+#endif /* _MSC_VER */
+
/* Urgh. `inflate_mask' must not be declared twice -- C++ doesn't like
this. We temporarily disable it and load all necessary header files. */
#define NO_INFLATE_MASK
@@ -86,6 +96,10 @@
#include "inflate.c"
#include "adler32.c"
+#if defined( _MSC_VER )
+#pragma warning( pop )
+#endif
+
#endif /* !FT_CONFIG_OPTION_SYSTEM_ZLIB */
@@ -107,7 +121,7 @@
{
FT_ULong sz = (FT_ULong)size * items;
FT_Error error;
- FT_Pointer p;
+ FT_Pointer p = NULL;
(void)FT_ALLOC( p, sz );
@@ -194,12 +208,12 @@
/* head[0] && head[1] are the magic numbers; */
/* head[2] is the method, and head[3] the flags */
- if ( head[0] != 0x1f ||
- head[1] != 0x8b ||
+ if ( head[0] != 0x1F ||
+ head[1] != 0x8B ||
head[2] != Z_DEFLATED ||
(head[3] & FT_GZIP_RESERVED) )
{
- error = Gzip_Err_Invalid_File_Format;
+ error = FT_THROW( Invalid_File_Format );
goto Exit;
}
@@ -261,7 +275,7 @@
FT_Stream source )
{
z_stream* zstream = &zip->zstream;
- FT_Error error = Gzip_Err_Ok;
+ FT_Error error = FT_Err_Ok;
zip->stream = stream;
@@ -293,7 +307,7 @@
if ( inflateInit2( zstream, -MAX_WBITS ) != Z_OK ||
zstream->next_in == NULL )
- error = Gzip_Err_Invalid_File_Format;
+ error = FT_THROW( Invalid_File_Format );
Exit:
return error;
@@ -364,7 +378,7 @@
size = stream->read( stream, stream->pos, zip->input,
FT_GZIP_BUFFER_SIZE );
if ( size == 0 )
- return Gzip_Err_Invalid_Stream_Operation;
+ return FT_THROW( Invalid_Stream_Operation );
}
else
{
@@ -373,7 +387,7 @@
size = FT_GZIP_BUFFER_SIZE;
if ( size == 0 )
- return Gzip_Err_Invalid_Stream_Operation;
+ return FT_THROW( Invalid_Stream_Operation );
FT_MEM_COPY( zip->input, stream->base + stream->pos, size );
}
@@ -382,7 +396,7 @@
zstream->next_in = zip->input;
zstream->avail_in = size;
- return Gzip_Err_Ok;
+ return FT_Err_Ok;
}
@@ -390,7 +404,7 @@
ft_gzip_file_fill_output( FT_GZipFile zip )
{
z_stream* zstream = &zip->zstream;
- FT_Error error = 0;
+ FT_Error error = FT_Err_Ok;
zip->cursor = zip->buffer;
@@ -415,12 +429,12 @@
{
zip->limit = zstream->next_out;
if ( zip->limit == zip->cursor )
- error = Gzip_Err_Invalid_Stream_Operation;
+ error = FT_THROW( Invalid_Stream_Operation );
break;
}
else if ( err != Z_OK )
{
- error = Gzip_Err_Invalid_Stream_Operation;
+ error = FT_THROW( Invalid_Stream_Operation );
break;
}
}
@@ -434,7 +448,7 @@
ft_gzip_file_skip_output( FT_GZipFile zip,
FT_ULong count )
{
- FT_Error error = Gzip_Err_Ok;
+ FT_Error error = FT_Err_Ok;
FT_ULong delta;
@@ -571,7 +585,7 @@
old_pos = stream->pos;
if ( !FT_Stream_Seek( stream, stream->size - 4 ) )
{
- result = (FT_ULong)FT_Stream_ReadLong( stream, &error );
+ result = FT_Stream_ReadULong( stream, &error );
if ( error )
result = 0;
@@ -582,15 +596,25 @@
}
+ /* documentation is in ftgzip.h */
+
FT_EXPORT_DEF( FT_Error )
FT_Stream_OpenGzip( FT_Stream stream,
FT_Stream source )
{
FT_Error error;
- FT_Memory memory = source->memory;
- FT_GZipFile zip;
+ FT_Memory memory;
+ FT_GZipFile zip = NULL;
+ if ( !stream || !source )
+ {
+ error = FT_THROW( Invalid_Stream_Handle );
+ goto Exit;
+ }
+
+ memory = source->memory;
+
/*
* check the header right now; this prevents allocating un-necessary
* objects when we don't need them
@@ -628,7 +652,7 @@
if ( zip_size != 0 && zip_size < 40 * 1024 )
{
- FT_Byte* zip_buff;
+ FT_Byte* zip_buff = NULL;
if ( !FT_ALLOC( zip_buff, zip_size ) )
@@ -656,7 +680,7 @@
ft_gzip_file_io( zip, 0, NULL, 0 );
FT_FREE( zip_buff );
}
- error = 0;
+ error = FT_Err_Ok;
}
}
@@ -670,7 +694,69 @@
return error;
}
-#else /* !FT_CONFIG_OPTION_USE_ZLIB */
+
+ /* documentation is in ftgzip.h */
+
+ FT_EXPORT_DEF( FT_Error )
+ FT_Gzip_Uncompress( FT_Memory memory,
+ FT_Byte* output,
+ FT_ULong* output_len,
+ const FT_Byte* input,
+ FT_ULong input_len )
+ {
+ z_stream stream;
+ int err;
+
+
+ /* check for `input' delayed to `inflate' */
+
+ if ( !memory || ! output_len || !output )
+ return FT_THROW( Invalid_Argument );
+
+ /* this function is modeled after zlib's `uncompress' function */
+
+ stream.next_in = (Bytef*)input;
+ stream.avail_in = (uInt)input_len;
+
+ stream.next_out = output;
+ stream.avail_out = (uInt)*output_len;
+
+ stream.zalloc = (alloc_func)ft_gzip_alloc;
+ stream.zfree = (free_func) ft_gzip_free;
+ stream.opaque = memory;
+
+ err = inflateInit2( &stream, MAX_WBITS );
+ if ( err != Z_OK )
+ return FT_THROW( Invalid_Argument );
+
+ err = inflate( &stream, Z_FINISH );
+ if ( err != Z_STREAM_END )
+ {
+ inflateEnd( &stream );
+ if ( err == Z_OK )
+ err = Z_BUF_ERROR;
+ }
+ else
+ {
+ *output_len = stream.total_out;
+
+ err = inflateEnd( &stream );
+ }
+
+ if ( err == Z_MEM_ERROR )
+ return FT_THROW( Out_Of_Memory );
+
+ if ( err == Z_BUF_ERROR )
+ return FT_THROW( Array_Too_Large );
+
+ if ( err == Z_DATA_ERROR )
+ return FT_THROW( Invalid_Table );
+
+ return FT_Err_Ok;
+ }
+
+
+#else /* !FT_CONFIG_OPTION_USE_ZLIB */
FT_EXPORT_DEF( FT_Error )
FT_Stream_OpenGzip( FT_Stream stream,
@@ -679,7 +765,24 @@
FT_UNUSED( stream );
FT_UNUSED( source );
- return Gzip_Err_Unimplemented_Feature;
+ return FT_THROW( Unimplemented_Feature );
+ }
+
+
+ FT_EXPORT_DEF( FT_Error )
+ FT_Gzip_Uncompress( FT_Memory memory,
+ FT_Byte* output,
+ FT_ULong* output_len,
+ const FT_Byte* input,
+ FT_ULong input_len )
+ {
+ FT_UNUSED( memory );
+ FT_UNUSED( output );
+ FT_UNUSED( output_len );
+ FT_UNUSED( input );
+ FT_UNUSED( input_len );
+
+ return FT_THROW( Unimplemented_Feature );
}
#endif /* !FT_CONFIG_OPTION_USE_ZLIB */