Skip to content

Commit

Permalink
fix memory allocation to be portable
Browse files Browse the repository at this point in the history
or as Coverity puts it:

suspicious_sizeof: Passing argument /* sizeof (struct ts_sample_mt **) */ to function malloc and then casting the return value to struct ts_sample_mt ** is suspicious. In this particular case sizeof (struct ts_sample_mt **) happens to be equal to sizeof (struct ts_sample_mt *), but this is not a portable assumption.
  • Loading branch information
merge committed Dec 14, 2016
1 parent 5df29eb commit cebfbd6
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion plugins/input-raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ static int ts_input_read_mt(struct tslib_module_info *inf,
int pen_up = 0;

if (i->buf == NULL) {
i->buf = malloc(nr * sizeof(struct ts_sample_mt **));
i->buf = malloc(nr * sizeof(struct ts_sample_mt *));
if (!i->buf)
return -ENOMEM;

Expand Down
2 changes: 1 addition & 1 deletion plugins/median.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ static int median_read_mt(struct tslib_module_info *inf, struct ts_sample_mt **s
free(c->delay_mt);
}

c->delay_mt = malloc(max_slots * sizeof(struct ts_sample_mt **));
c->delay_mt = malloc(max_slots * sizeof(struct ts_sample_mt *));
if (!c->delay_mt)
return -ENOMEM;

Expand Down
2 changes: 1 addition & 1 deletion plugins/variance.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ static int variance_read_mt(struct tslib_module_info *info, struct ts_sample_mt
if (!samp)
return -ENOMEM;

cur_mt = malloc(nr * sizeof(struct ts_sample_mt **));
cur_mt = malloc(nr * sizeof(struct ts_sample_mt *));
if (!cur_mt) {
free(samp);
return -ENOMEM;
Expand Down
2 changes: 1 addition & 1 deletion tools/ts_uinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ int main(int argc, char **argv)
if (!data.ev)
goto out;

data.s_array = calloc(TS_READ_WHOLE_SAMPLES, sizeof(struct ts_sample_mt **));
data.s_array = calloc(TS_READ_WHOLE_SAMPLES, sizeof(struct ts_sample_mt *));
if (!data.s_array)
goto out;

Expand Down

0 comments on commit cebfbd6

Please sign in to comment.