motion
motion copied to clipboard
Fix incorrect sizeof() calculations in malloc and memset
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.
Rather than rebase, I have rolled back the affected files and removed your changes from my fork.