Skip to content

Commit 3ea6dd6

Browse files
leekilloughhughes-c
authored andcommitted
Replace Variable-Length Arrays with arrays allocated with std::make_unique (sstsimulator#2512)
1 parent f913110 commit 3ea6dd6

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ SST_ELEMENT_CONFIG_OUTPUT()
6262
# depending on the use-picky flag
6363
SST_CHECK_PICKY
6464
AS_IF([test "x$use_picky" = "xyes"],
65-
[WARNFLAGS="-Wall -Wextra"],
65+
[WARNFLAGS="-Wall -Wextra -Wvla"],
6666
[WARNFLAGS=""])
6767
AM_CFLAGS="$AM_CFLAGS $WARNFLAGS"
6868
AM_CXXFLAGS="$AM_CXXFLAGS $WARNFLAGS"

src/sst/elements/mask-mpi/mpi_api_type.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Questions? Contact sst-macro-help@sandia.gov
4646
//#include <sumi-mpi/otf2_output_stat.h>
4747
#include <mercury/components/operating_system.h>
4848
#include <climits>
49+
#include <memory>
4950

5051
namespace SST::Hg {
5152
extern void apiLock();
@@ -429,12 +430,12 @@ MpiApi::typeIndexed(int count, const int lens[], const int* displs,
429430
{
430431
MpiType* in_type_obj = typeFromId(intype);
431432
int type_extent = in_type_obj->extent();
432-
MPI_Aint byte_displs[count];
433+
auto byte_displs = std::make_unique<MPI_Aint[]>(count);
433434
for (int i=0; i < count; ++i){
434435
byte_displs[i] = displs[i] * type_extent;
435436
}
436437

437-
int rc = doTypeHindexed(count, lens, byte_displs, in_type_obj, outtype);
438+
int rc = doTypeHindexed(count, lens, byte_displs.get(), in_type_obj, outtype);
438439
#ifdef SST_HG_OTF2_ENABLED
439440
if (OTF2Writer_){
440441
OTF2Writer_->writer().register_type(*outtype, count*in_type_obj->packed_size());
@@ -525,11 +526,11 @@ MpiApi::typeCreateStruct(const int count, const int* blocklens,
525526
const MPI_Aint* indices, const MPI_Datatype* old_types,
526527
MPI_Datatype* newtype)
527528
{
528-
int new_ind[count];
529+
auto new_ind = std::make_unique<int[]>(count);
529530
for (int i=0; i < count; ++i){
530531
new_ind[i] = indices[i];
531532
}
532-
return typeCreateStruct(count, blocklens, new_ind, old_types, newtype);
533+
return typeCreateStruct(count, blocklens, new_ind.get(), old_types, newtype);
533534
}
534535

535536
//

src/sst/elements/mask-mpi/mpi_comm/mpi_comm_cart.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Questions? Contact sst-macro-help@sandia.gov
4545
#include <mpi_comm/mpi_comm_cart.h>
4646
#include <mercury/common/errors.h>
4747

48+
#include <memory>
49+
4850
namespace SST::MASKMPI {
4951

5052
MpiCommCart::MpiCommCart(
@@ -96,26 +98,26 @@ MpiCommCart::shift(int dir, int dis)
9698
"mpicomm_cart::shift: dir %d is too big for dims %d",
9799
dir, dims_.size());
98100
}
99-
int coords[dims_.size()];
100-
set_coords(rank_, coords);
101+
auto coords = std::make_unique<int[]>(dims_.size());
102+
set_coords(rank_, coords.get());
101103
coords[dir] += dis;
102104

103105
if (coords[dir] >= dims_[dir]) {
104106
if (periods_[dir]) {
105107
coords[dir] = coords[dir] % dims_[dir];
106-
return rank(coords);
108+
return rank(coords.get());
107109
} else {
108110
return MpiComm::proc_null;
109111
}
110112
} else if (coords[dir] < 0) {
111113
if (periods_[dir]) {
112114
coords[dir] = (dims_[dir] + coords[dir]) % dims_[dir];
113-
return rank(coords);
115+
return rank(coords.get());
114116
} else {
115117
return MpiComm::proc_null;
116118
}
117119
} else {
118-
return rank(coords);
120+
return rank(coords.get());
119121
}
120122

121123
}

src/sst/elements/zodiac/zsirius.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "zsirius.h"
1919

2020
#include <assert.h>
21+
#include <memory>
2122

2223
#include "sst/core/params.h"
2324

@@ -97,11 +98,11 @@ void ZodiacSiriusTraceReader::setup() {
9798

9899
eventQ = new std::queue<ZodiacEvent*>();
99100

100-
char trace_name[trace_file.length() + 20];
101-
snprintf(trace_name, trace_file.length() + 20, "%s.%d", trace_file.c_str(), rank);
101+
auto trace_name = std::make_unique<char[]>(trace_file.length() + 20);
102+
snprintf(trace_name.get(), trace_file.length() + 20, "%s.%d", trace_file.c_str(), rank);
102103

103-
printf("Opening trace file: %s\n", trace_name);
104-
trace = new SiriusReader(trace_name, rank, 64, eventQ, verbosityLevel);
104+
printf("Opening trace file: %s\n", trace_name.get());
105+
trace = new SiriusReader(trace_name.get(), rank, 64, eventQ, verbosityLevel);
105106
trace->setOutput(&zOut);
106107

107108
int count = trace->generateNextEvents();

0 commit comments

Comments
 (0)