And avoid to call memcpy with overlapping regions.
int smpi_datatype_copy(void *sendbuf, int sendcount, MPI_Datatype sendtype,
void *recvbuf, int recvcount, MPI_Datatype recvtype)
{
int smpi_datatype_copy(void *sendbuf, int sendcount, MPI_Datatype sendtype,
void *recvbuf, int recvcount, MPI_Datatype recvtype)
{
/* First check if we really have something to do */
/* First check if we really have something to do */
- if (recvcount == 0) {
- retval = sendcount == 0 ? MPI_SUCCESS : MPI_ERR_TRUNCATE;
- } else {
+ if (recvcount > 0 && recvbuf != sendbuf) {
/* FIXME: treat packed cases */
sendcount *= smpi_datatype_size(sendtype);
recvcount *= smpi_datatype_size(recvtype);
/* FIXME: treat packed cases */
sendcount *= smpi_datatype_size(sendtype);
recvcount *= smpi_datatype_size(recvtype);
- retval = sendcount > recvcount ? MPI_ERR_TRUNCATE : MPI_SUCCESS;
+ return sendcount > recvcount ? MPI_ERR_TRUNCATE : MPI_SUCCESS;