Skip to content

Commit 7800d73

Browse files
committed
Replace variable-length arrays with std::make_unique allocated arrays; add -Wvla
1 parent 0077a83 commit 7800d73

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

configure.ac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ AC_CONFIG_HEADERS([src/sst/core/sst_config.h])
2525
# Lets check for the standard compilers and basic options
2626
AC_PROG_CC
2727
AM_PROG_CC_C_O
28-
m4_if(m4_defn([AC_AUTOCONF_VERSION]), 2.71,, m4_defn([AC_AUTOCONF_VERSION]), 2.70,, [AC_PROG_CC_C99])
28+
m4_if(m4_defn([AC_AUTOCONF_VERSION]), 2.71,, m4_defn([AC_AUTOCONF_VERSION]), 2.70,, [AC_PROG_CC_C99])
2929
AC_C_INLINE
3030
AC_PROG_MAKE_SET
3131

@@ -62,7 +62,7 @@ esac
6262

6363
SST_CHECK_PICKY
6464
AS_IF([test "x$use_picky" = "xyes"],
65-
[WARNFLAGS="-Wall -Wextra"],
65+
[WARNFLAGS="-Wall -Wextra -Wvla"],
6666
[WARNFLAGS=""])
6767
CFLAGS="$CFLAGS $WARNFLAGS"
6868
CXXFLAGS="$CXXFLAGS $WARNFLAGS"

src/sst/core/bootsst.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
#include "sst/core/configShared.h"
1616

1717
#include <cstdlib>
18-
#include <string.h>
18+
#include <cstring>
19+
#include <memory>
1920
#include <unistd.h> // for opterr
2021

2122
int
@@ -31,14 +32,14 @@ main(int argc, char* argv[])
3132
SST::ConfigShared cfg(true, true, true, true);
3233

3334
// Make a copy of the argv array (shallow)
34-
char* argv_copy[argc + 1];
35+
auto argv_copy = std::make_unique<char*[]>(argc + 1);
3536
for ( int i = 0; i < argc; ++i ) {
3637
argv_copy[i] = argv[i];
3738
}
3839
argv[argc] = nullptr;
3940

4041
// All ranks parse the command line
41-
cfg.parseCmdLine(argc, argv_copy);
42+
cfg.parseCmdLine(argc, argv_copy.get());
4243

4344
if ( cfg.no_env_config() ) config_env = 0;
4445
if ( cfg.verbose() ) verbose = 1;

src/sst/core/bootsstinfo.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#include "sst/core/bootshared.h"
1515
#include "sst/core/configShared.h"
1616

17+
#include <cstdio>
18+
#include <memory>
19+
1720
int
1821
main(int argc, char* argv[])
1922
{
@@ -26,13 +29,13 @@ main(int argc, char* argv[])
2629
SST::ConfigShared cfg(true, true, true, true);
2730

2831
// Make a copy of the argv array (shallow)
29-
char* argv_copy[argc + 1];
32+
auto argv_copy = std::make_unique<char*[]>(argc + 1);
3033
for ( int i = 0; i < argc; ++i ) {
3134
argv_copy[i] = argv[i];
3235
}
3336
argv[argc] = nullptr;
3437

35-
cfg.parseCmdLine(argc, argv_copy, true);
38+
cfg.parseCmdLine(argc, argv_copy.get(), true);
3639

3740
if ( cfg.no_env_config() ) config_env = false;
3841

src/sst/core/configBase.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <cstdlib>
2121
#include <getopt.h>
2222
#include <iostream>
23+
#include <memory>
2324
#include <string>
2425
#include <sys/ioctl.h>
2526
#include <sys/stat.h>
@@ -317,13 +318,13 @@ ConfigBase::parseCmdLine(int argc, char* argv[], bool ignore_unknown)
317318
// Turn off printing of errors in getopt_long
318319
opterr = 0;
319320
}
320-
struct option sst_long_options[num_options + 2];
321+
auto sst_long_options = std::make_unique<option[]>(num_options + 2);
321322

322323
// Because a zero index can mean two different things, we put in a
323324
// dummy so we don't ever get a zero index
324325
sst_long_options[0] = { "*DUMMY_ARGUMENT*", no_argument, nullptr, 0 };
325-
int option_map[num_options + 1];
326-
option_map[0] = 0;
326+
auto option_map = std::make_unique<int[]>(num_options + 1);
327+
option_map[0] = 0;
327328
{
328329
int count = 1;
329330

@@ -359,7 +360,8 @@ ConfigBase::parseCmdLine(int argc, char* argv[], bool ignore_unknown)
359360
int status = 0;
360361
while ( 0 == status ) {
361362
int option_index = 0;
362-
const int intC = getopt_long(my_argc, argv, short_options_string.c_str(), sst_long_options, &option_index);
363+
const int intC =
364+
getopt_long(my_argc, argv, short_options_string.c_str(), sst_long_options.get(), &option_index);
363365

364366
if ( intC == -1 ) /* We're done */
365367
break;

src/sst/core/impl/partitioners/simplepart.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "sst/core/warnmacros.h"
1818

1919
#include <map>
20+
#include <memory>
2021
#include <stdlib.h>
2122
#include <vector>
2223

@@ -192,8 +193,8 @@ SimplePartitioner::performPartition(PartitionGraph* graph)
192193
graph->getNumComponents() % 2 == 1 ? (graph->getNumComponents() / 2) + 1 : (graph->getNumComponents() / 2);
193194
const int B_size = graph->getNumComponents() / 2;
194195

195-
ComponentId_t setA[A_size];
196-
ComponentId_t setB[B_size];
196+
auto setA = std::make_unique<ComponentId_t[]>(A_size);
197+
auto setB = std::make_unique<ComponentId_t[]>(B_size);
197198

198199
int indexA = 0;
199200
int indexB = 0;
@@ -229,7 +230,7 @@ SimplePartitioner::performPartition(PartitionGraph* graph)
229230
}
230231
}
231232

232-
simple_partition_step(component_map, setA, A_size, 0, setB, B_size, 1, timeTable, 1);
233+
simple_partition_step(component_map, setA.get(), A_size, 0, setB.get(), B_size, 1, timeTable, 1);
233234
}
234235
}
235236

0 commit comments

Comments
 (0)