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:
Alfred Klomp
2014-05-02 10:49:50 +02:00
parent 95c6a9fd29
commit d0cc56c733

View File

@@ -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"))