Skip to content

Commit

Permalink
avoid zero-sized memcpy (fixes #321)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjakob committed Oct 13, 2023
1 parent 249adc0 commit 939487b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/implicit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ void implicitly_convertible(const std::type_info *src,

void **data = (void **) malloc(sizeof(void *) * (size + 2));

memcpy(data, t->implicit, size * sizeof(void *));
if (size)
memcpy(data, t->implicit, size * sizeof(void *));
data[size] = (void *) src;
data[size + 1] = nullptr;
free(t->implicit);
Expand Down Expand Up @@ -66,7 +67,8 @@ void implicitly_convertible(bool (*predicate)(PyTypeObject *, PyObject *,
}

void **data = (void **) malloc(sizeof(void *) * (size + 2));
memcpy(data, t->implicit_py, size * sizeof(void *));
if (size)
memcpy(data, t->implicit_py, size * sizeof(void *));
data[size] = (void *) predicate;
data[size + 1] = nullptr;
free(t->implicit_py);
Expand Down

0 comments on commit 939487b

Please sign in to comment.