Skip to content

use optional for json file name #4597

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 1 commit into from
May 1, 2019
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
4 changes: 3 additions & 1 deletion jbmc/src/janalyzer/janalyzer_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,9 @@ int janalyzer_parse_optionst::perform_analysis(const optionst &options)
}
else
{
std::string json_file = cmdline.get_value("json");
optionalt<std::string> json_file;
if(cmdline.isset("json"))
json_file = cmdline.get_value("json");
bool result = taint_analysis(
goto_model, taint_file, ui_message_handler, false, json_file);
return result ? CPROVER_EXIT_VERIFICATION_UNSAFE : CPROVER_EXIT_SUCCESS;
Expand Down
18 changes: 9 additions & 9 deletions src/goto-analyzer/taint_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class taint_analysist
const symbol_tablet &,
goto_functionst &,
bool show_full,
const std::string &json_file_name);
const optionalt<std::string> &json_file_name);

protected:
messaget log;
Expand Down Expand Up @@ -224,12 +224,12 @@ bool taint_analysist::operator()(
const symbol_tablet &symbol_table,
goto_functionst &goto_functions,
bool show_full,
const std::string &json_file_name)
const optionalt<std::string> &json_file_name)
{
try
{
json_arrayt json_result;
bool use_json=!json_file_name.empty();
bool use_json = json_file_name.has_value();

log.status() << "Reading taint file `" << taint_file_name << "'"
<< messaget::eom;
Expand Down Expand Up @@ -378,17 +378,17 @@ bool taint_analysist::operator()(

if(use_json)
{
std::ofstream json_out(json_file_name);
std::ofstream json_out(json_file_name.value());

if(!json_out)
{
log.error() << "Failed to open json output `" << json_file_name << "'"
<< messaget::eom;
log.error() << "Failed to open json output `" << json_file_name.value()
<< "'" << messaget::eom;
return true;
}

log.status() << "Analysis result is written to `" << json_file_name << "'"
<< messaget::eom;
log.status() << "Analysis result is written to `"
<< json_file_name.value() << "'" << messaget::eom;

json_out << json_result << '\n';
}
Expand Down Expand Up @@ -418,7 +418,7 @@ bool taint_analysis(
const std::string &taint_file_name,
message_handlert &message_handler,
bool show_full,
const std::string &json_file_name)
const optionalt<std::string> &json_file_name)
{
taint_analysist taint_analysis(message_handler);
return taint_analysis(
Expand Down
2 changes: 1 addition & 1 deletion src/goto-analyzer/taint_analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ bool taint_analysis(
const std::string &taint_file_name,
message_handlert &,
bool show_full,
const std::string &json_output_file_name = "");
const optionalt<std::string> &json_output_file_name = {});

#endif // CPROVER_GOTO_ANALYZER_TAINT_ANALYSIS_H