Skip to content

Commit 5d98be6

Browse files
committed
Address coverity and clang-tidy recommendations
1 parent 2b54abc commit 5d98be6

36 files changed

+222
-187
lines changed

packages/seacas/applications/conjoin/CJ_ExodusFile.C

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ bool Excn::ExodusFile::initialize(const SystemInterface &si)
112112
}
113113

114114
float version = 0.0;
115-
int overall_max_name_length = 32;
115+
int64_t overall_max_name_length = 32;
116116

117117
if (si.inputFiles_.size() == 1) {
118118
// The file should contain multiple change sets which will be concatenated...
@@ -125,7 +125,7 @@ bool Excn::ExodusFile::initialize(const SystemInterface &si)
125125
return false;
126126
}
127127

128-
int num_change_sets = ex_inquire_int(exoid, EX_INQ_NUM_CHILD_GROUPS);
128+
auto num_change_sets = ex_inquire_int(exoid, EX_INQ_NUM_CHILD_GROUPS);
129129
if (num_change_sets > 1) {
130130
usingChangeSets_ = true;
131131

@@ -140,7 +140,7 @@ bool Excn::ExodusFile::initialize(const SystemInterface &si)
140140
exodusMode_ = EX_ALL_INT64_API;
141141
}
142142

143-
int name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_USED_NAME_LENGTH);
143+
auto name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_USED_NAME_LENGTH);
144144
if (name_length > overall_max_name_length) {
145145
overall_max_name_length = name_length;
146146
}
@@ -150,8 +150,8 @@ bool Excn::ExodusFile::initialize(const SystemInterface &si)
150150
fileids_.resize(num_change_sets, exoid);
151151

152152
// Get names of change sets...
153-
int group_name_length = ex_inquire_int(exoid, EX_INQ_GROUP_NAME_LEN);
154-
group_name_length = std::max(32, group_name_length);
153+
auto group_name_length = ex_inquire_int(exoid, EX_INQ_GROUP_NAME_LEN);
154+
group_name_length = std::max(int64_t(32), group_name_length);
155155
std::vector<char> group_name(group_name_length + 1, '\0');
156156

157157
for (int i = 1; i <= num_change_sets; i++) {
@@ -189,7 +189,7 @@ bool Excn::ExodusFile::initialize(const SystemInterface &si)
189189
return false;
190190
}
191191

