Skip to content
Snippets Groups Projects
Commit 178f0cb7 authored by Thomas Jahns's avatar Thomas Jahns :cartwheel:
Browse files

Prevent creation of zero size index vector.

parent 8b27f032
No related branches found
No related tags found
No related merge requests found
......@@ -361,25 +361,28 @@ xt_idxvec_from_stripes_new(const struct Xt_stripe stripes[],
assert((sizeof (long long) > sizeof (int)) & (num_indices <= INT_MAX)
& (num_indices >= 0));
size_t vector_size = (size_t)num_indices * sizeof (Xt_int),
header_size = ((sizeof (struct Xt_idxvec_) + sizeof (Xt_int) - 1)
/sizeof (Xt_int)) * sizeof (Xt_int);
Xt_idxvec idxvec_obj = xmalloc(header_size + vector_size);
Xt_int *restrict indices
= (Xt_int *)(void *)((unsigned char *)idxvec_obj + header_size);
idxvec_obj->vector = indices;
size_t k = (size_t)-1;
for (int i = 0; i < num_stripes; ++i)
for (int j = 0; j < stripes[i].nstrides; ++j)
indices[++k] = (Xt_int)(stripes[i].start + j * stripes[i].stride);
Xt_idxlist_init(&idxvec_obj->parent, &idxvec_vtable, (int)num_indices);
generate_sorted_vector_from_stripes(stripes, num_stripes, idxvec_obj);
return (Xt_idxlist)idxvec_obj;
Xt_idxlist idxlist;
if (num_indices > 0) {
size_t vector_size = (size_t)num_indices * sizeof (Xt_int),
header_size = ((sizeof (struct Xt_idxvec_) + sizeof (Xt_int) - 1)
/sizeof (Xt_int)) * sizeof (Xt_int);
Xt_idxvec idxvec_obj = xmalloc(header_size + vector_size);
Xt_int *restrict indices
= (Xt_int *)(void *)((unsigned char *)idxvec_obj + header_size);
idxvec_obj->vector = indices;
size_t k = (size_t)-1;
for (int i = 0; i < num_stripes; ++i)
for (int j = 0; j < stripes[i].nstrides; ++j)
indices[++k] = (Xt_int)(stripes[i].start + j * stripes[i].stride);
Xt_idxlist_init(&idxvec_obj->parent, &idxvec_vtable, (int)num_indices);
generate_sorted_vector_from_stripes(stripes, num_stripes, idxvec_obj);
idxlist = (Xt_idxlist)idxvec_obj;
} else
idxlist = xt_idxempty_new();
return idxlist;
}
static void idxvec_delete(Xt_idxlist obj) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment