Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect sizeof() calculations in malloc and memset #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions alg.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ static int alg_labeling(struct context *cnt)
imgs->labels_above = 0;

/* Init: 0 means no label set / not checked. */
memset(labels, 0, width * height * sizeof(labels));
memset(labels, 0, width * height * sizeof(*labels));
pixelpos = 0;

for (iy = 0; iy < height - 1; iy++) {
Expand Down Expand Up @@ -1363,6 +1363,6 @@ void alg_update_reference_frame(struct context *cnt, int action)
/* Copy fresh image */
memcpy(cnt->imgs.ref, cnt->imgs.image_virgin, cnt->imgs.size);
/* Reset static objects */
memset(cnt->imgs.ref_dyn, 0, cnt->imgs.motionsize * sizeof(cnt->imgs.ref_dyn));
memset(cnt->imgs.ref_dyn, 0, cnt->imgs.motionsize * sizeof(*cnt->imgs.ref_dyn));
}
}
10 changes: 5 additions & 5 deletions motion.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -917,7 +917,7 @@ static int motion_init(struct context *cnt)
/* Always initialize smart_mask - someone could turn it on later... */
memset(cnt->imgs.smartmask, 0, cnt->imgs.motionsize);
memset(cnt->imgs.smartmask_final, 255, cnt->imgs.motionsize);
memset(cnt->imgs.smartmask_buffer, 0, cnt->imgs.motionsize*sizeof(cnt->imgs.smartmask_buffer));
memset(cnt->imgs.smartmask_buffer, 0, cnt->imgs.motionsize * sizeof(*cnt->imgs.smartmask_buffer));

/* Set noise level */
cnt->noise = cnt->conf.noise;
Expand Down