motion icon indicating copy to clipboard operation
motion copied to clipboard

Fix incorrect sizeof() calculations in malloc and memset

Open aklomp opened this issue 10 years ago • 1 comments

The proper idiom for calculating an image's memory size from a pointer using sizeof() is:

ptr = malloc(width * height * sizeof(*ptr));

The sizeof() dereferences the pointer's type, and allocates enough memory to store an image's worth of elements of that type. However, Motion was occasionally using this pattern:

ptr = malloc(width * height * sizeof(ptr));

Not dereferencing the pointer, this uses the storage size of the pointer itself, not its target type, for the calculation. While this is probably not immediately harmful since pointers tend to be large, it is incorrect. This pull request fixes a number of these issues.

aklomp avatar May 03 '14 18:05 aklomp

Rather than rebase, I have rolled back the affected files and removed your changes from my fork.

Mr-Dave avatar Sep 07 '14 18:09 Mr-Dave