[XviD-devel] mem_align.c problem

pikatu xvid-devel@xvid.org
Thu, 28 Nov 2002 11:03:41 +0000


The patch that came with my original message is correct, 

if (!alignment) {
                /* We have not to satisfy any alignment */
                if ((mem_ptr = (uint8_t *) malloc(size + 1)) != NULL) {

               /* Store (mem_ptr - "real allocated memory") in *(mem_ptr-1) */
                        *mem_ptr = 1;
                        /* Return the mem_ptr pointer */
                        return (void *) ++mem_ptr;
                }

The code in my second message was not meant to be a patch. 

A related question. In encoder.c 

	/* 1 keyframe each 10 seconds */

	if (pParam->max_key_interval <= 0)
		pParam->max_key_interval = 10 * pParam->fincr / pParam->fbase;

Shouldn't it be 
		10 / pParam->fincr * pParam->fbase;






On Wednesday 27 November 2002 21:19, Edouard Gomez wrote:
> pikatu (pikatu@012.net.il) wrote:
> > you are wrong edouard.
>
> Yes you're  right, you're  patch was wrong  too :-) Everything  is wrong
> here.
>
> The correct  patch is just  to return (void*)(mem_ptr+1).  The mem_ptr++
> was wrong  or should have  been a prefixed increment  ++mem_ptr. Typical
> typo error when coding.
>
> Thanks for the report.
>
> PS: your  patch was  wrong because it  writes outside the  malloc block,
> this is not important with a libc that adds boundaries before the malloc
> block and after the malloc block (typical with msvc libs) but for a libc
> that  does not  add protection  boundaries, this  could have  lead  to a
> segmentation fault (memory access exception on win32)