Skip to content

Commit 221e6e2

Browse files
committed
Add the datatype checks to the pack/unpack functions.
The datatype must satisfy the same constraints as for the corresponding communication function (send for pack and recv for unpack).
1 parent 1ff2a38 commit 221e6e2

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

ompi/mpi/c/pack.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
44
* University Research and Technology
55
* Corporation. All rights reserved.
6-
* Copyright (c) 2004-2005 The University of Tennessee and The University
6+
* Copyright (c) 2004-2016 The University of Tennessee and The University
77
* of Tennessee Research Foundation. All rights
88
* reserved.
99
* Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
@@ -45,7 +45,7 @@ static const char FUNC_NAME[] = "MPI_Pack";
4545
int MPI_Pack(const void *inbuf, int incount, MPI_Datatype datatype,
4646
void *outbuf, int outsize, int *position, MPI_Comm comm)
4747
{
48-
int rc;
48+
int rc = MPI_SUCCESS;
4949
opal_convertor_t local_convertor;
5050
struct iovec invec;
5151
unsigned int iov_count;
@@ -67,9 +67,11 @@ int MPI_Pack(const void *inbuf, int incount, MPI_Datatype datatype,
6767
return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_COUNT, FUNC_NAME);
6868
} else if (outsize < 0) {
6969
return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG, FUNC_NAME);
70-
} else if (MPI_DATATYPE_NULL == datatype || NULL == datatype) {
71-
return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_TYPE, FUNC_NAME);
7270
}
71+
OMPI_CHECK_DATATYPE_FOR_SEND(rc, datatype, incount);
72+
OMPI_ERRHANDLER_CHECK(rc, comm, rc, FUNC_NAME);
73+
OMPI_CHECK_USER_BUFFER(rc, inbuf, datatype, incount);
74+
OMPI_ERRHANDLER_CHECK(rc, comm, rc, FUNC_NAME);
7375
}
7476

7577
OPAL_CR_ENTER_LIBRARY();

ompi/mpi/c/pack_external.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
44
* University Research and Technology
55
* Corporation. All rights reserved.
6-
* Copyright (c) 2004-2005 The University of Tennessee and The University
6+
* Copyright (c) 2004-2016 The University of Tennessee and The University
77
* of Tennessee Research Foundation. All rights
88
* reserved.
99
* Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
@@ -46,7 +46,7 @@ int MPI_Pack_external(const char datarep[], const void *inbuf, int incount,
4646
MPI_Datatype datatype, void *outbuf,
4747
MPI_Aint outsize, MPI_Aint *position)
4848
{
49-
int rc;
49+
int rc = MPI_SUCCESS;
5050
opal_convertor_t local_convertor;
5151
struct iovec invec;
5252
unsigned int iov_count;
@@ -65,9 +65,11 @@ int MPI_Pack_external(const char datarep[], const void *inbuf, int incount,
6565
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COUNT, FUNC_NAME);
6666
} else if (outsize < 0) {
6767
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG, FUNC_NAME);
68-
} else if (MPI_DATATYPE_NULL == datatype || NULL == datatype) {
69-
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_TYPE, FUNC_NAME);
7068
}
69+
OMPI_CHECK_DATATYPE_FOR_SEND(rc, datatype, incount);
70+
OMPI_ERRHANDLER_CHECK(rc, MPI_COMM_WORLD, rc, FUNC_NAME);
71+
OMPI_CHECK_USER_BUFFER(rc, inbuf, datatype, incount);
72+
OMPI_ERRHANDLER_CHECK(rc, MPI_COMM_WORLD, rc, FUNC_NAME);
7173
}
7274

7375
OPAL_CR_ENTER_LIBRARY();

