Skip to content

Commit cc8d75f

Browse files
committed
coll/base CID 1516784+1516786: fix bad shift
This almost certainly never happens in practice, but we might as well be defensive and handle the error case. Signed-off-by: Jeff Squyres <jsquyres@cisco.com>
1 parent 23fe4f7 commit cc8d75f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

ompi/mca/coll/base/coll_base_allreduce.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* and Technology (RIST). All rights reserved.
1818
* Copyright (c) 2018 Siberian State University of Telecommunications
1919
* and Information Science. All rights reserved.
20+
* Copyright (c) 2022 Cisco Systems, Inc. All rights reserved.
2021
* $COPYRIGHT$
2122
*
2223
* Additional copyrights may follow
@@ -982,7 +983,9 @@ int ompi_coll_base_allreduce_intra_redscat_allgather(
982983

983984
/* Find nearest power-of-two less than or equal to comm_size */
984985
int nsteps = opal_hibit(comm_size, comm->c_cube_dim + 1); /* ilog2(comm_size) */
985-
assert(nsteps >= 0);
986+
if (-1 == nsteps) {
987+
return MPI_ERR_ARG;
988+
}
986989
int nprocs_pof2 = 1 << nsteps; /* flp2(comm_size) */
987990

988991
if (count < nprocs_pof2 || !ompi_op_is_commute(op)) {

ompi/mca/coll/base/coll_base_reduce.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* Copyright (c) 2016-2017 IBM Corporation. All rights reserved.
1818
* Copyright (c) 2018 Siberian State University of Telecommunications
1919
* and Information Science. All rights reserved.
20+
* Copyright (c) 2022 Cisco Systems, Inc. All rights reserved.
2021
* $COPYRIGHT$
2122
*
2223
* Additional copyrights may follow
@@ -812,7 +813,9 @@ int ompi_coll_base_reduce_intra_redscat_gather(
812813

813814
/* Find nearest power-of-two less than or equal to comm_size */
814815
int nsteps = opal_hibit(comm_size, comm->c_cube_dim + 1); /* ilog2(comm_size) */
815-
assert(nsteps >= 0);
816+
if (-1 == nsteps) {
817+
return MPI_ERR_ARG;
818+
}
816819
int nprocs_pof2 = 1 << nsteps; /* flp2(comm_size) */
817820

818821
if (nprocs_pof2 < 2 || count < nprocs_pof2 || !ompi_op_is_commute(op)) {

0 commit comments

Comments
 (0)