Fix call of memcpy with size=0 and src=NULL
This commit is contained in:
1 parent
b3440a2edd
commit
93b69d0f8b
1 file changed
+13
-8
+13
-8
@@ -121,16 +121,21 @@ m_bitset_set(m_bitset_t d, const m_bitset_t s)
|
|||||||
M_B1TSET_CONTRACT(s);
|
M_B1TSET_CONTRACT(s);
|
||||||
if (M_UNLIKELY (d == s)) return;
|
if (M_UNLIKELY (d == s)) return;
|
||||||
const size_t needAlloc = M_B1TSET_TO_ALLOC (s->size);
|
const size_t needAlloc = M_B1TSET_TO_ALLOC (s->size);
|
||||||
if (s->size > M_B1TSET_FROM_ALLOC (d->alloc)) {
|
if (M_LIKELY (s->size > 0)) {
|
||||||
m_b1tset_limb_ct *ptr = M_MEMORY_REALLOC (m_b1tset_limb_ct, d->ptr, needAlloc);
|
// Test if enough space in target
|
||||||
if (M_UNLIKELY (ptr == NULL)) {
|
if (s->size > M_B1TSET_FROM_ALLOC (d->alloc)) {
|
||||||
M_MEMORY_FULL(needAlloc);
|
m_b1tset_limb_ct *ptr = M_MEMORY_REALLOC (m_b1tset_limb_ct, d->ptr, needAlloc);
|
||||||
return ;
|
if (M_UNLIKELY (ptr == NULL)) {
|
||||||
|
M_MEMORY_FULL(needAlloc);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
d->ptr = ptr;
|
||||||
|
d->alloc = needAlloc;
|
||||||
}
|
}
|
||||||
d->ptr = ptr;
|
M_ASSERT(d->ptr != NULL);
|
||||||
d->alloc = needAlloc;
|
M_ASSERT(s->ptr != NULL);
|
||||||
|
memcpy (d->ptr, s->ptr, needAlloc * sizeof(m_b1tset_limb_ct) );
|
||||||
}
|
}
|
||||||
memcpy (d->ptr, s->ptr, needAlloc * sizeof(m_b1tset_limb_ct) );
|
|
||||||
d->size = s->size;
|
d->size = s->size;
|
||||||
M_B1TSET_CONTRACT(d);
|
M_B1TSET_CONTRACT(d);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user