Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions contrib/fparser/util/bytecoderules_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ namespace
size_t indent)
{
std::string codehash, prevlabel;
for(size_t a=chain.size(); a-- > 0; )
for(ptrdiff_t a=chain.size(); a-- > 0; )
{
codehash += chain[a];
std::string label = GenLabel(codehash);
Expand Down Expand Up @@ -509,7 +509,7 @@ namespace
outstream << "\n" << Indent(indent+1);

outstream << '"';
for(size_t a=so_far.size(); a-- > 0; )
for(ptrdiff_t a=so_far.size(); a-- > 0; )
{
if(a+1 != so_far.size()) outstream << " ";
outstream << so_far[a].name;
Expand Down Expand Up @@ -1269,7 +1269,7 @@ namespace
}

Node* head = &global_head;
for(size_t b=sequence.size(); b-->0; )
for(ptrdiff_t b=sequence.size(); b-->0; )
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How was this working before with an unsigned type and this cutesy b-->0 BS? When b==0 the test fails and then you post-decrement so the number wraps to max size_t, but we never see it because the loop is done?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Precisely. It's apparently a popular idiom, too; this is what -fsanitize=integer was complaining about in a couple places in libstdc++ basic_string code.

{
const Match& m = sequence[b];
bool dup = false;
Expand Down
15 changes: 15 additions & 0 deletions fsanitize_ignorelist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This is a set of exceptions to use in
# '-fsanitize-ignorelist=yourdir/fsanitize_ignorelist.txt'
#
# So far it's been tested and found to be complete for
# -fsanitize=integer on clang++ 14 with g++ 12.1.0 headers
fun:*basic_string_view*rfind*
fun:*basic_string*compare*
src:*hashing.h
src:*hashword.h
src:*libHilbert*SetBits*
src:*fpoptimizer*
src:*fp_opcode_add*
src:*bytecodesynth*
src:*fparser.cc
src:*Eigen/*
2 changes: 1 addition & 1 deletion include/base/getpot.h
Original file line number Diff line number Diff line change
Expand Up @@ -2777,7 +2777,7 @@ GetPot::_DBE_expand_string(const std::string& str)
unsigned first = 0;
for (unsigned i = 0; i<str.size(); i++)
{
if (i < str.size() - 2 && str.substr(i, 2) == "${")
if (i + 2 < str.size() && str.substr(i, 2) == "${")
{
if (open_brackets == 0)
first = i+2;
Expand Down
4 changes: 2 additions & 2 deletions include/mesh/namebased_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ NameBasedIO::is_parallel_file_format (std::string_view name)
{
return ((name.rfind(".xda") < name.size()) ||
(name.rfind(".xdr") < name.size()) ||
(name.rfind(".nem") + 4 == name.size()) ||
(name.rfind(".n") + 2 == name.size()) ||
(name.rfind(".nem") == name.size() - 4) ||
(name.rfind(".n") == name.size() - 2) ||
Comment on lines +128 to +129
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have guessed the sanitizer wouldn't like subtracting from an unsigned type that could possibly be 0? Oh, but std::string::rfind() returns std::string::npos which is effectively max size_t so adding to that would also be bad... not sure which is best actually.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah; the saving grace here is that npos actually gets returned pretty frequently in practice, whereas at least in our unit tests and examples we never try to open a filename that's only 3 characters long. UBSan adds a bunch of runtime checking; if it tried to also do compile-time checking of ranges then I can't imagine how many thousand false positives we'd have hit...

(name.rfind(".cp") < name.size())
);
}
Expand Down
2 changes: 1 addition & 1 deletion include/reduced_basis/rb_construction.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ class RBConstruction : public RBConstructionBase<LinearImplicitSystem>
*/
void set_rb_construction_parameters(unsigned int n_training_samples_in,
bool deterministic_training_in,
unsigned int training_parameters_random_seed_in,
int training_parameters_random_seed_in,
bool quiet_mode_in,
unsigned int Nmax_in,
Real rel_training_tolerance_in,
Expand Down
2 changes: 1 addition & 1 deletion include/reduced_basis/rb_construction_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class RBConstructionBase : public Base, public RBParametrized
/**
* Set the seed that is used to randomly generate training parameters.
*/
void set_training_random_seed(unsigned int seed);
void set_training_random_seed(int seed);

/**
* In some cases we only want to allow discrete parameter values, instead
Expand Down
2 changes: 1 addition & 1 deletion include/reduced_basis/rb_eim_construction.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class RBEIMConstruction : public RBConstructionBase<System>
*/
void set_rb_construction_parameters(unsigned int n_training_samples_in,
bool deterministic_training_in,
unsigned int training_parameters_random_seed_in,
int training_parameters_random_seed_in,
bool quiet_mode_in,
unsigned int Nmax_in,
Real rel_training_tolerance_in,
Expand Down
4 changes: 2 additions & 2 deletions src/base/dof_map.C
Original file line number Diff line number Diff line change
Expand Up @@ -2447,7 +2447,7 @@ void DofMap::_dof_indices (const Elem & elem,
di.resize(di.size() + nc, DofObject::invalid_id);
}
else
for (int i=n_comp-1; i>=dof_offset; i--)
for (int i=int(n_comp)-1; i>=dof_offset; i--)
{
const dof_id_type d =
node.dof_number(sys_num, vg, vig, i, n_comp);
Expand Down Expand Up @@ -2685,7 +2685,7 @@ void DofMap::old_dof_indices (const Elem * const elem,
}

// Compute the net amount of "extra" order, including Elem::p_level()
int extra_order = elem->p_level() + p_adjustment;
int extra_order = int(elem->p_level()) + p_adjustment;

FEType fe_type = var.type();

Expand Down
4 changes: 2 additions & 2 deletions src/base/dof_map_constraints.C
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,7 @@ dof_id_type DofMap::n_local_constrained_dofs() const
const DofConstraints::const_iterator lower =
_dof_constraints.lower_bound(this->first_dof()),
upper =
_dof_constraints.upper_bound(this->end_dof()-1);
_dof_constraints.lower_bound(this->end_dof());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like an actual bugfix... was that suggested by the sanitizer?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't suggested by the sanitizer; that only reports filename and line number and what type of behavior was detected, and leaves it up to the developer to figure out how to fix it. Maybe in LLVM 30.

But ... yeah, this looks like a real bug fix. I recently spent a ton of time fixing a bug that was triggered by an unexpected corner case with element deletion, just like this one could easily have been, and as annoying as the sanitizer is I have to say this fix alone made me feel like the annoyance was worth it so far.


return cast_int<dof_id_type>(std::distance(lower, upper));
}
Expand Down Expand Up @@ -2086,7 +2086,7 @@ void DofMap::process_mesh_constraint_rows(const MeshBase & mesh)

if (was_previously_constrained.count(constrained_id))
{
for (auto q : IntRange<unsigned int>(0, n_adjoint_rhs+1))
for (auto q : IntRange<int>(0, n_adjoint_rhs+1))
{
DenseMatrix<Number> K(1,1);
DenseVector<Number> F(1);
Expand Down
4 changes: 3 additions & 1 deletion src/base/dof_object.C
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ void DofObject::set_n_systems (const unsigned int ns)

const unsigned int nei = this->n_extra_integers();
const dof_id_type header_size = ns + bool(nei);
const dof_id_type hdr = nei ? -header_size : header_size;
const dof_id_type hdr = nei ?
static_cast<dof_id_type>(-static_cast<std::ptrdiff_t>(header_size))
: header_size;
index_buffer_t new_buf(header_size + nei, hdr);
if (nei)
{
Expand Down
8 changes: 4 additions & 4 deletions src/fe/fe_base.C
Original file line number Diff line number Diff line change
Expand Up @@ -1635,10 +1635,10 @@ FEGenericBase<OutputType>::compute_proj_constraints (DofConstraints & constraint
// minimum shared p_level
const unsigned int old_elem_level = elem->p_level();
if (elem->p_level() != min_p_level)
my_fe->set_fe_order(my_fe->get_fe_type().order.get_order() - old_elem_level + min_p_level);
my_fe->set_fe_order(my_fe->get_fe_type().order.get_order() + min_p_level - old_elem_level);
const unsigned int old_neigh_level = neigh->p_level();
if (old_neigh_level != min_p_level)
neigh_fe->set_fe_order(neigh_fe->get_fe_type().order.get_order() - old_neigh_level + min_p_level);
neigh_fe->set_fe_order(neigh_fe->get_fe_type().order.get_order() + min_p_level - old_neigh_level);

my_fe->reinit(elem, s);

Expand Down Expand Up @@ -1668,10 +1668,10 @@ FEGenericBase<OutputType>::compute_proj_constraints (DofConstraints & constraint
// derivatives for C1 elements) are supported on side nodes
FEType elem_fe_type = base_fe_type;
if (old_elem_level != min_p_level)
elem_fe_type.order = base_fe_type.order.get_order() - old_elem_level + min_p_level;
elem_fe_type.order = base_fe_type.order.get_order() + min_p_level - old_elem_level;
FEType neigh_fe_type = base_fe_type;
if (old_neigh_level != min_p_level)
neigh_fe_type.order = base_fe_type.order.get_order() - old_neigh_level + min_p_level;
neigh_fe_type.order = base_fe_type.order.get_order() + min_p_level - old_neigh_level;
FEInterface::dofs_on_side(elem, Dim, elem_fe_type, s, my_side_dofs);
FEInterface::dofs_on_side(neigh, Dim, neigh_fe_type, s_neigh, neigh_side_dofs);

Expand Down
2 changes: 1 addition & 1 deletion src/mesh/dyna_io.C
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ DynaIO::DynaIO (MeshBase & mesh,

void DynaIO::read (const std::string & name)
{
const bool gzipped_file = (name.size() - name.rfind(".gz") == 3);
const bool gzipped_file = (name.rfind(".gz") == name.size() - 3);
// These will be handled in unzip_file:
// const bool bzipped_file = (name.size() - name.rfind(".bz2") == 4);
// const bool xzipped_file = (name.size() - name.rfind(".xz") == 3);
Expand Down
9 changes: 6 additions & 3 deletions src/mesh/mesh_refinement_smoothing.C
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,9 @@ bool MeshRefinement::eliminate_unrefined_patches ()
libmesh_assert_greater (elem->p_level(), 0);
my_p_adjustment = -1;
}
const unsigned int my_new_p_level = elem->p_level() +
my_p_adjustment;
const unsigned int my_new_p_level =
cast_int<unsigned int>(int(elem->p_level()) +
my_p_adjustment);

// Check all the element neighbors
for (auto neighbor : elem->neighbor_ptr_range())
Expand Down Expand Up @@ -479,7 +480,9 @@ bool MeshRefinement::eliminate_unrefined_patches ()
libmesh_assert_greater (neighbor->p_level(), 0);
p_adjustment = -1;
}
if (my_new_p_level >= neighbor->p_level() + p_adjustment)
if (my_new_p_level >=
cast_int<unsigned int>(int(neighbor->p_level())
+ p_adjustment))
{
p_flag_me = false;
if (!h_flag_me)
Expand Down
20 changes: 10 additions & 10 deletions src/mesh/namebased_io.C
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ void NameBasedIO::read (const std::string & name)

// For Nemesis files, the name we try to read will have suffixes
// identifying processor rank
if (basename.rfind(".nem") + 4 == basename.size() ||
basename.rfind(".n") + 2 == basename.size())
if (basename.rfind(".nem") == basename.size() - 4 ||
basename.rfind(".n") == basename.size() - 2)
{
std::ostringstream full_name;

Expand Down Expand Up @@ -189,7 +189,7 @@ void NameBasedIO::read (const std::string & name)
pid_suffix << '_' << getpid();
// Nasty hack for reading/writing zipped files
std::string new_name = name;
if (name.size() - name.rfind(".bz2") == 4)
if (name.rfind(".bz2") == name.size() - 4)
{
#ifdef LIBMESH_HAVE_BZIP
new_name.erase(new_name.end() - 4, new_name.end());
Expand All @@ -203,7 +203,7 @@ void NameBasedIO::read (const std::string & name)
libmesh_error_msg("ERROR: need bzip2/bunzip2 to open .bz2 file " << name);
#endif
}
else if (name.size() - name.rfind(".xz") == 3)
else if (name.rfind(".xz") == name.size() - 3)
{
#ifdef LIBMESH_HAVE_XZ
new_name.erase(new_name.end() - 3, new_name.end());
Expand Down Expand Up @@ -292,9 +292,9 @@ void NameBasedIO::read (const std::string & name)

// If we temporarily decompressed a file, remove the
// uncompressed version
if (name.size() - name.rfind(".bz2") == 4)
if (name.rfind(".bz2") == name.size() - 4)
std::remove(new_name.c_str());
if (name.size() - name.rfind(".xz") == 3)
if (name.rfind(".xz") == name.size() - 3)
std::remove(new_name.c_str());
}

Expand Down Expand Up @@ -348,12 +348,12 @@ void NameBasedIO::write (const std::string & name)
std::ostringstream pid_suffix;
pid_suffix << '_' << pid_0;

if (name.size() - name.rfind(".bz2") == 4)
if (name.rfind(".bz2") == name.size() - 4)
{
new_name.erase(new_name.end() - 4, new_name.end());
new_name += pid_suffix.str();
}
else if (name.size() - name.rfind(".xz") == 3)
else if (name.rfind(".xz") == name.size() - 3)
{
new_name.erase(new_name.end() - 3, new_name.end());
new_name += pid_suffix.str();
Expand Down Expand Up @@ -432,7 +432,7 @@ void NameBasedIO::write (const std::string & name)
}

// Nasty hack for reading/writing zipped files
if (name.size() - name.rfind(".bz2") == 4)
if (name.rfind(".bz2") == name.size() - 4)
{
LOG_SCOPE("system(bzip2)", "NameBasedIO");
if (mymesh.processor_id() == 0)
Expand All @@ -445,7 +445,7 @@ void NameBasedIO::write (const std::string & name)
}
mymesh.comm().barrier();
}
if (name.size() - name.rfind(".xz") == 3)
if (name.rfind(".xz") == name.size() - 3)
{
LOG_SCOPE("system(xz)", "NameBasedIO");
if (mymesh.processor_id() == 0)
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/unstructured_mesh.C
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ void UnstructuredMesh::read (const std::string & name,
// during prepare_for_use() for certain types of mesh files.
// This is required in cases where there is an associated solution
// file which expects a certain ordering of the nodes.
if (name.rfind(".gmv") + 4 == name.size())
if (name.rfind(".gmv") == name.size() - 4)
this->allow_renumbering(false);

NameBasedIO(*this).read(name);
Expand Down
2 changes: 1 addition & 1 deletion src/numerics/petsc_vector.C
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ void PetscVector<T>::localize (const numeric_index_type first_local_idx,
libmesh_assert_less_equal (last_local_idx+1, this->size());

const numeric_index_type my_size = this->size();
const numeric_index_type my_local_size = (last_local_idx - first_local_idx + 1);
const numeric_index_type my_local_size = (last_local_idx + 1 - first_local_idx);
PetscErrorCode ierr=0;

// Don't bother for serial cases
Expand Down
6 changes: 4 additions & 2 deletions src/parallel/parallel_bin_sorter.C
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ void BinSorter<KeyType,IdxType>::binsort (const IdxType nbins,

// Step through the histogram until we have the
// desired bin size
while ((current_bin_size + histogram[current_histogram_bin] + delta) <= target_bin_size[b])
while ((current_bin_size +
cast_int<int>(histogram[current_histogram_bin]) +
delta) <= cast_int<int>(target_bin_size[b]))
{
// Don't index out of the histogram!
if ((current_histogram_bin+1) == phist.n_bins())
Expand All @@ -114,7 +116,7 @@ void BinSorter<KeyType,IdxType>::binsort (const IdxType nbins,
current_bin_size += histogram[current_histogram_bin++];
}

delta += current_bin_size - target_bin_size[b];
delta += current_bin_size - static_cast<int>(target_bin_size[b]);

// Set the upper bound of the bin
bin_bounds[b+1] = phist.upper_bound (current_histogram_bin);
Expand Down
4 changes: 2 additions & 2 deletions src/reduced_basis/rb_construction.C
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ void RBConstruction::process_parameters_file (const std::string & parameters_fil
// Set the parameters that have been read in
set_rb_construction_parameters(n_training_samples,
deterministic_training,
training_parameters_random_seed_in,
static_cast<int>(training_parameters_random_seed_in),
quiet_mode_in,
Nmax_in,
rel_training_tolerance_in,
Expand All @@ -273,7 +273,7 @@ void RBConstruction::process_parameters_file (const std::string & parameters_fil
void RBConstruction::set_rb_construction_parameters(
unsigned int n_training_samples_in,
bool deterministic_training_in,
unsigned int training_parameters_random_seed_in,
int training_parameters_random_seed_in,
bool quiet_mode_in,
unsigned int Nmax_in,
Real rel_training_tolerance_in,
Expand Down
2 changes: 1 addition & 1 deletion src/reduced_basis/rb_construction_base.C
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ void RBConstructionBase<Base>::broadcast_parameters(unsigned int proc_id)
}

template <class Base>
void RBConstructionBase<Base>::set_training_random_seed(unsigned int seed)
void RBConstructionBase<Base>::set_training_random_seed(int seed)
{
this->training_parameters_random_seed = seed;
}
Expand Down
2 changes: 1 addition & 1 deletion src/reduced_basis/rb_eim_construction.C
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ void RBEIMConstruction::process_parameters_file (const std::string & parameters_

void RBEIMConstruction::set_rb_construction_parameters(unsigned int n_training_samples_in,
bool deterministic_training_in,
unsigned int training_parameters_random_seed_in,
int training_parameters_random_seed_in,
bool quiet_mode_in,
unsigned int Nmax_in,
Real rel_training_tolerance_in,
Expand Down
4 changes: 2 additions & 2 deletions src/reduced_basis/rb_scm_construction.C
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ void RBSCMConstruction::process_parameters_file(const std::string & parameters_f
// Read in training_parameters_random_seed value. This is used to
// seed the RNG when picking the training parameters. By default the
// value is -1, which means use std::time to seed the RNG.
unsigned int training_parameters_random_seed_in = static_cast<int>(-1);
unsigned int training_parameters_random_seed_in = static_cast<unsigned int>(-1);
training_parameters_random_seed_in = infile("training_parameters_random_seed",
training_parameters_random_seed_in);
set_training_random_seed(training_parameters_random_seed_in);
set_training_random_seed(static_cast<int>(training_parameters_random_seed_in));

// SCM Greedy termination tolerance
const Real SCM_training_tolerance_in = infile("SCM_training_tolerance", SCM_training_tolerance);
Expand Down
9 changes: 5 additions & 4 deletions src/systems/fem_context.C
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ void FEMContext::attach_quadrature_rules()
FEType fe_type = sys.variable_type(v);

_element_fe[dim][fe_type]->attach_quadrature_rule(_element_qrule[dim].get());
_side_fe[dim][fe_type]->attach_quadrature_rule(_side_qrule[dim].get());

if (dim)
_side_fe[dim][fe_type]->attach_quadrature_rule(_side_qrule[dim].get());
if (dim == 3)
_edge_fe[fe_type]->attach_quadrature_rule(_edge_qrule.get());
};
Expand All @@ -157,8 +157,9 @@ void FEMContext::use_default_quadrature_rules(int extra_quadrature_order)
// Create an adequate quadrature rule
_element_qrule[dim] =
hardest_fe_type.default_quadrature_rule(dim, _extra_quadrature_order);
_side_qrule[dim] =
hardest_fe_type.default_quadrature_rule(dim-1, _extra_quadrature_order);
if (dim)
_side_qrule[dim] =
hardest_fe_type.default_quadrature_rule(dim-1, _extra_quadrature_order);
if (dim == 3)
_edge_qrule = hardest_fe_type.default_quadrature_rule(1, _extra_quadrature_order);
}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/utility.C
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ std::string Utility::unzip_file (std::string_view name)
pid_suffix << '_' << getpid();

std::string new_name { name };
if (name.size() - name.rfind(".bz2") == 4)
if (name.rfind(".bz2") == name.size() - 4)
{
#ifdef LIBMESH_HAVE_BZIP
new_name.erase(new_name.end() - 4, new_name.end());
Expand All @@ -174,7 +174,7 @@ std::string Utility::unzip_file (std::string_view name)
libmesh_error_msg("ERROR: need bzip2/bunzip2 to open .bz2 file " << name);
#endif
}
else if (name.size() - name.rfind(".xz") == 3)
else if (name.rfind(".xz") == name.size() - 3)
{
#ifdef LIBMESH_HAVE_XZ
new_name.erase(new_name.end() - 3, new_name.end());
Expand Down
Loading