Added a lot of error checking code to the exported functions in the `base'

subdir (not complete yet).
This commit is contained in:
Werner Lemberg 2000-06-02 00:01:14 +00:00
parent d66ea312f6
commit 2fbf7e439f
9 changed files with 263 additions and 72 deletions

View File

@ -122,6 +122,12 @@
FT_Extension_Registry* registry;
if ( !driver )
return FT_Err_Invalid_Driver_Handle;
if ( !class )
return FT_Err_Invalid_Argument;
registry = (FT_Extension_Registry*)driver->extensions;
if ( registry )
{
@ -172,6 +178,9 @@
FT_Extension_Registry* registry;
if ( !face || !extension_id || !extension_interface )
return 0;
registry = (FT_Extension_Registry*)face->driver->extensions;
if ( registry && face->extensions )
{
@ -190,6 +199,7 @@
/* could not find the extension id */
*extension_interface = 0;
return 0;
}

View File

@ -86,7 +86,7 @@
/* */
/* <Note> */
/* If the font contains glyph outlines, these will be automatically */
/* converted to a bitmap according to the value of `grays' */
/* converted to a bitmap according to the value of `grays'. */
/* */
/* If `grays' is set to 0, the result is a 1-bit monochrome bitmap */
/* otherwise, it is an 8-bit gray-level bitmap. */
@ -121,6 +121,12 @@
FT_Pos origin_y = 0;
if ( !face )
return FT_Err_Invalid_Face_Handle;
if ( !abitglyph )
return FT_Err_Invalid_Argument;
*abitglyph = 0;
if ( origin )
@ -304,6 +310,11 @@
FT_OutlineGlyph glyph;
/* test for valid face delayed to FT_Load_Glyph() */
if ( !vecglyph )
return FT_Err_Invalid_Argument;
*vecglyph = 0;
/* check that NO_OUTLINE and NO_RECURSE are not set */
@ -394,6 +405,9 @@
FT_Matrix* matrix,
FT_Vector* delta )
{
if ( !face )
return;
face->transform_flags = 0;
if ( !matrix )
@ -496,6 +510,9 @@
FT_EXPORT_FUNC( void ) FT_Glyph_Get_Box( FT_Glyph glyph,
FT_BBox* box )
{
if ( !box )
return;
box->xMin = box->xMax = 0;
box->yMin = box->yMax = 0;
@ -529,7 +546,7 @@
default:
;
}
}
}

View File

@ -1632,7 +1632,7 @@
return error;
Invalid_Outline:
return -1;
return ErrRaster_Invalid_Outline;
}
#endif /* _STANDALONE_ */
@ -1797,11 +1797,11 @@
return 0;
if ( !outline || !outline->contours || !outline->points )
return -1;
return ErrRaster_Invalid_Outline;
if ( outline->n_points !=
outline->contours[outline->n_contours - 1] + 1 )
return -1;
return ErrRaster_Invalid_Outline;
if ( !target_map || !target_map->buffer )
return -1;

View File

