comparison mem.c @ 2422:18b8b2dcc037 libavcodec

various security fixes and precautionary checks
author michael
date Wed, 12 Jan 2005 00:16:25 +0000
parents f980082baeaa
children d0bcc85d3856
comparison
equal deleted inserted replaced
2421:e326490f58c4 2422:18b8b2dcc037
43 * CPU). av_malloc(0) must return a non NULL pointer. 43 * CPU). av_malloc(0) must return a non NULL pointer.
44 */ 44 */
45 void *av_malloc(unsigned int size) 45 void *av_malloc(unsigned int size)
46 { 46 {
47 void *ptr; 47 void *ptr;
48
49 /* lets disallow possible ambiguous cases */
50 if(size > INT_MAX)
51 return NULL;
48 52
49 #ifdef MEMALIGN_HACK 53 #ifdef MEMALIGN_HACK
50 int diff; 54 int diff;
51 ptr = malloc(size+16+1); 55 ptr = malloc(size+16+1);
52 diff= ((-(int)ptr - 1)&15) + 1; 56 diff= ((-(int)ptr - 1)&15) + 1;
91 * identical to malloc(size). If size is zero, it is identical to 95 * identical to malloc(size). If size is zero, it is identical to
92 * free(ptr) and NULL is returned. 96 * free(ptr) and NULL is returned.
93 */ 97 */
94 void *av_realloc(void *ptr, unsigned int size) 98 void *av_realloc(void *ptr, unsigned int size)
95 { 99 {
100 /* lets disallow possible ambiguous cases */
101 if(size > INT_MAX)
102 return NULL;
103
96 #ifdef MEMALIGN_HACK 104 #ifdef MEMALIGN_HACK
97 //FIXME this isnt aligned correctly though it probably isnt needed 105 //FIXME this isnt aligned correctly though it probably isnt needed
98 int diff; 106 int diff;
99 if(!ptr) return av_malloc(size); 107 if(!ptr) return av_malloc(size);
100 diff= ((char*)ptr)[-1]; 108 diff= ((char*)ptr)[-1];