Skip to content

Commit

Permalink
Added check to make sure argument to getIDFromName only contains digits.
Browse files Browse the repository at this point in the history
  • Loading branch information
pbehne committed Apr 16, 2024
1 parent b1c2514 commit d2a8707
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions framework/include/utils/MooseMeshUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,16 +291,19 @@ void makeOrderedNodeList(std::vector<std::pair<dof_id_type, dof_id_type>> & node
std::vector<dof_id_type> & ordered_elem_id_list);

/**
* Converts a given name (BoundaryName or SubdomainName) into a corresponding ID (BoundaryID or
* SubdomainID) and performs bounds checking to ensure that overflow doesn't happen.
* Converts a given name (BoundaryName or SubdomainName) that is known to only contain digits into a
* corresponding ID (BoundaryID or SubdomainID) and performs bounds checking to ensure that overflow
* doesn't happen.
* @param name Name that is to be converted into an ID.
* @return ID type corresponding to the type of name.
*/
template <typename T, typename Q>
Q
getIDFromName(const T & name)
{
std::istringstream ss(name);
if (!MooseUtils::isDigits(name))
mooseError(
"'name' ", name, " should only contain digits that can be converted to a numerical type.");
long long id = std::stoll(name);
Q id_Q = Q(id);
if (id < std::numeric_limits<Q>::min() || id > std::numeric_limits<Q>::max())
Expand Down

0 comments on commit d2a8707

Please sign in to comment.