2018-06-03 22:00:42 +02:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* ftmemory.h
|
|
|
|
*
|
|
|
|
* The FreeType memory management macros (specification).
|
|
|
|
*
|
2021-01-17 07:18:48 +01:00
|
|
|
* Copyright (C) 1996-2021 by
|
2018-06-03 22:00:42 +02:00
|
|
|
* David Turner, Robert Wilhelm, and Werner Lemberg
|
|
|
|
*
|
|
|
|
* This file is part of the FreeType project, and may only be used,
|
|
|
|
* modified, and distributed under the terms of the FreeType project
|
|
|
|
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
|
|
|
* this file you indicate that you have read the license and
|
|
|
|
* understand and accept it fully.
|
|
|
|
*
|
|
|
|
*/
|
2000-05-16 21:51:49 +02:00
|
|
|
|
2000-07-18 08:50:03 +02:00
|
|
|
|
2016-01-12 21:37:13 +01:00
|
|
|
#ifndef FTMEMORY_H_
|
|
|
|
#define FTMEMORY_H_
|
2000-05-16 21:51:49 +02:00
|
|
|
|
2000-12-09 01:45:38 +01:00
|
|
|
|
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_CONFIG_CONFIG_H
|
2020-06-08 13:31:55 +02:00
|
|
|
#include <freetype/fttypes.h>
|
2000-12-09 01:45:38 +01:00
|
|
|
|
2020-07-02 11:09:57 +02:00
|
|
|
#include "compiler-macros.h"
|
2000-08-01 15:17:04 +02:00
|
|
|
|
2000-12-01 00:12:33 +01:00
|
|
|
FT_BEGIN_HEADER
|
2000-08-01 15:17:04 +02:00
|
|
|
|
2000-12-09 01:45:38 +01:00
|
|
|
|
2018-06-03 22:00:42 +02:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
2018-06-17 21:08:36 +02:00
|
|
|
* @macro:
|
2018-06-03 22:00:42 +02:00
|
|
|
* FT_SET_ERROR
|
|
|
|
*
|
2018-06-17 21:08:36 +02:00
|
|
|
* @description:
|
2018-08-24 18:52:30 +02:00
|
|
|
* This macro is used to set an implicit 'error' variable to a given
|
2018-06-03 22:00:42 +02:00
|
|
|
* expression's value (usually a function call), and convert it to a
|
|
|
|
* boolean which is set whenever the value is != 0.
|
|
|
|
*/
|
2000-05-16 21:51:49 +02:00
|
|
|
#undef FT_SET_ERROR
|
|
|
|
#define FT_SET_ERROR( expression ) \
|
2000-07-18 08:50:03 +02:00
|
|
|
( ( error = (expression) ) != 0 )
|
2000-05-16 21:51:49 +02:00
|
|
|
|
|
|
|
|
2005-03-03 14:58:13 +01:00
|
|
|
|
2000-05-16 21:51:49 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/**** ****/
|
|
|
|
/**** ****/
|
|
|
|
/**** M E M O R Y ****/
|
|
|
|
/**** ****/
|
|
|
|
/**** ****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2006-01-27 15:16:16 +01:00
|
|
|
|
2019-11-23 10:28:37 +01:00
|
|
|
/* The calculation `NULL + n' is undefined in C. Even if the resulting */
|
|
|
|
/* pointer doesn't get dereferenced, this causes warnings with */
|
|
|
|
/* sanitizers. */
|
|
|
|
/* */
|
|
|
|
/* We thus provide a macro that should be used if `base' can be NULL. */
|
|
|
|
#define FT_OFFSET( base, count ) ( (base) ? (base) + (count) : NULL )
|
|
|
|
|
|
|
|
|
2006-05-03 22:39:55 +02:00
|
|
|
/*
|
2018-06-03 22:00:42 +02:00
|
|
|
* C++ refuses to handle statements like p = (void*)anything, with `p' a
|
2018-08-24 18:52:30 +02:00
|
|
|
* typed pointer. Since we don't have a `typeof' operator in standard C++,
|
|
|
|
* we have to use a template to emulate it.
|
2006-05-03 22:39:55 +02:00
|
|
|
*/
|
|
|
|
|
2006-05-03 11:40:33 +02:00
|
|
|
#ifdef __cplusplus
|
2010-07-12 20:57:54 +02:00
|
|
|
|
2016-05-21 10:58:40 +02:00
|
|
|
extern "C++"
|
|
|
|
{
|
2010-07-12 20:57:54 +02:00
|
|
|
template <typename T> inline T*
|
|
|
|
cplusplus_typeof( T*,
|
|
|
|
void *v )
|
|
|
|
{
|
|
|
|
return static_cast <T*> ( v );
|
|
|
|
}
|
2016-05-21 10:58:40 +02:00
|
|
|
}
|
2010-07-12 20:57:54 +02:00
|
|
|
|
|
|
|
#define FT_ASSIGNP( p, val ) (p) = cplusplus_typeof( (p), (val) )
|
|
|
|
|
2006-05-03 11:40:33 +02:00
|
|
|
#else
|
2010-07-12 20:57:54 +02:00
|
|
|
|
2006-05-03 22:39:55 +02:00
|
|
|
#define FT_ASSIGNP( p, val ) (p) = (val)
|
2010-07-12 20:57:54 +02:00
|
|
|
|
2006-05-03 11:40:33 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
* include/freetype/fterrdef.h, include/freetype/config/ftconfig.h,
include/freetype/internal/ftmemory.h, src/base/ftdbgmem.c,
src/base/ftutil.c: udpating the memory management functions and
macros to safely deal with array size buffer overflows, this
corresponds to attemps to allocate arrays that are too large. For
an example, consider the following code:
count = read_uint32_from_file();
array = malloc( sizeof(Item) * count );
for ( nn = 0; nn < count; nn++ )
array[nn] = read_item_from_file();
if 'count' is larger than FT_UINT_MAX/sizeof(Item), the multiplication
will overflow and the array allocated will be smaller than the data
read from the file. In this case, the heap will be trashed, and this
can be used as a denial-of-service, or make the engine crash later.
the FT_ARRAY_NEW and FT_ARRAY_RENEW macro now check that the new
count is no more than FT_INT_MAX/item_size, otherwise, a new error,
named 'FT_Err_Array_Too_Large' will be returned.
note that the memory debugger now works again when FT_DEBUG_MEMORY
is defined, and FT_STRICT_ALIASING has disappeared, the corresponding
code being now the default.
2006-05-02 08:34:27 +02:00
|
|
|
#ifdef FT_DEBUG_MEMORY
|
|
|
|
|
2006-05-03 00:22:16 +02:00
|
|
|
FT_BASE( const char* ) _ft_debug_file;
|
|
|
|
FT_BASE( long ) _ft_debug_lineno;
|
* include/freetype/fterrdef.h, include/freetype/config/ftconfig.h,
include/freetype/internal/ftmemory.h, src/base/ftdbgmem.c,
src/base/ftutil.c: udpating the memory management functions and
macros to safely deal with array size buffer overflows, this
corresponds to attemps to allocate arrays that are too large. For
an example, consider the following code:
count = read_uint32_from_file();
array = malloc( sizeof(Item) * count );
for ( nn = 0; nn < count; nn++ )
array[nn] = read_item_from_file();
if 'count' is larger than FT_UINT_MAX/sizeof(Item), the multiplication
will overflow and the array allocated will be smaller than the data
read from the file. In this case, the heap will be trashed, and this
can be used as a denial-of-service, or make the engine crash later.
the FT_ARRAY_NEW and FT_ARRAY_RENEW macro now check that the new
count is no more than FT_INT_MAX/item_size, otherwise, a new error,
named 'FT_Err_Array_Too_Large' will be returned.
note that the memory debugger now works again when FT_DEBUG_MEMORY
is defined, and FT_STRICT_ALIASING has disappeared, the corresponding
code being now the default.
2006-05-02 08:34:27 +02:00
|
|
|
|
2006-05-03 22:39:55 +02:00
|
|
|
#define FT_DEBUG_INNER( exp ) ( _ft_debug_file = __FILE__, \
|
|
|
|
_ft_debug_lineno = __LINE__, \
|
|
|
|
(exp) )
|
2006-05-03 11:40:33 +02:00
|
|
|
|
2006-05-03 22:39:55 +02:00
|
|
|
#define FT_ASSIGNP_INNER( p, exp ) ( _ft_debug_file = __FILE__, \
|
|
|
|
_ft_debug_lineno = __LINE__, \
|
|
|
|
FT_ASSIGNP( p, exp ) )
|
* include/freetype/fterrdef.h, include/freetype/config/ftconfig.h,
include/freetype/internal/ftmemory.h, src/base/ftdbgmem.c,
src/base/ftutil.c: udpating the memory management functions and
macros to safely deal with array size buffer overflows, this
corresponds to attemps to allocate arrays that are too large. For
an example, consider the following code:
count = read_uint32_from_file();
array = malloc( sizeof(Item) * count );
for ( nn = 0; nn < count; nn++ )
array[nn] = read_item_from_file();
if 'count' is larger than FT_UINT_MAX/sizeof(Item), the multiplication
will overflow and the array allocated will be smaller than the data
read from the file. In this case, the heap will be trashed, and this
can be used as a denial-of-service, or make the engine crash later.
the FT_ARRAY_NEW and FT_ARRAY_RENEW macro now check that the new
count is no more than FT_INT_MAX/item_size, otherwise, a new error,
named 'FT_Err_Array_Too_Large' will be returned.
note that the memory debugger now works again when FT_DEBUG_MEMORY
is defined, and FT_STRICT_ALIASING has disappeared, the corresponding
code being now the default.
2006-05-02 08:34:27 +02:00
|
|
|
|
|
|
|
#else /* !FT_DEBUG_MEMORY */
|
2006-01-27 13:11:22 +01:00
|
|
|
|
2006-05-03 22:39:55 +02:00
|
|
|
#define FT_DEBUG_INNER( exp ) (exp)
|
|
|
|
#define FT_ASSIGNP_INNER( p, exp ) FT_ASSIGNP( p, exp )
|
2006-05-03 00:22:16 +02:00
|
|
|
|
|
|
|
#endif /* !FT_DEBUG_MEMORY */
|
* include/freetype/fterrdef.h, include/freetype/config/ftconfig.h,
include/freetype/internal/ftmemory.h, src/base/ftdbgmem.c,
src/base/ftutil.c: udpating the memory management functions and
macros to safely deal with array size buffer overflows, this
corresponds to attemps to allocate arrays that are too large. For
an example, consider the following code:
count = read_uint32_from_file();
array = malloc( sizeof(Item) * count );
for ( nn = 0; nn < count; nn++ )
array[nn] = read_item_from_file();
if 'count' is larger than FT_UINT_MAX/sizeof(Item), the multiplication
will overflow and the array allocated will be smaller than the data
read from the file. In this case, the heap will be trashed, and this
can be used as a denial-of-service, or make the engine crash later.
the FT_ARRAY_NEW and FT_ARRAY_RENEW macro now check that the new
count is no more than FT_INT_MAX/item_size, otherwise, a new error,
named 'FT_Err_Array_Too_Large' will be returned.
note that the memory debugger now works again when FT_DEBUG_MEMORY
is defined, and FT_STRICT_ALIASING has disappeared, the corresponding
code being now the default.
2006-05-02 08:34:27 +02:00
|
|
|
|
2006-01-27 15:16:16 +01:00
|
|
|
|
|
|
|
/*
|
2018-08-24 18:52:30 +02:00
|
|
|
* The allocation functions return a pointer, and the error code is written
|
|
|
|
* to through the `p_error' parameter.
|
2006-01-27 15:16:16 +01:00
|
|
|
*/
|
2006-01-27 13:11:22 +01:00
|
|
|
|
2016-09-06 12:29:18 +02:00
|
|
|
/* The `q' variants of the functions below (`q' for `quick') don't fill */
|
|
|
|
/* the allocated or reallocated memory with zero bytes. */
|
|
|
|
|
2006-01-27 13:11:22 +01:00
|
|
|
FT_BASE( FT_Pointer )
|
* builds/amiga/src/base/ftsystem.c, devel/ftoption.h
include/freetype/ftcache.h, include/freetype/ftoutln.h,
include/freetype/cache/ftccache.h, include/freetype/cache/ftccmap.h,
include/freetype/config/ftoption.h, include/freetype/internal/ftcalc.h,
include/freetype/internal/ftdriver.h,
include/freetype/internal/ftmemory.h,
include/freetype/internal/ftobjs.h, include/freetype/internal/ftrfork.h,
include/freetype/internal/psaux.h, include/freetype/internal/sfnt.h,
include/freetype/internal/t1types.h, include/freetype/internal/tttypes.h,
src/base/ftcalc.c, src/base/ftdbgmem.c, src/base/ftobjs.c,
src/base/ftsystem.c, src/base/ftutil.c, src/bdf/bdfdrivr.c,
src/cache/ftccache.c, src/cache/ftccback.h, src/cache/ftccmap.c,
src/cache/ftcmanag.c, src/cff/cffdrivr.c, src/cid/cidriver.c,
src/pcf/pcfdrivr.c, src/pfr/pfrdrivr.c, src/psaux/psauxmod.c,
src/sfnt/sfdriver.c, src/truetype/ttdriver.c, src/type1/t1driver.c,
src/type1/t1objs.c, src/type42/t42drivr.c, src/winfonts/winfnt.c:
massive changes to the internals to respect the internal object layouts
and exported functions of FreeType 2.1.7. Note that the cache sub-system
cannot be fully retrofitted, unfortunately.
2006-02-16 23:45:31 +01:00
|
|
|
ft_mem_alloc( FT_Memory memory,
|
|
|
|
FT_Long size,
|
|
|
|
FT_Error *p_error );
|
2006-01-27 13:11:22 +01:00
|
|
|
|
|
|
|
FT_BASE( FT_Pointer )
|
* builds/amiga/src/base/ftsystem.c, devel/ftoption.h
include/freetype/ftcache.h, include/freetype/ftoutln.h,
include/freetype/cache/ftccache.h, include/freetype/cache/ftccmap.h,
include/freetype/config/ftoption.h, include/freetype/internal/ftcalc.h,
include/freetype/internal/ftdriver.h,
include/freetype/internal/ftmemory.h,
include/freetype/internal/ftobjs.h, include/freetype/internal/ftrfork.h,
include/freetype/internal/psaux.h, include/freetype/internal/sfnt.h,
include/freetype/internal/t1types.h, include/freetype/internal/tttypes.h,
src/base/ftcalc.c, src/base/ftdbgmem.c, src/base/ftobjs.c,
src/base/ftsystem.c, src/base/ftutil.c, src/bdf/bdfdrivr.c,
src/cache/ftccache.c, src/cache/ftccback.h, src/cache/ftccmap.c,
src/cache/ftcmanag.c, src/cff/cffdrivr.c, src/cid/cidriver.c,
src/pcf/pcfdrivr.c, src/pfr/pfrdrivr.c, src/psaux/psauxmod.c,
src/sfnt/sfdriver.c, src/truetype/ttdriver.c, src/type1/t1driver.c,
src/type1/t1objs.c, src/type42/t42drivr.c, src/winfonts/winfnt.c:
massive changes to the internals to respect the internal object layouts
and exported functions of FreeType 2.1.7. Note that the cache sub-system
cannot be fully retrofitted, unfortunately.
2006-02-16 23:45:31 +01:00
|
|
|
ft_mem_qalloc( FT_Memory memory,
|
|
|
|
FT_Long size,
|
|
|
|
FT_Error *p_error );
|
2006-01-27 13:11:22 +01:00
|
|
|
|
|
|
|
FT_BASE( FT_Pointer )
|
* builds/amiga/src/base/ftsystem.c, devel/ftoption.h
include/freetype/ftcache.h, include/freetype/ftoutln.h,
include/freetype/cache/ftccache.h, include/freetype/cache/ftccmap.h,
include/freetype/config/ftoption.h, include/freetype/internal/ftcalc.h,
include/freetype/internal/ftdriver.h,
include/freetype/internal/ftmemory.h,
include/freetype/internal/ftobjs.h, include/freetype/internal/ftrfork.h,
include/freetype/internal/psaux.h, include/freetype/internal/sfnt.h,
include/freetype/internal/t1types.h, include/freetype/internal/tttypes.h,
src/base/ftcalc.c, src/base/ftdbgmem.c, src/base/ftobjs.c,
src/base/ftsystem.c, src/base/ftutil.c, src/bdf/bdfdrivr.c,
src/cache/ftccache.c, src/cache/ftccback.h, src/cache/ftccmap.c,
src/cache/ftcmanag.c, src/cff/cffdrivr.c, src/cid/cidriver.c,
src/pcf/pcfdrivr.c, src/pfr/pfrdrivr.c, src/psaux/psauxmod.c,
src/sfnt/sfdriver.c, src/truetype/ttdriver.c, src/type1/t1driver.c,
src/type1/t1objs.c, src/type42/t42drivr.c, src/winfonts/winfnt.c:
massive changes to the internals to respect the internal object layouts
and exported functions of FreeType 2.1.7. Note that the cache sub-system
cannot be fully retrofitted, unfortunately.
2006-02-16 23:45:31 +01:00
|
|
|
ft_mem_realloc( FT_Memory memory,
|
* include/freetype/fterrdef.h, include/freetype/config/ftconfig.h,
include/freetype/internal/ftmemory.h, src/base/ftdbgmem.c,
src/base/ftutil.c: udpating the memory management functions and
macros to safely deal with array size buffer overflows, this
corresponds to attemps to allocate arrays that are too large. For
an example, consider the following code:
count = read_uint32_from_file();
array = malloc( sizeof(Item) * count );
for ( nn = 0; nn < count; nn++ )
array[nn] = read_item_from_file();
if 'count' is larger than FT_UINT_MAX/sizeof(Item), the multiplication
will overflow and the array allocated will be smaller than the data
read from the file. In this case, the heap will be trashed, and this
can be used as a denial-of-service, or make the engine crash later.
the FT_ARRAY_NEW and FT_ARRAY_RENEW macro now check that the new
count is no more than FT_INT_MAX/item_size, otherwise, a new error,
named 'FT_Err_Array_Too_Large' will be returned.
note that the memory debugger now works again when FT_DEBUG_MEMORY
is defined, and FT_STRICT_ALIASING has disappeared, the corresponding
code being now the default.
2006-05-02 08:34:27 +02:00
|
|
|
FT_Long item_size,
|
|
|
|
FT_Long cur_count,
|
|
|
|
FT_Long new_count,
|
* builds/amiga/src/base/ftsystem.c, devel/ftoption.h
include/freetype/ftcache.h, include/freetype/ftoutln.h,
include/freetype/cache/ftccache.h, include/freetype/cache/ftccmap.h,
include/freetype/config/ftoption.h, include/freetype/internal/ftcalc.h,
include/freetype/internal/ftdriver.h,
include/freetype/internal/ftmemory.h,
include/freetype/internal/ftobjs.h, include/freetype/internal/ftrfork.h,
include/freetype/internal/psaux.h, include/freetype/internal/sfnt.h,
include/freetype/internal/t1types.h, include/freetype/internal/tttypes.h,
src/base/ftcalc.c, src/base/ftdbgmem.c, src/base/ftobjs.c,
src/base/ftsystem.c, src/base/ftutil.c, src/bdf/bdfdrivr.c,
src/cache/ftccache.c, src/cache/ftccback.h, src/cache/ftccmap.c,
src/cache/ftcmanag.c, src/cff/cffdrivr.c, src/cid/cidriver.c,
src/pcf/pcfdrivr.c, src/pfr/pfrdrivr.c, src/psaux/psauxmod.c,
src/sfnt/sfdriver.c, src/truetype/ttdriver.c, src/type1/t1driver.c,
src/type1/t1objs.c, src/type42/t42drivr.c, src/winfonts/winfnt.c:
massive changes to the internals to respect the internal object layouts
and exported functions of FreeType 2.1.7. Note that the cache sub-system
cannot be fully retrofitted, unfortunately.
2006-02-16 23:45:31 +01:00
|
|
|
void* block,
|
|
|
|
FT_Error *p_error );
|
2006-01-27 13:11:22 +01:00
|
|
|
|
|
|
|
FT_BASE( FT_Pointer )
|
* builds/amiga/src/base/ftsystem.c, devel/ftoption.h
include/freetype/ftcache.h, include/freetype/ftoutln.h,
include/freetype/cache/ftccache.h, include/freetype/cache/ftccmap.h,
include/freetype/config/ftoption.h, include/freetype/internal/ftcalc.h,
include/freetype/internal/ftdriver.h,
include/freetype/internal/ftmemory.h,
include/freetype/internal/ftobjs.h, include/freetype/internal/ftrfork.h,
include/freetype/internal/psaux.h, include/freetype/internal/sfnt.h,
include/freetype/internal/t1types.h, include/freetype/internal/tttypes.h,
src/base/ftcalc.c, src/base/ftdbgmem.c, src/base/ftobjs.c,
src/base/ftsystem.c, src/base/ftutil.c, src/bdf/bdfdrivr.c,
src/cache/ftccache.c, src/cache/ftccback.h, src/cache/ftccmap.c,
src/cache/ftcmanag.c, src/cff/cffdrivr.c, src/cid/cidriver.c,
src/pcf/pcfdrivr.c, src/pfr/pfrdrivr.c, src/psaux/psauxmod.c,
src/sfnt/sfdriver.c, src/truetype/ttdriver.c, src/type1/t1driver.c,
src/type1/t1objs.c, src/type42/t42drivr.c, src/winfonts/winfnt.c:
massive changes to the internals to respect the internal object layouts
and exported functions of FreeType 2.1.7. Note that the cache sub-system
cannot be fully retrofitted, unfortunately.
2006-02-16 23:45:31 +01:00
|
|
|
ft_mem_qrealloc( FT_Memory memory,
|
* include/freetype/fterrdef.h, include/freetype/config/ftconfig.h,
include/freetype/internal/ftmemory.h, src/base/ftdbgmem.c,
src/base/ftutil.c: udpating the memory management functions and
macros to safely deal with array size buffer overflows, this
corresponds to attemps to allocate arrays that are too large. For
an example, consider the following code:
count = read_uint32_from_file();
array = malloc( sizeof(Item) * count );
for ( nn = 0; nn < count; nn++ )
array[nn] = read_item_from_file();
if 'count' is larger than FT_UINT_MAX/sizeof(Item), the multiplication
will overflow and the array allocated will be smaller than the data
read from the file. In this case, the heap will be trashed, and this
can be used as a denial-of-service, or make the engine crash later.
the FT_ARRAY_NEW and FT_ARRAY_RENEW macro now check that the new
count is no more than FT_INT_MAX/item_size, otherwise, a new error,
named 'FT_Err_Array_Too_Large' will be returned.
note that the memory debugger now works again when FT_DEBUG_MEMORY
is defined, and FT_STRICT_ALIASING has disappeared, the corresponding
code being now the default.
2006-05-02 08:34:27 +02:00
|
|
|
FT_Long item_size,
|
|
|
|
FT_Long cur_count,
|
|
|
|
FT_Long new_count,
|
* builds/amiga/src/base/ftsystem.c, devel/ftoption.h
include/freetype/ftcache.h, include/freetype/ftoutln.h,
include/freetype/cache/ftccache.h, include/freetype/cache/ftccmap.h,
include/freetype/config/ftoption.h, include/freetype/internal/ftcalc.h,
include/freetype/internal/ftdriver.h,
include/freetype/internal/ftmemory.h,
include/freetype/internal/ftobjs.h, include/freetype/internal/ftrfork.h,
include/freetype/internal/psaux.h, include/freetype/internal/sfnt.h,
include/freetype/internal/t1types.h, include/freetype/internal/tttypes.h,
src/base/ftcalc.c, src/base/ftdbgmem.c, src/base/ftobjs.c,
src/base/ftsystem.c, src/base/ftutil.c, src/bdf/bdfdrivr.c,
src/cache/ftccache.c, src/cache/ftccback.h, src/cache/ftccmap.c,
src/cache/ftcmanag.c, src/cff/cffdrivr.c, src/cid/cidriver.c,
src/pcf/pcfdrivr.c, src/pfr/pfrdrivr.c, src/psaux/psauxmod.c,
src/sfnt/sfdriver.c, src/truetype/ttdriver.c, src/type1/t1driver.c,
src/type1/t1objs.c, src/type42/t42drivr.c, src/winfonts/winfnt.c:
massive changes to the internals to respect the internal object layouts
and exported functions of FreeType 2.1.7. Note that the cache sub-system
cannot be fully retrofitted, unfortunately.
2006-02-16 23:45:31 +01:00
|
|
|
void* block,
|
|
|
|
FT_Error *p_error );
|
2006-01-27 13:11:22 +01:00
|
|
|
|
|
|
|
FT_BASE( void )
|
* builds/amiga/src/base/ftsystem.c, devel/ftoption.h
include/freetype/ftcache.h, include/freetype/ftoutln.h,
include/freetype/cache/ftccache.h, include/freetype/cache/ftccmap.h,
include/freetype/config/ftoption.h, include/freetype/internal/ftcalc.h,
include/freetype/internal/ftdriver.h,
include/freetype/internal/ftmemory.h,
include/freetype/internal/ftobjs.h, include/freetype/internal/ftrfork.h,
include/freetype/internal/psaux.h, include/freetype/internal/sfnt.h,
include/freetype/internal/t1types.h, include/freetype/internal/tttypes.h,
src/base/ftcalc.c, src/base/ftdbgmem.c, src/base/ftobjs.c,
src/base/ftsystem.c, src/base/ftutil.c, src/bdf/bdfdrivr.c,
src/cache/ftccache.c, src/cache/ftccback.h, src/cache/ftccmap.c,
src/cache/ftcmanag.c, src/cff/cffdrivr.c, src/cid/cidriver.c,
src/pcf/pcfdrivr.c, src/pfr/pfrdrivr.c, src/psaux/psauxmod.c,
src/sfnt/sfdriver.c, src/truetype/ttdriver.c, src/type1/t1driver.c,
src/type1/t1objs.c, src/type42/t42drivr.c, src/winfonts/winfnt.c:
massive changes to the internals to respect the internal object layouts
and exported functions of FreeType 2.1.7. Note that the cache sub-system
cannot be fully retrofitted, unfortunately.
2006-02-16 23:45:31 +01:00
|
|
|
ft_mem_free( FT_Memory memory,
|
|
|
|
const void* P );
|
2006-01-27 13:11:22 +01:00
|
|
|
|
|
|
|
|
2016-09-06 12:29:18 +02:00
|
|
|
/* The `Q' variants of the macros below (`Q' for `quick') don't fill */
|
|
|
|
/* the allocated or reallocated memory with zero bytes. */
|
|
|
|
|
2013-06-05 13:43:20 +02:00
|
|
|
#define FT_MEM_ALLOC( ptr, size ) \
|
|
|
|
FT_ASSIGNP_INNER( ptr, ft_mem_alloc( memory, \
|
|
|
|
(FT_Long)(size), \
|
|
|
|
&error ) )
|
2006-01-27 13:11:22 +01:00
|
|
|
|
2019-10-06 21:12:42 +02:00
|
|
|
#define FT_MEM_FREE( ptr ) \
|
|
|
|
FT_BEGIN_STMNT \
|
|
|
|
FT_DEBUG_INNER( ft_mem_free( memory, (ptr) ) ); \
|
|
|
|
(ptr) = NULL; \
|
2006-05-03 00:22:16 +02:00
|
|
|
FT_END_STMNT
|
2006-01-27 15:16:16 +01:00
|
|
|
|
2006-05-03 00:22:16 +02:00
|
|
|
#define FT_MEM_NEW( ptr ) \
|
|
|
|
FT_MEM_ALLOC( ptr, sizeof ( *(ptr) ) )
|
2006-01-27 13:11:22 +01:00
|
|
|
|
2006-05-03 11:40:33 +02:00
|
|
|
#define FT_MEM_REALLOC( ptr, cursz, newsz ) \
|
2013-06-05 13:43:20 +02:00
|
|
|
FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, \
|
|
|
|
1, \
|
|
|
|
(FT_Long)(cursz), \
|
|
|
|
(FT_Long)(newsz), \
|
|
|
|
(ptr), \
|
|
|
|
&error ) )
|
|
|
|
|
|
|
|
#define FT_MEM_QALLOC( ptr, size ) \
|
|
|
|
FT_ASSIGNP_INNER( ptr, ft_mem_qalloc( memory, \
|
|
|
|
(FT_Long)(size), \
|
|
|
|
&error ) )
|
2006-01-27 15:16:16 +01:00
|
|
|
|
2006-05-03 00:22:16 +02:00
|
|
|
#define FT_MEM_QNEW( ptr ) \
|
|
|
|
FT_MEM_QALLOC( ptr, sizeof ( *(ptr) ) )
|
2006-01-27 15:16:16 +01:00
|
|
|
|
2013-06-05 13:43:20 +02:00
|
|
|
#define FT_MEM_QREALLOC( ptr, cursz, newsz ) \
|
|
|
|
FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, \
|
|
|
|
1, \
|
|
|
|
(FT_Long)(cursz), \
|
|
|
|
(FT_Long)(newsz), \
|
|
|
|
(ptr), \
|
|
|
|
&error ) )
|
|
|
|
|
|
|
|
#define FT_MEM_ALLOC_MULT( ptr, count, item_size ) \
|
|
|
|
FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, \
|
|
|
|
(FT_Long)(item_size), \
|
|
|
|
0, \
|
|
|
|
(FT_Long)(count), \
|
|
|
|
NULL, \
|
|
|
|
&error ) )
|
|
|
|
|
|
|
|
#define FT_MEM_REALLOC_MULT( ptr, oldcnt, newcnt, itmsz ) \
|
|
|
|
FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, \
|
|
|
|
(FT_Long)(itmsz), \
|
|
|
|
(FT_Long)(oldcnt), \
|
|
|
|
(FT_Long)(newcnt), \
|
|
|
|
(ptr), \
|
|
|
|
&error ) )
|
|
|
|
|
|
|
|
#define FT_MEM_QALLOC_MULT( ptr, count, item_size ) \
|
|
|
|
FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, \
|
|
|
|
(FT_Long)(item_size), \
|
|
|
|
0, \
|
|
|
|
(FT_Long)(count), \
|
|
|
|
NULL, \
|
|
|
|
&error ) )
|
|
|
|
|
2017-09-30 16:16:03 +02:00
|
|
|
#define FT_MEM_QREALLOC_MULT( ptr, oldcnt, newcnt, itmsz ) \
|
2013-06-05 13:43:20 +02:00
|
|
|
FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, \
|
|
|
|
(FT_Long)(itmsz), \
|
|
|
|
(FT_Long)(oldcnt), \
|
|
|
|
(FT_Long)(newcnt), \
|
|
|
|
(ptr), \
|
|
|
|
&error ) )
|
2006-01-27 13:11:22 +01:00
|
|
|
|
|
|
|
|
2006-05-03 00:22:16 +02:00
|
|
|
#define FT_MEM_SET_ERROR( cond ) ( (cond), error != 0 )
|
2001-10-22 16:50:41 +02:00
|
|
|
|
2006-01-27 13:11:22 +01:00
|
|
|
|
2015-02-16 07:03:22 +01:00
|
|
|
#define FT_MEM_SET( dest, byte, count ) \
|
|
|
|
ft_memset( dest, byte, (FT_Offset)(count) )
|
2006-01-27 13:11:22 +01:00
|
|
|
|
2015-02-16 07:03:22 +01:00
|
|
|
#define FT_MEM_COPY( dest, source, count ) \
|
|
|
|
ft_memcpy( dest, source, (FT_Offset)(count) )
|
2006-01-27 13:11:22 +01:00
|
|
|
|
2015-02-16 07:03:22 +01:00
|
|
|
#define FT_MEM_MOVE( dest, source, count ) \
|
|
|
|
ft_memmove( dest, source, (FT_Offset)(count) )
|
2006-01-27 13:11:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
#define FT_MEM_ZERO( dest, count ) FT_MEM_SET( dest, 0, count )
|
|
|
|
|
|
|
|
#define FT_ZERO( p ) FT_MEM_ZERO( p, sizeof ( *(p) ) )
|
|
|
|
|
* include/freetype/fterrdef.h, include/freetype/config/ftconfig.h,
include/freetype/internal/ftmemory.h, src/base/ftdbgmem.c,
src/base/ftutil.c: udpating the memory management functions and
macros to safely deal with array size buffer overflows, this
corresponds to attemps to allocate arrays that are too large. For
an example, consider the following code:
count = read_uint32_from_file();
array = malloc( sizeof(Item) * count );
for ( nn = 0; nn < count; nn++ )
array[nn] = read_item_from_file();
if 'count' is larger than FT_UINT_MAX/sizeof(Item), the multiplication
will overflow and the array allocated will be smaller than the data
read from the file. In this case, the heap will be trashed, and this
can be used as a denial-of-service, or make the engine crash later.
the FT_ARRAY_NEW and FT_ARRAY_RENEW macro now check that the new
count is no more than FT_INT_MAX/item_size, otherwise, a new error,
named 'FT_Err_Array_Too_Large' will be returned.
note that the memory debugger now works again when FT_DEBUG_MEMORY
is defined, and FT_STRICT_ALIASING has disappeared, the corresponding
code being now the default.
2006-05-02 08:34:27 +02:00
|
|
|
|
2015-02-16 07:03:22 +01:00
|
|
|
#define FT_ARRAY_ZERO( dest, count ) \
|
|
|
|
FT_MEM_ZERO( dest, \
|
|
|
|
(FT_Offset)(count) * sizeof ( *(dest) ) )
|
2006-01-27 13:11:22 +01:00
|
|
|
|
2015-02-16 07:03:22 +01:00
|
|
|
#define FT_ARRAY_COPY( dest, source, count ) \
|
|
|
|
FT_MEM_COPY( dest, \
|
|
|
|
source, \
|
|
|
|
(FT_Offset)(count) * sizeof ( *(dest) ) )
|
2006-01-27 13:11:22 +01:00
|
|
|
|
2015-02-16 07:03:22 +01:00
|
|
|
#define FT_ARRAY_MOVE( dest, source, count ) \
|
|
|
|
FT_MEM_MOVE( dest, \
|
|
|
|
source, \
|
|
|
|
(FT_Offset)(count) * sizeof ( *(dest) ) )
|
2006-01-27 13:11:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2018-08-24 18:52:30 +02:00
|
|
|
* Return the maximum number of addressable elements in an array. We limit
|
|
|
|
* ourselves to INT_MAX, rather than UINT_MAX, to avoid any problems.
|
2006-01-27 13:11:22 +01:00
|
|
|
*/
|
|
|
|
#define FT_ARRAY_MAX( ptr ) ( FT_INT_MAX / sizeof ( *(ptr) ) )
|
|
|
|
|
|
|
|
#define FT_ARRAY_CHECK( ptr, count ) ( (count) <= FT_ARRAY_MAX( ptr ) )
|
|
|
|
|
|
|
|
|
2018-06-03 22:00:42 +02:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* The following functions macros expect that their pointer argument is
|
|
|
|
* _typed_ in order to automatically compute array element sizes.
|
|
|
|
*/
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2013-06-05 13:43:20 +02:00
|
|
|
#define FT_MEM_NEW_ARRAY( ptr, count ) \
|
|
|
|
FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, \
|
|
|
|
sizeof ( *(ptr) ), \
|
|
|
|
0, \
|
|
|
|
(FT_Long)(count), \
|
|
|
|
NULL, \
|
|
|
|
&error ) )
|
|
|
|
|
|
|
|
#define FT_MEM_RENEW_ARRAY( ptr, cursz, newsz ) \
|
|
|
|
FT_ASSIGNP_INNER( ptr, ft_mem_realloc( memory, \
|
|
|
|
sizeof ( *(ptr) ), \
|
|
|
|
(FT_Long)(cursz), \
|
|
|
|
(FT_Long)(newsz), \
|
|
|
|
(ptr), \
|
|
|
|
&error ) )
|
|
|
|
|
|
|
|
#define FT_MEM_QNEW_ARRAY( ptr, count ) \
|
|
|
|
FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, \
|
|
|
|
sizeof ( *(ptr) ), \
|
|
|
|
0, \
|
|
|
|
(FT_Long)(count), \
|
|
|
|
NULL, \
|
|
|
|
&error ) )
|
|
|
|
|
|
|
|
#define FT_MEM_QRENEW_ARRAY( ptr, cursz, newsz ) \
|
|
|
|
FT_ASSIGNP_INNER( ptr, ft_mem_qrealloc( memory, \
|
|
|
|
sizeof ( *(ptr) ), \
|
|
|
|
(FT_Long)(cursz), \
|
|
|
|
(FT_Long)(newsz), \
|
|
|
|
(ptr), \
|
|
|
|
&error ) )
|
2005-03-04 00:05:29 +01:00
|
|
|
|
2006-05-03 00:22:16 +02:00
|
|
|
#define FT_ALLOC( ptr, size ) \
|
|
|
|
FT_MEM_SET_ERROR( FT_MEM_ALLOC( ptr, size ) )
|
2005-03-03 14:58:13 +01:00
|
|
|
|
2006-05-03 00:22:16 +02:00
|
|
|
#define FT_REALLOC( ptr, cursz, newsz ) \
|
|
|
|
FT_MEM_SET_ERROR( FT_MEM_REALLOC( ptr, cursz, newsz ) )
|
2006-05-02 11:00:29 +02:00
|
|
|
|
2006-05-03 00:22:16 +02:00
|
|
|
#define FT_ALLOC_MULT( ptr, count, item_size ) \
|
|
|
|
FT_MEM_SET_ERROR( FT_MEM_ALLOC_MULT( ptr, count, item_size ) )
|
2006-05-02 11:00:29 +02:00
|
|
|
|
2006-05-03 00:22:16 +02:00
|
|
|
#define FT_REALLOC_MULT( ptr, oldcnt, newcnt, itmsz ) \
|
|
|
|
FT_MEM_SET_ERROR( FT_MEM_REALLOC_MULT( ptr, oldcnt, \
|
|
|
|
newcnt, itmsz ) )
|
2004-06-24 08:56:06 +02:00
|
|
|
|
2006-05-03 00:22:16 +02:00
|
|
|
#define FT_QALLOC( ptr, size ) \
|
|
|
|
FT_MEM_SET_ERROR( FT_MEM_QALLOC( ptr, size ) )
|
2002-03-01 03:26:22 +01:00
|
|
|
|
2006-05-03 00:22:16 +02:00
|
|
|
#define FT_QREALLOC( ptr, cursz, newsz ) \
|
|
|
|
FT_MEM_SET_ERROR( FT_MEM_QREALLOC( ptr, cursz, newsz ) )
|
2006-05-02 11:00:29 +02:00
|
|
|
|
2006-05-03 00:22:16 +02:00
|
|
|
#define FT_QALLOC_MULT( ptr, count, item_size ) \
|
|
|
|
FT_MEM_SET_ERROR( FT_MEM_QALLOC_MULT( ptr, count, item_size ) )
|
2006-05-02 11:00:29 +02:00
|
|
|
|
2006-05-03 00:22:16 +02:00
|
|
|
#define FT_QREALLOC_MULT( ptr, oldcnt, newcnt, itmsz ) \
|
|
|
|
FT_MEM_SET_ERROR( FT_MEM_QREALLOC_MULT( ptr, oldcnt, \
|
|
|
|
newcnt, itmsz ) )
|
2002-03-25 17:35:13 +01:00
|
|
|
|
2006-05-03 00:22:16 +02:00
|
|
|
#define FT_FREE( ptr ) FT_MEM_FREE( ptr )
|
2000-05-16 21:51:49 +02:00
|
|
|
|
2006-05-03 00:22:16 +02:00
|
|
|
#define FT_NEW( ptr ) FT_MEM_SET_ERROR( FT_MEM_NEW( ptr ) )
|
2004-06-23 17:44:03 +02:00
|
|
|
|
2006-05-03 00:22:16 +02:00
|
|
|
#define FT_NEW_ARRAY( ptr, count ) \
|
|
|
|
FT_MEM_SET_ERROR( FT_MEM_NEW_ARRAY( ptr, count ) )
|
2004-06-23 17:44:03 +02:00
|
|
|
|
2006-05-03 00:22:16 +02:00
|
|
|
#define FT_RENEW_ARRAY( ptr, curcnt, newcnt ) \
|
|
|
|
FT_MEM_SET_ERROR( FT_MEM_RENEW_ARRAY( ptr, curcnt, newcnt ) )
|
2004-06-23 17:44:03 +02:00
|
|
|
|
2021-10-16 04:18:38 +02:00
|
|
|
#define FT_QNEW( ptr ) FT_MEM_SET_ERROR( FT_MEM_QNEW( ptr ) )
|
2004-06-24 08:56:06 +02:00
|
|
|
|
2021-10-16 04:18:38 +02:00
|
|
|
#define FT_QNEW_ARRAY( ptr, count ) \
|
|
|
|
FT_MEM_SET_ERROR( FT_MEM_QNEW_ARRAY( ptr, count ) )
|
2000-07-18 08:50:03 +02:00
|
|
|
|
2021-10-16 04:18:38 +02:00
|
|
|
#define FT_QRENEW_ARRAY( ptr, curcnt, newcnt ) \
|
|
|
|
FT_MEM_SET_ERROR( FT_MEM_QRENEW_ARRAY( ptr, curcnt, newcnt ) )
|
2002-03-30 00:23:28 +01:00
|
|
|
|
2005-03-16 00:31:48 +01:00
|
|
|
|
2007-02-12 15:55:03 +01:00
|
|
|
FT_BASE( FT_Pointer )
|
|
|
|
ft_mem_strdup( FT_Memory memory,
|
|
|
|
const char* str,
|
|
|
|
FT_Error *p_error );
|
|
|
|
|
|
|
|
FT_BASE( FT_Pointer )
|
|
|
|
ft_mem_dup( FT_Memory memory,
|
|
|
|
const void* address,
|
|
|
|
FT_ULong size,
|
|
|
|
FT_Error *p_error );
|
|
|
|
|
2013-05-10 07:58:47 +02:00
|
|
|
|
2007-07-07 09:30:40 +02:00
|
|
|
#define FT_MEM_STRDUP( dst, str ) \
|
|
|
|
(dst) = (char*)ft_mem_strdup( memory, (const char*)(str), &error )
|
2007-02-12 15:55:03 +01:00
|
|
|
|
2007-02-12 22:44:10 +01:00
|
|
|
#define FT_STRDUP( dst, str ) \
|
|
|
|
FT_MEM_SET_ERROR( FT_MEM_STRDUP( dst, str ) )
|
2007-02-12 15:55:03 +01:00
|
|
|
|
2007-02-12 22:44:10 +01:00
|
|
|
#define FT_MEM_DUP( dst, address, size ) \
|
|
|
|
(dst) = ft_mem_dup( memory, (address), (FT_ULong)(size), &error )
|
2007-02-12 15:55:03 +01:00
|
|
|
|
2007-02-12 22:44:10 +01:00
|
|
|
#define FT_DUP( dst, address, size ) \
|
|
|
|
FT_MEM_SET_ERROR( FT_MEM_DUP( dst, address, size ) )
|
2007-02-12 15:55:03 +01:00
|
|
|
|
2007-02-12 22:44:10 +01:00
|
|
|
|
|
|
|
/* Return >= 1 if a truncation occurs. */
|
|
|
|
/* Return 0 if the source string fits the buffer. */
|
|
|
|
/* This is *not* the same as strlcpy(). */
|
2007-02-12 15:55:03 +01:00
|
|
|
FT_BASE( FT_Int )
|
|
|
|
ft_mem_strcpyn( char* dst,
|
|
|
|
const char* src,
|
|
|
|
FT_ULong size );
|
|
|
|
|
2007-02-12 22:44:10 +01:00
|
|
|
#define FT_STRCPYN( dst, src, size ) \
|
|
|
|
ft_mem_strcpyn( (char*)dst, (const char*)(src), (FT_ULong)(size) )
|
2007-02-12 15:55:03 +01:00
|
|
|
|
2002-03-30 00:23:28 +01:00
|
|
|
|
2000-12-01 00:12:33 +01:00
|
|
|
FT_END_HEADER
|
2000-08-01 15:17:04 +02:00
|
|
|
|
2016-01-12 21:37:13 +01:00
|
|
|
#endif /* FTMEMORY_H_ */
|
2000-05-16 21:51:49 +02:00
|
|
|
|
2000-07-18 08:50:03 +02:00
|
|
|
|
2000-05-16 21:51:49 +02:00
|
|
|
/* END */
|