bska fixed integer overflow in malloc call
Signed-off-by: Bård Skaflestad <Bard.Skaflestad@sintef.no>
This commit is contained in:
parent
f2b111f504
commit
1f0b08755c
@ -51,6 +51,7 @@ void free_sparse_table (sparse_table_t *tab)
|
||||
|
||||
sparse_table_t *malloc_sparse_table(int m, int n, int datasz)
|
||||
{
|
||||
size_t alloc_sz;
|
||||
sparse_table_t *tab = malloc(sizeof *tab);
|
||||
tab->m = m;
|
||||
tab->n = n;
|
||||
@ -61,8 +62,9 @@ sparse_table_t *malloc_sparse_table(int m, int n, int datasz)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
if(!(tab->data = malloc(n * datasz))){
|
||||
alloc_sz = datasz;
|
||||
alloc_sz *= n;
|
||||
if(!(tab->data = malloc(alloc_sz))){
|
||||
fprintf(stderr, "Could not allocate space for sparse data(%d)\n", n);
|
||||
free_sparse_table(tab);
|
||||
return NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user