Skip to content

Commit 255d3a9

Browse files
committed
COVERITY: Address issues found by coverity
1 parent 13a708d commit 255d3a9

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

packages/seacas/applications/exodiff/exodiff.C

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright(C) 1999-, 20242024 National Technology & Engineering Solutions
1+
// Copyright(C) 1999-, 20242024, , 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
//
@@ -610,17 +610,24 @@ int main(int argc, char *argv[])
610610

611611
bool diff_flag = false;
612612
bool has_change_sets = false;
613-
if (int_size == 4) {
614-
auto diff_change = exodiff_setup(file1_name, file2_name, int(0));
615-
diff_flag = diff_change.first;
616-
has_change_sets = diff_change.second;
613+
try {
614+
if (int_size == 4) {
615+
auto diff_change = exodiff_setup(file1_name, file2_name, int(0));
616+
diff_flag = diff_change.first;
617+
has_change_sets = diff_change.second;
618+
}
619+
else {
620+
auto diff_change = exodiff_setup(file1_name, file2_name, int64_t(0));
621+
diff_flag = diff_change.first;
622+
has_change_sets = diff_change.second;
623+
}
617624
}
618-
else {
619-
auto diff_change = exodiff_setup(file1_name, file2_name, int64_t(0));
620-
diff_flag = diff_change.first;
621-
has_change_sets = diff_change.second;
625+
catch (std::exception &e) {
626+
fmt::print(stderr, "\n{}\n\nEXODIFF terminated due to exception\n", e.what());
627+
exit(EXIT_FAILURE);
622628
}
623629

630+
624631
if (has_change_sets) {
625632
if (diff_flag) {
626633
DIFF_OUT("exodiff: At least one change set is different\n");

packages/seacas/libraries/ioss/src/Ioss_ChangeSetFactory.C

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright(C) 2024 National Technology & Engineering Solutions
1+
// Copyright(C) 2024, 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
//
@@ -63,8 +63,11 @@ std::shared_ptr<Ioss::ChangeSet> Ioss::ChangeSetFactory::create(Ioss::Region *re
6363
" Was Ioss::Init::Initializer() called?\n\n");
6464
IOSS_ERROR(errmsg);
6565
}
66-
else {
67-
iter = registry()->find("ioss");
66+
iter = registry()->find("ioss");
67+
if (iter == registry()->end()) {
68+
std::ostringstream errmsg;
69+
fmt::print(errmsg, "ERROR: Could not locate correct change set types.\n\n");
70+
IOSS_ERROR(errmsg);
6871
}
6972
}
7073

@@ -89,8 +92,11 @@ std::shared_ptr<Ioss::ChangeSet> Ioss::ChangeSetFactory::create(Ioss::DatabaseIO
8992
" Was Ioss::Init::Initializer() called?\n\n");
9093
IOSS_ERROR(errmsg);
9194
}
92-
else {
93-
iter = registry()->find("ioss");
95+
iter = registry()->find("ioss");
96+
if (iter == registry()->end()) {
97+
std::ostringstream errmsg;
98+
fmt::print(errmsg, "ERROR: Could not locate correct change set types.\n\n");
99+
IOSS_ERROR(errmsg);
94100
}
95101
}
96102

packages/seacas/libraries/ioss/src/Ioss_DynamicTopologyFileControl.C

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright(C) 2024 National Technology & Engineering Solutions
1+
// Copyright(C) 2024, 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
//
@@ -92,16 +92,19 @@ namespace {
9292
namespace Ioss {
9393

9494
DynamicTopologyFileControl::DynamicTopologyFileControl(Region *region)
95-
: m_region(region), m_fileCyclicCount(region->get_file_cyclic_count()),
96-
m_ifDatabaseExists(region->get_if_database_exists_behavior()),
97-
m_dbChangeCount(region->get_topology_change_count())
95+
: m_region(region)
9896
{
9997
if (nullptr == region) {
10098
std::ostringstream errmsg;
10199
fmt::print(errmsg, "ERROR: null region passed in as argument to DynamicTopologyFileControl");
102100
IOSS_ERROR(errmsg);
103101
}
104102

103+
// If we are checking for `region == nullptr` above, we cannot
104+
// do these initializations above and must do them here...
105+
m_fileCyclicCount = region->get_file_cyclic_count();
106+
m_ifDatabaseExists = region->get_if_database_exists_behavior();
107+
m_dbChangeCount = region->get_topology_change_count();
105108
m_ioDB = region->get_property("base_filename").get_string();
106109
m_dbType = region->get_property("database_type").get_string();
107110
}

0 commit comments

Comments
 (0)