mirror of
https://github.com/Motion-Project/motion.git
synced 2026-02-07 05:22:06 -05:00
bugfix: motion.c: calculate proper allocation size
The proper idiom for calculating the size for memory allocation is: ptr = malloc(sizeof(*ptr)); The sizeof() dereferences the pointer's type, and allocates enough memory to store an instance of that type. motion.c was using this idiom: ptr = malloc(sizeof(ptr)); This is incorrect, but thankfully fairly harmless in practice since the pointer type is usually quite large. Change this to the proper idiom.
This commit is contained in:
8
motion.c
8
motion.c
@@ -723,13 +723,13 @@ static int motion_init(struct context *cnt)
|
||||
memset(cnt->imgs.out, 0, cnt->imgs.size);
|
||||
|
||||
/* contains the moving objects of ref. frame */
|
||||
cnt->imgs.ref_dyn = mymalloc(cnt->imgs.motionsize * sizeof(cnt->imgs.ref_dyn));
|
||||
cnt->imgs.ref_dyn = mymalloc(cnt->imgs.motionsize * sizeof(*cnt->imgs.ref_dyn));
|
||||
cnt->imgs.image_virgin = mymalloc(cnt->imgs.size);
|
||||
cnt->imgs.smartmask = mymalloc(cnt->imgs.motionsize);
|
||||
cnt->imgs.smartmask_final = mymalloc(cnt->imgs.motionsize);
|
||||
cnt->imgs.smartmask_buffer = mymalloc(cnt->imgs.motionsize * sizeof(cnt->imgs.smartmask_buffer));
|
||||
cnt->imgs.labels = mymalloc(cnt->imgs.motionsize * sizeof(cnt->imgs.labels));
|
||||
cnt->imgs.labelsize = mymalloc((cnt->imgs.motionsize/2+1) * sizeof(cnt->imgs.labelsize));
|
||||
cnt->imgs.smartmask_buffer = mymalloc(cnt->imgs.motionsize * sizeof(*cnt->imgs.smartmask_buffer));
|
||||
cnt->imgs.labels = mymalloc(cnt->imgs.motionsize * sizeof(*cnt->imgs.labels));
|
||||
cnt->imgs.labelsize = mymalloc((cnt->imgs.motionsize/2+1) * sizeof(*cnt->imgs.labelsize));
|
||||
|
||||
/* Set output picture type */
|
||||
if (!strcmp(cnt->conf.picture_type, "ppm"))
|
||||
|
||||
Reference in New Issue
Block a user