192-
int name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_USED_NAME_LENGTH);
192+
auto name_length = ex_inquire_int(exoid, EX_INQ_DB_MAX_USED_NAME_LENGTH);
193193
if (name_length > overall_max_name_length) {
194194
overall_max_name_length = name_length;
195195
}
@@ -217,7 +217,7 @@ bool Excn::ExodusFile::initialize(const SystemInterface &si)
217217
fmt::print(stderr, "ERROR: Cannot open file '{}'\n", filenames_[p]);
218218
return false;
219219
}
220-
int num_change_sets = ex_inquire_int(fileids_[p], EX_INQ_NUM_CHILD_GROUPS);
220+
auto num_change_sets = ex_inquire_int(fileids_[p], EX_INQ_NUM_CHILD_GROUPS);
221221
if (num_change_sets > 1) {
222222
fmt::print(stderr,
223223
"ERROR: Cannot (yet) handle multiple input files containing change "

packages/seacas/applications/conjoin/CJ_Internals.C

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright(C) 1999-, 20242024 National Technology & Engineering Solutions
2+
* Copyright(C) 1999-, 20242024, National Technology & Engineering Solutions
33
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
44
* NTESS, the U.S. Government retains certain rights in this software.
55
*
@@ -977,7 +977,7 @@ namespace {
977977
int id_type = get_type(exoid, EX_IDS_INT64_API);
978978

979979
if (id_type == NC_INT64) {
980-
status = nc_put_var_longlong(exoid, var_id, (long long int *)Data(ids));
980+
status = nc_put_var_longlong(exoid, var_id, Data(ids));
981981
}
982982
else {
983983
// Have entity_id (long long), need ints...

packages/seacas/applications/conjoin/CJ_SystemInterface.C

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright(C) 1999-2024 National Technology & Engineering Solutions
1+
// Copyright(C) 1999-2025 National Technology & Engineering Solutions
22
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
33
// NTESS, the U.S. Government retains certain rights in this software.
44
//
@@ -11,7 +11,7 @@
1111
#include <cctype> // for tolower
1212
#include <copyright.h>
1313
#include <cstddef> // for size_t
14-
#include <cstdlib> // for exit, strtol, EXIT_SUCCESS, etc
14+
#include <cstdlib> // for exit, EXIT_SUCCESS, etc
1515
#include <fmt/format.h>
1616
#include <term_width.h>
1717
#include <utility> // for pair, make_pair
@@ -184,7 +184,7 @@ bool Excn::SystemInterface::parse_options(int argc, char **argv)
184184
{
185185
const char *temp = options_.retrieve("alive_value");
186186
if (temp != nullptr) {
187-
int value = strtol(temp, nullptr, 10);
187+
int value = std::stoi(temp);
188188
if (value == 1 || value == 0) {
189189
aliveValue_ = value;
190190
}
@@ -264,7 +264,7 @@ bool Excn::SystemInterface::parse_options(int argc, char **argv)
264264
{
265265
const char *temp = options_.retrieve("compress");
266266
if (temp != nullptr) {
267-
compressionLevel_ = std::strtol(temp, nullptr, 10);
267+
compressionLevel_ = std::stoi(temp);
268268
if (!szip_ && !zlib_ && !zstd_ && !bz2_) {
269269
zlib_ = true;
270270
}
@@ -300,7 +300,7 @@ bool Excn::SystemInterface::parse_options(int argc, char **argv)
300300
{
301301
const char *temp = options_.retrieve("quantize_nsd");
302302
if (temp != nullptr) {
303-
quantizeNSD_ = std::strtol(temp, nullptr, 10);
303+
quantizeNSD_ = std::stoi(temp);
304304
if (!szip_ && !zlib_ && !zstd_ && !bz2_) {
305305
zlib_ = true;
306306
}

packages/seacas/applications/conjoin/Conjoin.C

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ namespace {
281281
std::vector<std::vector<Excn::NodeSet<INT>>> &nodesets,
282282
std::vector<std::vector<Excn::SideSet<INT>>> &sidesets);
283283

284-
bool case_compare(const std::string &s1, const std::string &s2);
284+
bool case_compare(std::string_view s1, std::string_view s2);
285285

286286
template <typename T>
287287
void verify_set_position_mapping(const std::string &type, size_t part_count,
@@ -2532,7 +2532,7 @@ namespace {
25322532
const_cast<INT *>(&glob_sset.sides[0]));
25332533
if (glob_sset.dfCount > 0) {
25342534
ex_put_set_dist_fact(exoid, EX_SIDE_SET, glob_sset.id,
2535-
reinterpret_cast<void *>(Data(glob_sset.distFactors)));
2535+
static_cast<void *>(Data(glob_sset.distFactors)));
25362536
}
25372537
}
25382538

@@ -2762,7 +2762,7 @@ namespace {
27622762
}
27632763
}
27642764

2765-
bool case_compare(const std::string &s1, const std::string &s2)
2765+
bool case_compare(std::string_view s1, std::string_view s2)
27662766
{
27672767
return (s1.size() == s2.size()) &&
27682768
std::equal(s1.begin(), s1.end(), s2.begin(),

packages/seacas/applications/cpup/CP_SystemInterface.C

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright(C) 1999-2024 National Technology & Engineering Solutions
2+
* Copyright(C) 1999-2025 National Technology & Engineering Solutions
33
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
44
* NTESS, the U.S. Government retains certain rights in this software.
55
*
@@ -474,7 +474,7 @@ void Cpup::SystemInterface::parse_step_option(const char *tokens)
474474

475475
tmp_str[k] = '\0';
476476
if (strlen(tmp_str) > 0) {
477-
val = strtol(tmp_str, nullptr, 0);
477+
val = std::stoi(tmp_str);
478478
}
479479

480480
if (tokens[j++] == '\0') {
@@ -490,7 +490,7 @@ void Cpup::SystemInterface::parse_step_option(const char *tokens)
490490
}
491491
else {
492492
// Does not contain a separator, min == max
493-
stepMin_ = stepMax_ = strtol(tokens, nullptr, 0);
493+
stepMin_ = stepMax_ = std::stoi(tokens);
494494
}
495495
}
496496
}

packages/seacas/applications/ejoin/EJoin.C

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,25 @@
4545
#endif
4646

4747
namespace {
48-
std::string tsFormat = "[%H:%M:%S] ";
48+
const std::string tsFormat = "[%H:%M:%S] ";
4949
unsigned int debug_level = 0;
5050

5151
bool valid_variable(const std::string &variable, size_t id, const StringIdVector &variable_list);
5252
bool check_variable_mismatch(const std::string &type, const StringIdVector &variable_list,
5353
const Ioss::NameList &fields);
5454

55-
bool define_global_fields(Ioss::Region &output_region, RegionVector &part_mesh,
55+
bool define_global_fields(Ioss::Region &output_region, const RegionVector &part_mesh,
5656
const StringIdVector &variable_list);
57-
bool define_nodal_fields(Ioss::Region &output_region, RegionVector &part_mesh,
58-
const StringIdVector &variable_list, SystemInterface &interFace);
59-
bool define_element_fields(Ioss::Region &output_region, RegionVector &part_mesh,
57+
bool define_nodal_fields(const Ioss::Region &output_region, const RegionVector &part_mesh,
58+
const StringIdVector &variable_list, const SystemInterface &interFace);
59+
bool define_element_fields(const Ioss::Region &output_region, const RegionVector &part_mesh,
6060
const StringIdVector &variable_list);
61-
bool define_nset_fields(Ioss::Region &output_region, RegionVector &part_mesh,
61+
bool define_nset_fields(const Ioss::Region &output_region, const RegionVector &part_mesh,
6262
const StringIdVector &variable_list);
63-
bool define_sset_fields(Ioss::Region &output_region, RegionVector &part_mesh,
63+
bool define_sset_fields(const Ioss::Region &output_region, const RegionVector &part_mesh,
6464
const StringIdVector &variable_list);
65-
void define_nodal_nodeset_fields(Ioss::Region &output_region, RegionVector &part_mesh,
66-
const StringIdVector &variable_list, SystemInterface &interFace);
65+
void define_nodal_nodeset_fields(const Ioss::Region &output_region, const RegionVector &part_mesh,
66+
const StringIdVector &variable_list, const SystemInterface &interFace);
6767

6868
template <typename INT>
6969
void output_nodeblock(Ioss::Region &output_region, RegionVector &part_mesh,
@@ -127,12 +127,12 @@ namespace {
127127
}
128128
}
129129

130-
void transfer_elementblock(Ioss::Region &region, Ioss::Region &output_region,
130+
void transfer_elementblock(const Ioss::Region &region, Ioss::Region &output_region,
131131
bool create_assemblies, bool debug);
132132
void transfer_assembly(const Ioss::Region &region, Ioss::Region &output_region, bool debug);
133-
void transfer_nodesets(Ioss::Region &region, Ioss::Region &output_region, bool debug);
134-
void transfer_sidesets(Ioss::Region &region, Ioss::Region &output_region, bool debug);
135-
void create_nodal_nodeset(Ioss::Region &region, Ioss::Region &output_region, bool debug);
133+
void transfer_nodesets(const Ioss::Region &region, Ioss::Region &output_region, bool debug);
134+
void transfer_sidesets(const Ioss::Region &region, Ioss::Region &output_region, bool debug);
135+
void create_nodal_nodeset(const Ioss::Region &region, Ioss::Region &output_region, bool debug);
136136
void transfer_fields(Ioss::GroupingEntity *ige, Ioss::GroupingEntity *oge,
137137
Ioss::Field::RoleType role, const std::string &prefix = "");
138138

@@ -609,7 +609,7 @@ namespace {
609609
return omitted;
610610
}
611611

612-
void transfer_elementblock(Ioss::Region &region, Ioss::Region &output_region,
612+
void transfer_elementblock(const Ioss::Region &region, Ioss::Region &output_region,
613613
bool create_assemblies, bool debug)
614614
{
615615
static int used_blocks = 0;
@@ -708,7 +708,7 @@ namespace {
708708
}
709709
}
710710

711-
void transfer_sidesets(Ioss::Region &region, Ioss::Region &output_region, bool debug)
711+
void transfer_sidesets(const Ioss::Region &region, Ioss::Region &output_region, bool debug)
712712
{
713713
const std::string &prefix = region.name();
714714

@@ -752,7 +752,7 @@ namespace {
752752

753753
// Create a nodeset on the output region consisting of all the nodes
754754
// in the input region.
755-
void create_nodal_nodeset(Ioss::Region &region, Ioss::Region &output_region, bool debug)
755+
void create_nodal_nodeset(const Ioss::Region &region, Ioss::Region &output_region, bool debug)
756756
{
757757
const std::string &prefix = region.name();
758758

@@ -805,8 +805,8 @@ namespace {
805805
}
806806
}
807807

808-
void define_nodal_nodeset_fields(Ioss::Region &output_region, RegionVector &part_mesh,
809-
const StringIdVector &variable_list, SystemInterface &interFace)
808+
void define_nodal_nodeset_fields(const Ioss::Region &output_region, const RegionVector &part_mesh,
809+
const StringIdVector &variable_list, const SystemInterface &interFace)
810810
{
811811
// This routine does not check that all variables in `variable_list` have been
812812
// found since the checking has already been done in define_nodal_fields.
@@ -839,7 +839,7 @@ namespace {
839839
}
840840
}
841841

842-
void transfer_nodesets(Ioss::Region &region, Ioss::Region &output_region, bool debug)
842+
void transfer_nodesets(const Ioss::Region &region, Ioss::Region &output_region, bool debug)
843843
{
844844
bool combine_similar = false;
845845
const std::string &prefix = region.name();
@@ -1376,7 +1376,7 @@ namespace {
13761376
oge->put_field_data(field_name, data);
13771377
}
13781378

1379-
bool define_global_fields(Ioss::Region &output_region, RegionVector &part_mesh,
1379+
bool define_global_fields(Ioss::Region &output_region, const RegionVector &part_mesh,
13801380
const StringIdVector &variable_list)
13811381
{
13821382
bool error = false;
@@ -1403,8 +1403,8 @@ namespace {
14031403
return error;
14041404
}
14051405

1406-
bool define_nodal_fields(Ioss::Region &output_region, RegionVector &part_mesh,
1407-
const StringIdVector &variable_list, SystemInterface &interFace)
1406+
bool define_nodal_fields(const Ioss::Region &output_region, const RegionVector &part_mesh,
1407+
const StringIdVector &variable_list, const SystemInterface &interFace)
14081408
{
14091409
bool error = false;
14101410
if (!variable_list.empty() && variable_list[0].first == "none") {
@@ -1439,7 +1439,7 @@ namespace {
14391439
return error;
14401440
}
14411441

1442-
bool define_element_fields(Ioss::Region &output_region, RegionVector &part_mesh,
1442+
bool define_element_fields(const Ioss::Region &output_region, const RegionVector &part_mesh,
14431443
const StringIdVector &variable_list)
14441444
{
14451445
bool error = false;
@@ -1487,7 +1487,7 @@ namespace {
14871487
return error;
14881488
}
14891489

1490-
bool define_nset_fields(Ioss::Region &output_region, RegionVector &part_mesh,
1490+
bool define_nset_fields(const Ioss::Region &output_region, const RegionVector &part_mesh,
14911491
const StringIdVector &variable_list)
14921492
{
14931493
bool error = false;
@@ -1536,7 +1536,7 @@ namespace {
15361536
return error;
15371537
}
15381538

1539-
bool define_sset_fields(Ioss::Region &output_region, RegionVector &part_mesh,
1539+
bool define_sset_fields(const Ioss::Region &output_region, const RegionVector &part_mesh,
15401540
const StringIdVector &variable_list)
15411541
{
15421542
bool error = false;
@@ -1622,9 +1622,9 @@ namespace {
16221622
return false;
16231623
}
16241624

1625-
for (const auto &var : variable_list) {
1626-
if (var.first == variable) {
1627-
if (id == 0 || id == var.second || var.second == 0) {
1625+
for (const auto & [var_name, var_id] : variable_list) {
1626+
if (var_name == variable) {
1627+
if (id == 0 || id == var_id || var_id == 0) {
16281628
return true;
16291629
}
16301630
}

packages/seacas/applications/epu/EP_ExodusFile.C

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ void Excn::ExodusFile::initialize(const SystemInterface &si, int start_part, int
228228
activeChangeSet_ = si.selected_change_set();
229229
if (si.selected_change_set() > 0) {
230230
onlySelectedChangeSet_ = true;
231-
;
232231
}
233232

234233
// EPU always wants entity (block, set, map) ids as 64-bit quantities...

packages/seacas/applications/exo2mat/exo2mat.C

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ namespace {
6969

7070
void usage()
7171
{
72-
const auto *v5default = MAT_FT_DEFAULT == MAT_FT_MAT5 ? "[default]" : "";
73-
const auto *v7default = MAT_FT_DEFAULT == MAT_FT_MAT73 ? "[default]" : "";
72+
const auto *v5default = (MAT_FT_DEFAULT == MAT_FT_MAT5 ? "[default]" : "");
73+
const auto *v7default = (MAT_FT_DEFAULT == MAT_FT_MAT73 ? "[default]" : "");
7474
fmt::print("exo2mat [options] exodus_file_name.\n"
7575
" the exodus_file_name is required (exodus only).\n"
7676
" Options:\n"
@@ -79,11 +79,11 @@ namespace {
7979
" -c use cell arrays for transient variables.\n"
8080
" -v5 output version 5 mat file {}\n"
8181
" -v73 output version 7.3 mat file (hdf5-based) {}\n"
82-
" -v7.3 output version 7.3 mat file (hdf5-based)\n"
82+
" -v7.3 output version 7.3 mat file (hdf5-based) {}\n"
8383
" -change_set cs_# Read from change set #.\n"
8484
" ** note **\n"
8585
"Binary files are written by default on all platforms.\n",
86-
v5default, v7default);
86+
v5default, v7default, v7default);
8787
}
8888

8989
/* put a string into an m file. If the string has

0 commit comments

Comments
 (0)