Skip to content

Commit

Permalink
Static analyzer fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gsjaardema committed Jan 4, 2024
1 parent fe96b10 commit 10b907e
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 141 deletions.
195 changes: 98 additions & 97 deletions packages/seacas/applications/conjoin/Conjoin.C
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(C) 1999-2023 National Technology & Engineering Solutions
// Copyright(C) 1999-2024 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
Expand Down Expand Up @@ -53,7 +53,7 @@
#include "CJ_Version.h"

namespace {
bool check_variable_params(size_t p, Excn::Variables &vars);
bool check_variable_params(size_t p, const Excn::Variables &vars);
template <typename T> void clear(std::vector<T> &vec)
{
vec.clear();
Expand Down Expand Up @@ -290,19 +290,19 @@ namespace {
bool problem = false;
for (size_t p = 0; p < part_count; p++) {
for (size_t i = 0; i < sets[p].size(); i++) {
if (sets[p][i].id == 0) {
continue;
}
auto glob_pos = sets[p][i].position_;
if (sets[p][i].id == 0) {
continue;
}
auto glob_pos = sets[p][i].position_;
if (global_sets[glob_pos].id != sets[p][i].id ||
case_compare(global_sets[glob_pos].name_, sets[p][i].name_) != 0) {
problem = true;
fmt::print(stderr,
"\nERROR: {0} Mismatch on part {1}:\n"
"\tpart {0} at position {2} has id {3} and name {4}\n"
"\tglobal {0} at position {5} has id {6} and name {7}\n",
type, p+1, i, sets[p][i].id, sets[p][i].name_,
glob_pos, global_sets[glob_pos].id, global_sets[glob_pos].name_);
"\tpart {0} at position {2} has id {3} and name {4}\n"
"\tglobal {0} at position {5} has id {6} and name {7}\n",
type, p + 1, i, sets[p][i].id, sets[p][i].name_, glob_pos,
global_sets[glob_pos].id, global_sets[glob_pos].name_);
global_sets[glob_pos].dump();
sets[p][i].dump();
}
Expand Down Expand Up @@ -2024,7 +2024,7 @@ namespace {
}
}

bool check_variable_params(size_t p, Excn::Variables &vars)
bool check_variable_params(size_t p, const Excn::Variables &vars)
{
// Determines the number of variables of type 'type()' that will
// be written to the output database. The 'variable_list' vector
Expand Down Expand Up @@ -2372,7 +2372,7 @@ namespace {
}
}
SMART_ASSERT(gi != gsset_size);
sets[p][i].position_ = gi;
sets[p][i].position_ = gi;

// Get the parameters for this sideset...
ex_set set{};
Expand Down Expand Up @@ -2422,23 +2422,26 @@ namespace {
size_t offset = 0;

for (size_t p = 0; p < part_count; p++) {
for (size_t lss = 0; lss < sets[p].size(); lss++) {
if (sets[p][lss].position_ == ss) {
Excn::ExodusFile id(p);
sets[p][lss].elems.resize(sets[p][lss].sideCount);
sets[p][lss].sides.resize(sets[p][lss].sideCount);
ex_get_set(id, EX_SIDE_SET, ss_id, sets[p][lss].elems.data(), sets[p][lss].sides.data());

// Add these to the elem_side vector...
for (size_t i = 0; i < sets[p][lss].sideCount; i++) {
size_t global_elem = local_mesh[p].localElementToGlobal[sets[p][lss].elems[i] - 1] + 1;
elem_side[offset + i] = std::make_pair((INT)global_elem, (INT)sets[p][lss].sides[i]);
}
offset += sets[p][lss].sideCount;
break;
}
}
}
for (size_t lss = 0; lss < sets[p].size(); lss++) {
if (sets[p][lss].position_ == ss) {
Excn::ExodusFile id(p);
sets[p][lss].elems.resize(sets[p][lss].sideCount);
sets[p][lss].sides.resize(sets[p][lss].sideCount);
ex_get_set(id, EX_SIDE_SET, ss_id, sets[p][lss].elems.data(),
sets[p][lss].sides.data());

// Add these to the elem_side vector...
for (size_t i = 0; i < sets[p][lss].sideCount; i++) {
size_t global_elem =
local_mesh[p].localElementToGlobal[sets[p][lss].elems[i] - 1] + 1;
elem_side[offset + i] =
std::make_pair((INT)global_elem, (INT)sets[p][lss].sides[i]);
}
offset += sets[p][lss].sideCount;
break;
}
}
}

uniquify(elem_side);

Expand All @@ -2461,21 +2464,22 @@ namespace {
// Try the lower_bound searching of elem_side for now. If
// inefficient, fix later...
for (size_t p = 0; p < part_count; p++) {
for (size_t lss = 0; lss < sets[p].size(); lss++) {
if (sets[p][lss].position_ == ss) {
sets[p][lss].elemOrderMap.resize(sets[p][lss].sideCount);
for (size_t i = 0; i < sets[p][lss].sideCount; i++) {
size_t global_elem =
local_mesh[p].localElementToGlobal[sets[p][lss].elems[i] - 1] + 1;
std::pair<INT, INT> es = std::make_pair((INT)global_elem, (INT)sets[p][lss].sides[i]);

auto iter = std::lower_bound(elem_side.begin(), elem_side.end(), es);
size_t pos = iter - elem_side.begin();
sets[p][lss].elemOrderMap[i] = pos;
}
break;
}
}
for (size_t lss = 0; lss < sets[p].size(); lss++) {
if (sets[p][lss].position_ == ss) {
sets[p][lss].elemOrderMap.resize(sets[p][lss].sideCount);
for (size_t i = 0; i < sets[p][lss].sideCount; i++) {
size_t global_elem =
local_mesh[p].localElementToGlobal[sets[p][lss].elems[i] - 1] + 1;
std::pair<INT, INT> es =
std::make_pair((INT)global_elem, (INT)sets[p][lss].sides[i]);

auto iter = std::lower_bound(elem_side.begin(), elem_side.end(), es);
size_t pos = iter - elem_side.begin();
sets[p][lss].elemOrderMap[i] = pos;
}
break;
}
}
}
}
}
Expand All @@ -2484,19 +2488,19 @@ namespace {
for (size_t ss = 0; ss < glob_ssets.size(); ss++) {
size_t sum = 0;
for (size_t p = 0; p < part_count; p++) {
for (size_t lss = 0; lss < sets[p].size(); lss++) {
if (sets[p][lss].position_ == ss) {
sets[p][lss].offset_ = sum;
sum += sets[p][lss].entity_count();

if (debug_level & 16) {
fmt::print("Part {} ", p + 1);
sets[p][lss].dump();
}
break;
}
}
}
for (size_t lss = 0; lss < sets[p].size(); lss++) {
if (sets[p][lss].position_ == ss) {
sets[p][lss].offset_ = sum;
sum += sets[p][lss].entity_count();

if (debug_level & 16) {
fmt::print("Part {} ", p + 1);
sets[p][lss].dump();
}
break;
}
}
}
}

// Free some memory which is no longer needed...
Expand Down Expand Up @@ -2628,54 +2632,51 @@ namespace {
std::string var_name;
int out_position = -1;
for (auto [v_name, v_blkid] : variable_names) {
if (v_blkid > 0) {
if (var_name != v_name) {
var_name = v_name;
// Find which exodus variable matches this name
out_position = -1;
for (size_t j = 0; j < exo_names.size(); j++) {
if (case_compare(exo_names[j], var_name) == 0) {
out_position = vars.index_[j] - 1;
break;
}
}
if (out_position < 0) {
fmt::print(stderr,
"ERROR: Variable '{}' does not exist on any block in this database.\n",
v_name);
exit(EXIT_FAILURE);
if (v_blkid > 0 && var_name != v_name) {
var_name = v_name;
// Find which exodus variable matches this name
out_position = -1;
for (size_t j = 0; j < exo_names.size(); j++) {
if (case_compare(exo_names[j], var_name) == 0) {
out_position = vars.index_[j] - 1;
break;
}
}
if (out_position < 0) {
fmt::print(stderr, "ERROR: Variable '{}' does not exist on any block in this database.\n",
v_name);
exit(EXIT_FAILURE);
}

// Set all truth table entries for this variable to negative
// of current value and then iterate over specified blocks and
// set those positive. This way can make sure that the
// variable truly exists for the block that the user specified.
found_it = false;
for (size_t b = 0; b < global.count(vars.objectType); b++) {
if (glob_blocks[b].id == v_blkid) {
if (glob_blocks[b].truthTable[out_position] == 0) {
fmt::print(stderr, "ERROR: Variable '{}' does not exist on block {}.\n", v_name,
v_blkid);
exit(EXIT_FAILURE);
}
else {
found_it = true;
break;
}
// Set all truth table entries for this variable to negative
// of current value and then iterate over specified blocks and
// set those positive. This way can make sure that the
// variable truly exists for the block that the user specified.
found_it = false;
for (size_t b = 0; b < global.count(vars.objectType); b++) {
if (glob_blocks[b].id == v_blkid) {
if (glob_blocks[b].truthTable[out_position] == 0) {
fmt::print(stderr, "ERROR: Variable '{}' does not exist on block {}.\n", v_name,
v_blkid);
exit(EXIT_FAILURE);
}
else {
// User does not want this variable output on these blocks...
glob_blocks[b].truthTable[out_position] = 0;
found_it = true;
break;
}
}

if (!found_it) {
fmt::print(stderr,
"ERROR: User-specified block id of {} for variable '{}' does not exist.\n",
v_blkid, v_name);
exit(EXIT_FAILURE);
else {
// User does not want this variable output on these blocks...
glob_blocks[b].truthTable[out_position] = 0;
}
}

if (!found_it) {
fmt::print(stderr,
"ERROR: User-specified block id of {} for variable '{}' does not exist.\n",
v_blkid, v_name);
exit(EXIT_FAILURE);
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/seacas/applications/ejoin/EJoin.C
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(C) 1999-2023 National Technology & Engineering Solutions
// Copyright(C) 1999-2024 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
Expand Down Expand Up @@ -126,7 +126,7 @@ namespace {
namespace {
void transfer_elementblock(Ioss::Region &region, Ioss::Region &output_region,
bool create_assemblies, bool debug);
void transfer_assembly(Ioss::Region &region, Ioss::Region &output_region, bool debug);
void transfer_assembly(const Ioss::Region &region, Ioss::Region &output_region, bool debug);
void transfer_nodesets(Ioss::Region &region, Ioss::Region &output_region, bool debug);
void transfer_sidesets(Ioss::Region &region, Ioss::Region &output_region, bool debug);
void create_nodal_nodeset(Ioss::Region &region, Ioss::Region &output_region, bool debug);
Expand Down Expand Up @@ -625,7 +625,7 @@ namespace {
}
}

void transfer_assembly(Ioss::Region &region, Ioss::Region &output_region, bool debug)
void transfer_assembly(const Ioss::Region &region, Ioss::Region &output_region, bool debug)
{
// All assemblies on the input parts will be transferred to the output mesh
// Possibly renamed if a name conflict
Expand Down
8 changes: 4 additions & 4 deletions packages/seacas/applications/slice/Slice.C
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(C) 1999-2023 National Technology & Engineering Solutions
// Copyright(C) 1999-2024 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
Expand Down Expand Up @@ -77,7 +77,7 @@ namespace {
}
}

Ioss::PropertyManager set_properties(SystemInterface &interFace)
Ioss::PropertyManager set_properties(const SystemInterface &interFace)
{
Ioss::PropertyManager properties;
if (interFace.netcdf4_) {
Expand Down Expand Up @@ -243,10 +243,10 @@ namespace {
const auto &blocks = region.get_element_blocks();
for (const auto &block : blocks) {
block->field_add(Ioss::Field(decomp_variable_name, region.field_int_type(), IOSS_SCALAR(),
Ioss::Field::TRANSIENT));
Ioss::Field::TRANSIENT));
if (add_chain_info) {
block->field_add(
Ioss::Field("chain", region.field_int_type(), "Real[2]", Ioss::Field::TRANSIENT));
Ioss::Field("chain", region.field_int_type(), "Real[2]", Ioss::Field::TRANSIENT));
}
}
region.end_mode(Ioss::STATE_DEFINE_TRANSIENT);
Expand Down
10 changes: 5 additions & 5 deletions packages/seacas/libraries/aprepro_lib/apr_builtin.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(C) 1999-2023 National Technology & Engineering Solutions
// Copyright(C) 1999-2024 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
Expand Down Expand Up @@ -471,9 +471,9 @@ namespace SEAMS {
{
double seconds = h * 3600.0 + mi * 60 + se;

int64_t m = static_cast<int64_t>(mon);
int64_t d = static_cast<int64_t>(day);
int64_t y = static_cast<int64_t>(year);
auto m = static_cast<int64_t>(mon);
auto d = static_cast<int64_t>(day);
auto y = static_cast<int64_t>(year);

if (m > 2) {
m -= 3;
Expand Down Expand Up @@ -954,7 +954,7 @@ namespace SEAMS {
lines << "\t";
for (int ic = 0; ic < cols; ic++) {
#if defined FMT_SUPPORT
SEAMS::symrec *format = aprepro->getsym("_FORMAT");
const SEAMS::symrec *format = aprepro->getsym("_FORMAT");
if (format->value.svar.empty()) {
fmt::print(lines, "{}", my_array_data->data[idx++]);
}
Expand Down
7 changes: 3 additions & 4 deletions packages/seacas/libraries/aprepro_lib/apr_getline.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/*
* Copyright (C) 1991, 1992, 1993, 2021, 2022, 2023 by Chris Thewalt ([email protected])
* Copyright (C) 1991, 1992, 1993, 2021, 2022, 2023, 2024 by Chris Thewalt ([email protected])
*
* Permission to use, copy, modify, and distribute this software
* for any purpose and without fee is hereby granted, provided
Expand Down Expand Up @@ -199,13 +199,12 @@ namespace {
{
#ifdef __unix__
char ch;
int c;
while ((c = read(0, &ch, 1)) == -1) {
while (read(0, &ch, 1) == -1) {
if (errno != EINTR) {
break;
}
}
c = (ch <= 0) ? -1 : ch;
int c = (ch <= 0) ? -1 : ch;
#endif /* __unix__ */
#ifdef MSDOS
int c = _bios_keybrd(_NKEYBRD_READ);
Expand Down
Loading

0 comments on commit 10b907e

Please sign in to comment.