@ -74,10 +74,12 @@ const FT_DriverInterface* ft_default_drivers[] =
/* */
FT_EXPORT_FUNC( void ) FT_Default_Drivers( FT_Library library )
{
FT_Error error;
const FT_DriverInterface* *cur;
FT_Error error;
const FT_DriverInterface** cur;
/* test for valid library delayed to FT_Add_Driver() */
cur = ft_default_drivers;
while ( *cur )
{

View File

@ -24,10 +24,13 @@
{
FT_Error error;
if ( !face )
return FT_Err_Invalid_Face_Handle;
error = FT_Err_Invalid_Argument;
if ( face && FT_HAS_MULTIPLE_MASTERS( face ) )
if ( FT_HAS_MULTIPLE_MASTERS( face ) )
{
FT_Driver driver = face->driver;
FT_Get_MM_Func func;
@ -51,9 +54,12 @@
FT_Error error;
if ( !face )
return FT_Err_Invalid_Face_Handle;
error = FT_Err_Invalid_Argument;
if ( face && FT_HAS_MULTIPLE_MASTERS( face ) )
if ( FT_HAS_MULTIPLE_MASTERS( face ) )
{
FT_Driver driver = face->driver;
FT_Set_MM_Design_Func func;
@ -77,9 +83,12 @@
FT_Error error;
if ( !face )
return FT_Err_Invalid_Face_Handle;
error = FT_Err_Invalid_Argument;
if ( face && FT_HAS_MULTIPLE_MASTERS( face ) )
if ( FT_HAS_MULTIPLE_MASTERS( face ) )
{
FT_Driver driver = face->driver;
FT_Set_MM_Blend_Func func;

View File

@ -217,6 +217,8 @@
/* <Description> */
/* Creates a new input stream object from an FT_Open_Args structure. */
/* */
/* <Note> */
/* The function expects a valid `astream' parameter. */
static
FT_Error ft_new_input_stream( FT_Library library,
FT_Open_Args* args,
@ -227,6 +229,12 @@
FT_Stream stream;
if ( !library )
return FT_Err_Invalid_Library_Handle;
if ( !args )
return FT_Err_Invalid_Argument;
*astream = 0;
memory = library->memory;
if ( ALLOC( stream, sizeof ( *stream ) ) )
@ -279,7 +287,7 @@
/* */
FT_EXPORT_FUNC( void ) FT_Done_Stream( FT_Stream stream )
{
if ( stream->close )
if ( stream && stream->close )
stream->close( stream );
}
@ -425,6 +433,9 @@
FT_Int n;
if ( !library )
return 0;
for ( n = 0; n < FT_MAX_GLYPH_FORMATS; n++ )
{
FT_Raster_Funcs* funcs = &library->raster_funcs[n];
@ -471,13 +482,21 @@
FT_EXPORT_FUNC( FT_Error ) FT_Set_Raster( FT_Library library,
FT_Raster_Funcs* raster_funcs )
{
FT_Glyph_Format glyph_format = raster_funcs->glyph_format;
FT_Glyph_Format glyph_format;
FT_Raster_Funcs* funcs;
FT_Raster raster;
FT_Error error;
FT_Int n, index;
if ( !library )
return FT_Err_Invalid_Library_Handle;
if ( !raster_funcs )
return FT_Err_Invalid_Argument;
glyph_format = raster_funcs->glyph_format;
if ( glyph_format == ft_glyph_format_none )
return FT_Err_Invalid_Argument;
@ -551,13 +570,21 @@
FT_Library library,
FT_Raster_Funcs* raster_funcs )
{
FT_Glyph_Format glyph_format = raster_funcs->glyph_format;
FT_Glyph_Format glyph_format;
FT_Error error;
FT_Int n;
if ( !library )
return FT_Err_Invalid_Library_Handle;
error = FT_Err_Invalid_Argument;
if ( !raster_funcs )
goto Exit;
glyph_format = raster_funcs->glyph_format;
if ( glyph_format == ft_glyph_format_none )
goto Exit;
@ -611,8 +638,11 @@
FT_Raster raster;
if ( !library )
return FT_Err_Invalid_Library_Handle;
raster = FT_Get_Raster( library, format, &funcs );
if ( raster && funcs.raster_set_mode )
if ( raster && args && funcs.raster_set_mode )
return funcs.raster_set_mode( raster, mode, args );
else
return FT_Err_Invalid_Argument;
@ -645,7 +675,8 @@
FT_UInt hook_index,
FT_DebugHook_Func debug_hook )
{
if ( hook_index <
if ( library && debug_hook &&
hook_index <
( sizeof ( library->debug_hooks ) / sizeof ( void* ) ) )
library->debug_hooks[hook_index] = debug_hook;
}
@ -673,10 +704,13 @@
FT_EXPORT_FUNC( FT_Error ) FT_New_Library( FT_Memory memory,
FT_Library* alibrary )
{
FT_Library library = 0;
FT_Error error;
FT_Library library = 0;
FT_Error error;
if ( !memory )
return FT_Err_Invalid_Argument;
/* first of all, allocate the library object */
if ( ALLOC( library, sizeof ( *library ) ) )
return error;
@ -804,9 +838,12 @@
FT_Memory memory;
if ( !library || !driver_interface )
if ( !library )
return FT_Err_Invalid_Library_Handle;
if ( !driver_interface )
return FT_Err_Invalid_Argument;
memory = library->memory;
error = FT_Err_Ok;
@ -1041,6 +1078,11 @@
FT_Open_Args args;
/* test for valid `library' and `aface' delayed to FT_Open_Face() */
if ( !pathname )
return FT_Err_Invalid_Argument;
args.flags = ft_open_pathname;
args.pathname = (char*)pathname;
@ -1097,6 +1139,11 @@
FT_Open_Args args;
/* test for valid `library' and `face' delayed to FT_Open_Face() */
if ( !file_base )
return FT_Err_Invalid_Argument;
args.flags = ft_open_memory;
args.memory_base = file_base;
args.memory_size = file_size;
@ -1158,10 +1205,13 @@
FT_ListNode node = 0;
*aface = 0;
/* test for valid `library' and `args' delayed to */
/* ft_new_input_stream() */
if ( !library )
return FT_Err_Invalid_Handle;
if ( !aface )
return FT_Err_Invalid_Argument;
*aface = 0;
/* create input stream */
error = ft_new_input_stream( library, args, &stream );
@ -1328,6 +1378,11 @@
FT_Open_Args open;
/* test for valid `face' delayed to FT_Attach_Stream() */
if ( !filepathname )
return FT_Err_Invalid_Argument;
open.flags = ft_open_pathname;
open.pathname = (char*)filepathname;
@ -1371,11 +1426,16 @@
FTDriver_getInterface get_interface;
if ( !face || !face->driver )
return FT_Err_Invalid_Handle;
/* test for valid `parameters' delayed to ft_new_input_stream() */
if ( !face )
return FT_Err_Invalid_Face_Handle;
driver = face->driver;
error = ft_new_input_stream( driver->library, parameters, &stream );
if ( !driver )
return FT_Err_Invalid_Driver_Handle;
error = ft_new_input_stream( driver->library, parameters, &stream );
if ( error )
goto Exit;
@ -1427,10 +1487,13 @@
FT_ListNode node;
if ( !face || !face->driver )
if ( !face )
return FT_Err_Invalid_Face_Handle;
driver = face->driver;
driver = face->driver;
if ( !driver )
return FT_Err_Invalid_Driver_Handle;
interface = &driver->interface;
memory = driver->memory;
@ -1482,11 +1545,18 @@
FT_ListNode node = 0;
if ( !face || !face->driver )
if ( !face )
return FT_Err_Invalid_Face_Handle;
*asize = 0;
driver = face->driver;
if ( !asize )
return FT_Err_Invalid_Argument;
*asize = 0;
driver = face->driver;
if ( !driver )
return FT_Err_Invalid_Driver_Handle;
interface = &driver->interface;
memory = face->memory;
@ -1544,17 +1614,20 @@
FT_ListNode node;
if ( !size || !size->face )
if ( !size )
return FT_Err_Invalid_Size_Handle;
driver = size->face->driver;
face = size->face;
if ( !face )
return FT_Err_Invalid_Face_Handle;
driver = face->driver;
if ( !driver )
return FT_Err_Invalid_Driver_Handle;
memory = driver->memory;
error = FT_Err_Ok;
face = size->face;
node = FT_List_Find( &face->sizes_list, size );
if ( node )
{
@ -1621,13 +1694,22 @@
FT_Driver driver;
FT_Memory memory;
FT_DriverInterface* interface;
FT_Size_Metrics* metrics = &face->size->metrics;
FT_Size_Metrics* metrics;
FT_Long dim_x, dim_y;
if ( !face || !face->size || !face->driver )
if ( !face )
return FT_Err_Invalid_Face_Handle;
if ( !face->size )
return FT_Err_Invalid_Size_Handle;
driver = face->driver;
if ( !driver )
return FT_Err_Invalid_Driver_Handle;
metrics = &face->size->metrics;
if ( !char_width )
char_width = char_height;
else if ( !char_height )
@ -1705,10 +1787,16 @@
FT_Size_Metrics* metrics = &face->size->metrics;
if ( !face || !face->size || !face->driver )
if ( !face )
return FT_Err_Invalid_Face_Handle;
driver = face->driver;
if ( !face->size )
return FT_Err_Invalid_Size_Handle;
driver = face->driver;
if ( !driver )
return FT_Err_Invalid_Driver_Handle;
interface = &driver->interface;
memory = driver->memory;
@ -1770,12 +1858,18 @@
FT_GlyphSlot slot;
*aslot = 0;
if ( !face || !face->driver )
if ( !face )
return FT_Err_Invalid_Face_Handle;
driver = face->driver;
if ( !aslot )
return FT_Err_Invalid_Argument;
*aslot = 0;
driver = face->driver;
if ( !driver )
return FT_Err_Invalid_Driver_Handle;
interface = &driver->interface;
memory = driver->memory;
@ -1880,9 +1974,15 @@
FT_Driver driver;
if ( !face || !face->size || !face->glyph )
if ( !face )
return FT_Err_Invalid_Face_Handle;
if ( !face->size )
return FT_Err_Invalid_Size_Handle;
if ( !face->glyph )
return FT_Err_Invalid_Slot_Handle;
if ( glyph_index >= face->num_glyphs )
return FT_Err_Invalid_Argument;
@ -1935,9 +2035,18 @@
FT_UInt glyph_index;
if ( !face || !face->size || !face->glyph || !face->charmap )
if ( !face )
return FT_Err_Invalid_Face_Handle;
if ( !face->size )
return FT_Err_Invalid_Size_Handle;
if ( !face->glyph )
return FT_Err_Invalid_Slot_Handle;
if ( !face->charmap )
return FT_Err_Invalid_CharMap_Handle;
driver = face->driver;
glyph_index = FT_Get_Char_Index( face, char_code );
@ -1986,16 +2095,16 @@
FT_UInt right_glyph,
FT_Vector* kerning )
{
FT_Error error;
FT_Error error = FT_Err_Ok;
FT_Driver driver;
FT_Memory memory;
if ( !face )
{
error = FT_Err_Invalid_Face_Handle;
goto Exit;
}
return FT_Err_Invalid_Face_Handle;
if ( !kerning )
return FT_Err_Invalid_Argument;
driver = face->driver;
memory = driver->memory;
@ -2011,10 +2120,8 @@
{
kerning->x = 0;
kerning->y = 0;
error = FT_Err_Ok;
}
Exit:
return error;
}
@ -2043,10 +2150,19 @@
FT_EXPORT_FUNC( FT_Error ) FT_Select_Charmap( FT_Face face,
FT_Encoding encoding )
{
FT_CharMap* cur = face->charmaps;
FT_CharMap* limit = cur + face->num_charmaps;
FT_CharMap* cur;
FT_CharMap* limit;
if ( !face )
return FT_Err_Invalid_Face_Handle;
cur = face->charmaps;
if ( !cur )
return FT_Err_Invalid_CharMap_Handle;
limit = cur + face->num_charmaps;
for ( ; cur < limit; cur++ )
{
if ( cur[0]->encoding == encoding )
@ -2083,10 +2199,19 @@
FT_EXPORT_FUNC( FT_Error ) FT_Set_Charmap( FT_Face face,
FT_CharMap charmap )
{
FT_CharMap* cur = face->charmaps;
FT_CharMap* limit = cur + face->num_charmaps;
FT_CharMap* cur;
FT_CharMap* limit;
if ( !face )
return FT_Err_Invalid_Face_Handle;
cur = face->charmaps;
if ( !cur )
return FT_Err_Invalid_CharMap_Handle;
limit = cur + face->num_charmaps;
for ( ; cur < limit; cur++ )
{
if ( cur[0] == charmap )
@ -2115,8 +2240,8 @@
/* <Return> */
/* The glyph index. 0 means `undefined character code'. */
/* */
FT_EXPORT_FUNC( FT_UInt ) FT_Get_Char_Index( FT_Face face,
FT_ULong charcode )
FT_EXPORT_FUNC( FT_UInt ) FT_Get_Char_Index( FT_Face face,
FT_ULong charcode )
{
FT_UInt result;
FT_Driver driver;
@ -2197,6 +2322,8 @@
/* */
FT_EXPORT_FUNC( FT_Error ) FT_Done_FreeType( FT_Library library )
{
/* test for valid `library' delayed to FT_Done_Library() */
/* Discard the library object */
FT_Done_Library( library );

View File

@ -77,10 +77,15 @@
FT_UInt first; /* index of first point in contour */
char tag; /* current point's state */
FT_Int shift = interface->shift;
FT_Pos delta = interface->delta;
FT_Int shift;
FT_Pos delta;
if ( !outline || !interface )
return FT_Err_Invalid_Argument;
shift = interface->shift;
delta = interface->delta;
first = 0;
for ( n = 0; n < outline->n_contours; n++ )
@ -718,6 +723,12 @@
FT_Raster_Params params;
if ( !library )
return FT_Err_Invalid_Library_Handle;
if ( !outline || !bitmap )
return FT_Err_Invalid_Argument;
error = FT_Err_Invalid_Glyph_Format;
raster = FT_Get_Raster( library, ft_glyph_format_outline, &funcs );
if ( !raster )
@ -770,15 +781,21 @@
/* converter is called, which means that the value you give to it is */
/* actually ignored. */
/* */
FT_EXPORT_FUNC( FT_Error ) FT_Outline_Render( FT_Library library,
FT_Outline* outline,
FT_Raster_Params* params )
FT_EXPORT_FUNC( FT_Error ) FT_Outline_Render( FT_Library library,
FT_Outline* outline,
FT_Raster_Params* params )
{
FT_Error error;
FT_Raster raster;
FT_Raster_Funcs funcs;
if ( !library )
return FT_Err_Invalid_Library_Handle;
if ( !outline || !params )
return FT_Err_Invalid_Argument;
error = FT_Err_Invalid_Glyph_Format;
raster = FT_Get_Raster( library, ft_glyph_format_outline, &funcs );
if ( !raster )
@ -925,12 +942,18 @@
/* <MT-Note> */
/* Yes. */
/* */
/* <Note> */
/* The result is undefined if either `vector' or `matrix' is invalid. */
/* */
FT_EXPORT_FUNC( void ) FT_Vector_Transform( FT_Vector* vector,
FT_Matrix* matrix )
{
FT_Pos xz, yz;
if ( !vector || !matrix )
return;
xz = FT_MulFix( vector->x, matrix->xx ) +
FT_MulFix( vector->y, matrix->xy );

View File

@ -2059,12 +2059,12 @@
}
static void
Vertical_Sweep_Drop( RAS_ARGS Short y,
FT_F26Dot6 x1,
FT_F26Dot6 x2,
PProfile left,
PProfile right )
static
void Vertical_Sweep_Drop( RAS_ARGS Short y,
FT_F26Dot6 x1,
FT_F26Dot6 x2,
PProfile left,
PProfile right )
{
Long e1, e2;
Short c1, f1;

View File

@ -112,14 +112,17 @@
static
void t2_done_cff_index( CFF_Index* index )
{
FT_Stream stream = index->stream;
FT_Memory memory = stream->memory;
if ( index->stream )
{
FT_Stream stream = index->stream;
FT_Memory memory = stream->memory;
if (index->bytes)
RELEASE_Frame( index->bytes );
if (index->bytes)
RELEASE_Frame( index->bytes );
FREE( index->offsets );
MEM_Set( index, 0, sizeof(*index) );
FREE( index->offsets );
MEM_Set( index, 0, sizeof(*index) );
}
}