ompi/mpi/c/unpack.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
33
* University Research and Technology
44
* Corporation. All rights reserved.
5-
* Copyright (c) 2004-2005 The University of Tennessee and The University
5+
* Copyright (c) 2004-2016 The University of Tennessee and The University
66
* of Tennessee Research Foundation. All rights
77
* reserved.
88
* Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
@@ -43,7 +43,7 @@ int MPI_Unpack(const void *inbuf, int insize, int *position,
4343
void *outbuf, int outcount, MPI_Datatype datatype,
4444
MPI_Comm comm)
4545
{
46-
int rc = 1;
46+
int rc = MPI_SUCCESS;
4747
opal_convertor_t local_convertor;
4848
struct iovec outvec;
4949
unsigned int iov_count;
@@ -70,9 +70,10 @@ int MPI_Unpack(const void *inbuf, int insize, int *position,
7070
return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_COUNT, FUNC_NAME);
7171
}
7272

73-
if (MPI_DATATYPE_NULL == datatype || NULL == datatype) {
74-
return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_TYPE, FUNC_NAME);
75-
}
73+
OMPI_CHECK_DATATYPE_FOR_RECV(rc, datatype, outcount);
74+
OMPI_ERRHANDLER_CHECK(rc, comm, rc, FUNC_NAME);
75+
OMPI_CHECK_USER_BUFFER(rc, outbuf, datatype, outcount);
76+
OMPI_ERRHANDLER_CHECK(rc, comm, rc, FUNC_NAME);
7677
}
7778

7879
OPAL_CR_ENTER_LIBRARY();
@@ -103,12 +104,11 @@ int MPI_Unpack(const void *inbuf, int insize, int *position,
103104

104105
/* All done. Note that the convertor returns 1 upon success, not
105106
OMPI_SUCCESS. */
106-
107+
rc = (1 == rc) ? OMPI_SUCCESS : OMPI_ERROR;
107108
}
108109

109110
OPAL_CR_EXIT_LIBRARY();
110111

111112
OMPI_ERRHANDLER_RETURN((rc == 1) ? OMPI_SUCCESS : OMPI_ERROR,
112113
comm, MPI_ERR_UNKNOWN, FUNC_NAME);
113-
114114
}

ompi/mpi/c/unpack_external.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
44
* University Research and Technology
55
* Corporation. All rights reserved.
6-
* Copyright (c) 2004-2005 The University of Tennessee and The University
6+
* Copyright (c) 2004-2016 The University of Tennessee and The University
77
* of Tennessee Research Foundation. All rights
88
* reserved.
99
* Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
@@ -45,7 +45,7 @@ int MPI_Unpack_external (const char datarep[], const void *inbuf, MPI_Aint insiz
4545
MPI_Aint *position, void *outbuf, int outcount,
4646
MPI_Datatype datatype)
4747
{
48-
int rc;
48+
int rc = MPI_SUCCESS;
4949
opal_convertor_t local_convertor;
5050
struct iovec outvec;
5151
unsigned int iov_count;
@@ -62,9 +62,11 @@ int MPI_Unpack_external (const char datarep[], const void *inbuf, MPI_Aint insiz
6262
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG, FUNC_NAME);
6363
} else if (outcount < 0) {
6464
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COUNT, FUNC_NAME);
65-
} else if (MPI_DATATYPE_NULL == datatype || NULL == datatype) {
66-
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_TYPE, FUNC_NAME);
6765
}
66+
OMPI_CHECK_DATATYPE_FOR_RECV(rc, datatype, outcount);
67+
OMPI_ERRHANDLER_CHECK(rc, MPI_COMM_WORLD, rc, FUNC_NAME);
68+
OMPI_CHECK_USER_BUFFER(rc, outbuf, datatype, outcount);
69+
OMPI_ERRHANDLER_CHECK(rc, MPI_COMM_WORLD, rc, FUNC_NAME);
6870
}
6971

7072
OPAL_CR_ENTER_LIBRARY();
@@ -73,7 +75,9 @@ int MPI_Unpack_external (const char datarep[], const void *inbuf, MPI_Aint insiz
7375

7476
/* the resulting convertor will be set to the position ZERO */
7577
opal_convertor_copy_and_prepare_for_recv( ompi_mpi_external32_convertor,
76-
&(datatype->super), outcount, outbuf, 0, &local_convertor );
78+
&(datatype->super), outcount, outbuf,
79+
0,
80+
&local_convertor );
7781

7882
/* Check for truncation */
7983
opal_convertor_get_packed_size( &local_convertor, &size );

0 commit comments

Comments
 (0)