From 39b656ec4bb942939456532534b2d5585b050bc1 Mon Sep 17 00:00:00 2001 From: Carsten Burstedde Date: Sun, 21 Jul 2024 13:33:38 +0200 Subject: [PATCH] sc_mpi: assert pointers depending on positive size --- src/sc_mpi.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/sc_mpi.c b/src/sc_mpi.c index 5be898c4..4b067bfc 100644 --- a/src/sc_mpi.c +++ b/src/sc_mpi.c @@ -296,7 +296,10 @@ sc_MPI_Gather (void *p, int np, sc_MPI_Datatype tp, /* *INDENT-ON* */ SC_ASSERT (lp == lq); - memcpy (q, p, lp); + if (lp > 0) { + SC_ASSERT (p != NULL && q != NULL); + memcpy (q, p, lp); + } return sc_MPI_SUCCESS; } @@ -324,7 +327,11 @@ sc_MPI_Gatherv (void *p, int np, sc_MPI_Datatype tp, /* *INDENT-ON* */ SC_ASSERT (lp == lq); - memcpy ((char *) q + displ[0] * sc_mpi_sizeof (tq), p, lp); + if (lp > 0) { + SC_ASSERT (p != NULL && q != NULL); + SC_ASSERT (displ != NULL); + memcpy ((char *) q + displ[0] * sc_mpi_sizeof (tq), p, lp); + } return sc_MPI_SUCCESS; } @@ -364,7 +371,10 @@ sc_MPI_Reduce (void *p, void *q, int n, sc_MPI_Datatype t, l = (size_t) n * sc_mpi_sizeof (t); /* *INDENT-ON* */ - memcpy (q, p, l); + if (l > 0) { + SC_ASSERT (p != NULL && q != NULL); + memcpy (q, p, l); + } return sc_MPI_SUCCESS; } @@ -492,8 +502,12 @@ sc_MPI_Pack (const void *inbuf, int incount, sc_MPI_Datatype datatype, } /* Copy the contiguous memory */ - memcpy ((char *) outbuf + *position, inbuf, size); - *position += size; + if (size > 0) { + SC_ASSERT (outbuf != NULL); + SC_ASSERT (inbuf != NULL); + memcpy ((char *) outbuf + *position, inbuf, size); + *position += size; + } return sc_MPI_SUCCESS; } @@ -518,8 +532,12 @@ sc_MPI_Unpack (const void *inbuf, int insize, int *position, } /* Copy the contiguous memory */ - memcpy (outbuf, (char *) inbuf + *position, size); - *position += size; + if (size > 0) { + SC_ASSERT (outbuf != NULL); + SC_ASSERT (inbuf != NULL); + memcpy (outbuf, (char *) inbuf + *position, size); + *position += size; + } return sc_MPI_SUCCESS; }