From 7b1dcc26bd29a8997c7f8220edfaba5fb486071b Mon Sep 17 00:00:00 2001 From: Greg Sjaardema Date: Mon, 18 Sep 2023 08:46:31 -0600 Subject: [PATCH] Address codacy issues --- .../seacas/applications/ejoin/EJ_mapping.C | 5 +++-- packages/seacas/applications/ejoin/EJoin.C | 4 ++-- .../seacas/applications/exodiff/create_file.C | 1 - .../seacas/applications/exodiff/exo_entity.C | 3 --- .../applications/nem_spread/ps_restart.C | 20 ++++--------------- .../libraries/exodus/src/ex_put_num_map.c | 2 +- .../seacas/libraries/ioss/src/Ioss_Compare.C | 10 +++------- .../libraries/ioss/src/exodus/Ioex_Utils.C | 11 +++++++--- .../libraries/ioss/src/exonull/Ioexnl_Utils.C | 6 +++--- .../seacas/libraries/ioss/src/main/io_info.C | 3 +-- 10 files changed, 25 insertions(+), 40 deletions(-) diff --git a/packages/seacas/applications/ejoin/EJ_mapping.C b/packages/seacas/applications/ejoin/EJ_mapping.C index 0feb37494d..e19268b630 100644 --- a/packages/seacas/applications/ejoin/EJ_mapping.C +++ b/packages/seacas/applications/ejoin/EJ_mapping.C @@ -162,8 +162,9 @@ void build_reverse_node_map(Ioss::Region & /*global*/, RegionVector &part_mesh, if (cur_pos == global_node_map.end() || *cur_pos != global_node) { auto iter = std::lower_bound(global_node_map.begin(), global_node_map.end(), global_node); if (iter == global_node_map.end()) { - fmt::print("{}\n", fmt::group_digits(global_node)); - SMART_ASSERT(iter != global_node_map.end()); + fmt::print(stderr, "ERROR: Could not find global node {} in global node map.\n", + fmt::group_digits(global_node)); + exit(EXIT_FAILURE); } cur_pos = iter; } diff --git a/packages/seacas/applications/ejoin/EJoin.C b/packages/seacas/applications/ejoin/EJoin.C index 1a19581107..7d1e18f97a 100644 --- a/packages/seacas/applications/ejoin/EJoin.C +++ b/packages/seacas/applications/ejoin/EJoin.C @@ -501,8 +501,8 @@ double ejoin(SystemInterface &interFace, std::vector &part_mesh, } else { if (global_times.size() != times.size()) { - fmt::print(stderr, "ERROR: Time step sizes must match."); - SMART_ASSERT(global_times.size() == times.size())(global_times.size())(times.size())(p); + fmt::print(stderr, "ERROR: Time step sizes must match. (Global = {}, Part {} = {}", + global_times.size(), p, times.size()); exit(EXIT_FAILURE); } diff --git a/packages/seacas/applications/exodiff/create_file.C b/packages/seacas/applications/exodiff/create_file.C index 081f6f940c..19ddb039fe 100644 --- a/packages/seacas/applications/exodiff/create_file.C +++ b/packages/seacas/applications/exodiff/create_file.C @@ -267,7 +267,6 @@ namespace { std::vector vars(names.size()); for (unsigned i = 0; i < names.size(); ++i) { vars[i] = const_cast(names[i].c_str()); - SMART_ASSERT(vars[i] != nullptr); } ex_put_variable_names(file_id, type, names.size(), vars.data()); } diff --git a/packages/seacas/applications/exodiff/exo_entity.C b/packages/seacas/applications/exodiff/exo_entity.C index 9a06e490d5..f005bf6798 100644 --- a/packages/seacas/applications/exodiff/exo_entity.C +++ b/packages/seacas/applications/exodiff/exo_entity.C @@ -73,7 +73,6 @@ bool Exo_Entity::is_valid_var(size_t var_index) const SMART_ASSERT((int)var_index < numVars); if (truth_ == nullptr) { get_truth_table(); - SMART_ASSERT(truth_ != nullptr); } return (truth_[var_index] != 0); @@ -101,7 +100,6 @@ std::string Exo_Entity::Load_Results(int time_step, int var_index) if (truth_ == nullptr) { get_truth_table(); - SMART_ASSERT(truth_ != nullptr); } if (truth_[var_index] != 0) { @@ -158,7 +156,6 @@ std::string Exo_Entity::Load_Results(int t1, int t2, double proportion, int var_ if (truth_ == nullptr) { get_truth_table(); - SMART_ASSERT(truth_ != nullptr); } if (truth_[var_index] != 0) { diff --git a/packages/seacas/applications/nem_spread/ps_restart.C b/packages/seacas/applications/nem_spread/ps_restart.C index 2d6312f677..0924cd8720 100644 --- a/packages/seacas/applications/nem_spread/ps_restart.C +++ b/packages/seacas/applications/nem_spread/ps_restart.C @@ -632,34 +632,22 @@ int NemSpread::read_vars(int exoid, int index, INT *eb_ids, INT *eb_cnts if (Restart_Info.NVar_Elem > 0) { fmt::print("Reading {} element variables...\n", Restart_Info.NVar_Elem); - if (read_elem_vars(exoid, index, eb_ids, eb_cnts, eb_map_ptr, eb_cnts_local) < 0) { - fmt::print(stderr, "{}: Error distributing elemental variables.\n", __func__); - return -1; - } + read_elem_vars(exoid, index, eb_ids, eb_cnts, eb_map_ptr, eb_cnts_local); } if (Restart_Info.NVar_Node > 0) { fmt::print("Reading {} nodal variables...\n", Restart_Info.NVar_Node); - if (read_nodal_vars(exoid, index) < 0) { - fmt::print(stderr, "{}: Error distributing nodal variables.\n", __func__); - return -1; - } + read_nodal_vars(exoid, index); } if (Restart_Info.NVar_Sset > 0) { fmt::print("Reading {} sideset variables...\n", Restart_Info.NVar_Sset); - if (read_sset_vars(exoid, index, ss_ids, ss_cnts) < 0) { - fmt::print(stderr, "{}: Error distributing sideset variables.\n", __func__); - return -1; - } + read_sset_vars(exoid, index, ss_ids, ss_cnts); } if (Restart_Info.NVar_Nset > 0) { fmt::print("Reading {} nodeset variables...\n", Restart_Info.NVar_Nset); - if (read_nset_vars(exoid, index, ns_ids, ns_cnts) < 0) { - fmt::print(stderr, "{}: Error distributing nodeset variables.\n", __func__); - return -1; - } + read_nset_vars(exoid, index, ns_ids, ns_cnts); } return 0; diff --git a/packages/seacas/libraries/exodus/src/ex_put_num_map.c b/packages/seacas/libraries/exodus/src/ex_put_num_map.c index 92dac8ebf1..f87ef7147a 100644 --- a/packages/seacas/libraries/exodus/src/ex_put_num_map.c +++ b/packages/seacas/libraries/exodus/src/ex_put_num_map.c @@ -117,7 +117,6 @@ int ex_put_num_map(int exoid, ex_entity_type map_type, ex_entity_id map_id, cons ex_err_fn(exoid, __func__, errmsg, status); EX_FUNC_LEAVE(EX_FATAL); } - int num_maps = num_entries; /* Keep track of the total number of maps defined using a counter stored in a linked list keyed by exoid. @@ -125,6 +124,7 @@ int ex_put_num_map(int exoid, ex_entity_type map_type, ex_entity_id map_id, cons for a specific file and returns that value. */ int cur_num_maps = ex__get_file_item(exoid, ex__get_counter_list(map_type)); + int num_maps = num_entries; if (!overwrite_map) { if (cur_num_maps >= num_maps) { snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: exceeded number of %ss (%d) specified in file id %d", diff --git a/packages/seacas/libraries/ioss/src/Ioss_Compare.C b/packages/seacas/libraries/ioss/src/Ioss_Compare.C index 16048568cf..4b752bfba0 100644 --- a/packages/seacas/libraries/ioss/src/Ioss_Compare.C +++ b/packages/seacas/libraries/ioss/src/Ioss_Compare.C @@ -1182,20 +1182,16 @@ namespace { } template - bool compare_sets(const std::vector &in_sets_1, const std::vector &in_sets_const_2, + bool compare_sets(const std::vector &in_sets_1, const std::vector &in_sets_2, const Ioss::MeshCopyOptions & /* options */, std::ostringstream & /* buf */) { bool overall_result = true; - if (in_sets_1.size() != in_sets_const_2.size()) { - fmt::print(Ioss::WarnOut(), COUNT_MISMATCH, "set", in_sets_1.size(), in_sets_const_2.size()); + if (in_sets_1.size() != in_sets_2.size()) { + fmt::print(Ioss::WarnOut(), COUNT_MISMATCH, "set", in_sets_1.size(), in_sets_2.size()); return false; } - // COPY the const input vector so that we remove elements as they're matched without - // affecting the original data structure. - std::vector in_sets_2 = in_sets_const_2; - if (!in_sets_1.empty()) { for (const auto &in_set_1 : in_sets_1) { const auto &name = in_set_1->name(); diff --git a/packages/seacas/libraries/ioss/src/exodus/Ioex_Utils.C b/packages/seacas/libraries/ioss/src/exodus/Ioex_Utils.C index dd1b31ceae..fb5379b8b3 100644 --- a/packages/seacas/libraries/ioss/src/exodus/Ioex_Utils.C +++ b/packages/seacas/libraries/ioss/src/exodus/Ioex_Utils.C @@ -35,6 +35,11 @@ namespace { return len; } + size_t match(const std::string &name1, const std::string &name2) + { + return match(name1.c_str(), name2.c_str()); + } + template void internal_write_coordinate_frames(int exoid, const Ioss::CoordinateFrameContainer &frames, INT /*dummy*/) @@ -237,7 +242,7 @@ namespace Ioex { const char *s = substring; const char *t = type.c_str(); - SMART_ASSERT(s != nullptr && t != nullptr); + SMART_ASSERT(s != nullptr); while (*s != '\0' && *t != '\0') { if (*s++ != tolower(*t++)) { return false; @@ -409,14 +414,14 @@ namespace Ioex { // VECTOR_3D). If found, it returns the name. // - static char displace[] = "displacement"; + static const std::string displace = "displacement"; size_t max_span = 0; for (const auto &name : fields) { std::string lc_name(name); Ioss::Utils::fixup_name(lc_name); - size_t span = match(lc_name.c_str(), displace); + size_t span = match(lc_name, displace); if (span > max_span) { const Ioss::VariableType *var_type = block->get_field(name).transformed_storage(); int comp_count = var_type->component_count(); diff --git a/packages/seacas/libraries/ioss/src/exonull/Ioexnl_Utils.C b/packages/seacas/libraries/ioss/src/exonull/Ioexnl_Utils.C index 85dcb42c29..871b913cdf 100644 --- a/packages/seacas/libraries/ioss/src/exonull/Ioexnl_Utils.C +++ b/packages/seacas/libraries/ioss/src/exonull/Ioexnl_Utils.C @@ -212,7 +212,7 @@ namespace Ioexnl { const char *s = substring; const char *t = type.c_str(); - SMART_ASSERT(s != nullptr && t != nullptr); + SMART_ASSERT(s != nullptr); while (*s != '\0' && *t != '\0') { if (*s++ != tolower(*t++)) { return false; @@ -384,14 +384,14 @@ namespace Ioexnl { // VECTOR_3D). If found, it returns the name. // - static char displace[] = "displacement"; + static const std::string &displace = "displacement"; size_t max_span = 0; for (const auto &name : fields) { std::string lc_name(name); Ioss::Utils::fixup_name(lc_name); - size_t span = match(lc_name.c_str(), displace); + size_t span = match(lc_name.c_str(), displace.c_str()); if (span > max_span) { const Ioss::VariableType *var_type = block->get_field(name).transformed_storage(); int comp_count = var_type->component_count(); diff --git a/packages/seacas/libraries/ioss/src/main/io_info.C b/packages/seacas/libraries/ioss/src/main/io_info.C index 89d9340ec5..a04ed4aa12 100644 --- a/packages/seacas/libraries/ioss/src/main/io_info.C +++ b/packages/seacas/libraries/ioss/src/main/io_info.C @@ -583,8 +583,6 @@ namespace Ioss { void io_info_set_db_properties(const Info::Interface &interFace, Ioss::DatabaseIO *dbi) { - std::string inpfile = interFace.filename(); - if (dbi == nullptr || !dbi->ok(true)) { std::exit(EXIT_FAILURE); } @@ -605,6 +603,7 @@ namespace Ioss { if (!interFace.groupname().empty()) { bool success = dbi->open_group(interFace.groupname()); if (!success) { + std::string inpfile = interFace.filename(); fmt::print("ERROR: Unable to open group '{}' in file '{}'\n", interFace.groupname(), inpfile); return;