Skip to content

Class loading utils #2640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
9 changes: 8 additions & 1 deletion jbmc/src/java_bytecode/java_class_loader_limit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ void java_class_loader_limitt::setup_class_load_limit(
// '@' signals file reading with list of class files to load
use_regex_match = java_cp_include_files[0] != '@';
if(use_regex_match)
{
regex_matcher=std::regex(java_cp_include_files);
debug() << "Limit loading to classes matching '" << java_cp_include_files
<< "'" << eom;
}
else
{
assert(java_cp_include_files.length()>1);
Expand Down Expand Up @@ -54,7 +58,10 @@ bool java_class_loader_limitt::load_class_file(const std::string &file_name)
if(use_regex_match)
{
std::smatch string_matches;
return std::regex_match(file_name, string_matches, regex_matcher);
if(std::regex_match(file_name, string_matches, regex_matcher))
return true;
debug() << file_name + " discarded since not matching loader regexp" << eom;
return false;
}
else
// load .class file only if it is in the match set
Expand Down
21 changes: 21 additions & 0 deletions src/util/string_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,24 @@ std::string escape(const std::string &s)

return result;
}

Copy link
Member

Choose a reason for hiding this comment

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

This bit of code is from stack overflow. You need to attribute it, and clearly mark it as covered by the MIT license.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kroening, added copyright notice.

/// Replace all occurrences of a string inside a string
/// \param [out] str: string to search
/// \param from: string to replace
/// \param to: string to replace with
/// Copyright notice:
/// Attributed to Gauthier Boaglio
/// Source: https://stackoverflow.com/a/24315631/7501486
/// Used under MIT license
void replace_all(
std::string &str,
const std::string &from,
const std::string &to)
{
size_t start_pos = 0;
while((start_pos = str.find(from, start_pos)) != std::string::npos)
{
str.replace(start_pos, from.length(), to);
start_pos += to.length();
}
}
2 changes: 2 additions & 0 deletions src/util/string_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,6 @@ Stream &join_strings(
/// programming language.
std::string escape(const std::string &);

void replace_all(std::string &, const std::string &, const std::string &);

#endif