Commit 8f026e90 authored by Philippe Gerum via Xenomai's avatar Philippe Gerum via Xenomai Committed by Jan Kiszka

lib/copperplate: heapobj: catch invalid array-type init request

Setting up a zero-size, zero-element array makes no sense with this
interface. Catch this early on, bailing out with -EINVAL.
Signed-off-by: Philippe Gerum's avatarPhilippe Gerum <rpm@xenomai.org>
Signed-off-by: Jan Kiszka's avatarJan Kiszka <jan.kiszka@siemens.com>
parent 05fdc509
......@@ -68,7 +68,12 @@ int __heapobj_init_private(struct heapobj *hobj, const char *name,
int heapobj_init_array_private(struct heapobj *hobj, const char *name,
size_t size, int elems)
{
size_t log2 = sizeof(size) * CHAR_BIT - 1 -
size_t log2;
if (size == 0 || elems <= 0)
return __bt(-EINVAL);
log2 = sizeof(size) * CHAR_BIT - 1 -
xenomai_count_leading_zeros(size);
/*
......
......@@ -84,6 +84,9 @@ int __heapobj_init_private(struct heapobj *hobj, const char *name,
int heapobj_init_array_private(struct heapobj *hobj, const char *name,
size_t size, int elems)
{
if (size == 0 || elems <= 0)
return __bt(-EINVAL);
return __bt(__heapobj_init_private(hobj, name, size * elems, NULL));
}
......
......@@ -69,6 +69,9 @@ int heapobj_init_array_private(struct heapobj *hobj, const char *name,
{
size_t poolsz;
if (size == 0 || elems <= 0)
return __bt(-EINVAL);
poolsz = (size + TLSF_BLOCK_ALIGN - 1) & ~(TLSF_BLOCK_ALIGN - 1);
poolsz *= elems;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment