From 56bef797506f7570090a3b144256e41185299408 Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Sun, 22 Apr 2012 00:04:30 +0000 Subject: check of avutil. avio, avformat and avcodec still to do. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2862 b956fd51-792f-4845-bead-9b4dfca2ff2c --- src/lib/ffmpeg-0.8/libavutil/mem.pas | 54 ++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 6 deletions(-) (limited to 'src/lib/ffmpeg-0.8/libavutil/mem.pas') diff --git a/src/lib/ffmpeg-0.8/libavutil/mem.pas b/src/lib/ffmpeg-0.8/libavutil/mem.pas index b68dd310..322a8657 100644 --- a/src/lib/ffmpeg-0.8/libavutil/mem.pas +++ b/src/lib/ffmpeg-0.8/libavutil/mem.pas @@ -29,9 +29,6 @@ *) (* memory handling functions *) - -type - FF_INTERNAL_MEM_TYPE = cuint; (** * Allocate a block of size bytes with alignment suitable for all @@ -41,7 +38,7 @@ type * be allocated. * @see av_mallocz() *) -function av_malloc(size: FF_INTERNAL_MEM_TYPE): pointer; +function av_malloc(size: size_t): pointer; cdecl; external av__util; {av_malloc_attrib av_alloc_size(1)} (** @@ -56,9 +53,22 @@ function av_malloc(size: FF_INTERNAL_MEM_TYPE): pointer; * cannot be allocated or the function is used to free the memory block. * @see av_fast_realloc() *) -function av_realloc(ptr: pointer; size: FF_INTERNAL_MEM_TYPE): pointer; +function av_realloc(ptr: pointer; size: size_t): pointer; cdecl; external av__util; {av_alloc_size(2)} +(** + * Allocate or reallocate a block of memory. + * This function does the same thing as av_realloc, except: + * - It takes two arguments and checks the result of the multiplication for + * integer overflow. + * - It frees the input block in case of failure, thus avoiding the memory + * leak with the classic "buf = realloc(buf); if (!buf) return -1;". + *) +{ available only in 0.8.5 - 0.8.10 +function av_realloc_f(ptr: pointer; nelem: size_t; size: size_t): pointer; + cdecl; external av__util; +} + (** * Free a memory block which has been allocated with av_malloc(z)() or * av_realloc(). @@ -78,9 +88,24 @@ procedure av_free(ptr: pointer); * @return Pointer to the allocated block, NULL if it cannot be allocated. * @see av_malloc() *) -function av_mallocz(size: FF_INTERNAL_MEM_TYPE): pointer; +function av_mallocz(size: size_t): pointer; cdecl; external av__util; {av_malloc_attrib av_alloc_size(1)} +(** + * Allocate a block of nmemb * size bytes with alignment suitable for all + * memory accesses (including vectors if available on the CPU) and + * zero all the bytes of the block. + * The allocation will fail if nmemb * size is greater than or equal + * to INT_MAX. + * @param nmemb + * @param size + * @return Pointer to the allocated block, NULL if it cannot be allocated. + *) +{ available only in 0.8.5 - 0.8.10 +function av_calloc(nmemb: size_t; size: size_t): pointer; + cdecl; external av__util; {av_malloc_attrib} +} + (** * Duplicate the string s. * @param s string to be duplicated. @@ -109,3 +134,20 @@ procedure av_freep (ptr: pointer); *) procedure av_dynarray_add(tab_ptr: pointer; nb_ptr: PCint; elem: pointer); cdecl; external av__util; + +(** + * Multiply two size_t values checking for overflow. + * @return 0 if success, AVERROR(EINVAL) if overflow. + *) +{ available only in 0.8.5 - 0.8.10 +//static inline int av_size_mult(size_t a, size_t b, size_t *r) +} +{ + size_t t = a * b; + /* Hack inspired from glibc: only try the division if nelem and elsize + * are both greater than sqrt(SIZE_MAX). */ + if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b) + return AVERROR(EINVAL); + *r = t; + return 0; +} -- cgit v1.2.3