Skip to content

Commit 66b5abb

Browse files
author
Daniel Kroening
committed
use optional for json file name
This is follow-up of #4041. It avoids the use of an empty string as indicator of 'no value'.
1 parent 8811606 commit 66b5abb

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

jbmc/src/janalyzer/janalyzer_parse_options.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,9 @@ int janalyzer_parse_optionst::perform_analysis(const optionst &options)
410410
}
411411
else
412412
{
413-
std::string json_file = cmdline.get_value("json");
413+
optionalt<std::string> json_file;
414+
if(cmdline.isset("json"))
415+
json_file = cmdline.get_value("json");
414416
bool result = taint_analysis(
415417
goto_model, taint_file, ui_message_handler, false, json_file);
416418
return result ? CPROVER_EXIT_VERIFICATION_UNSAFE : CPROVER_EXIT_SUCCESS;

src/goto-analyzer/taint_analysis.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class taint_analysist
3939
const symbol_tablet &,
4040
goto_functionst &,
4141
bool show_full,
42-
const std::string &json_file_name);
42+
const optionalt<std::string> &json_file_name);
4343

4444
protected:
4545
messaget log;
@@ -224,12 +224,12 @@ bool taint_analysist::operator()(
224224
const symbol_tablet &symbol_table,
225225
goto_functionst &goto_functions,
226226
bool show_full,
227-
const std::string &json_file_name)
227+
const optionalt<std::string> &json_file_name)
228228
{
229229
try
230230
{
231231
json_arrayt json_result;
232-
bool use_json=!json_file_name.empty();
232+
bool use_json = json_file_name.has_value();
233233

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

379379
if(use_json)
380380
{
381-
std::ofstream json_out(json_file_name);
381+
std::ofstream json_out(json_file_name.value());
382382

383383
if(!json_out)
384384
{
385-
log.error() << "Failed to open json output `" << json_file_name << "'"
386-
<< messaget::eom;
385+
log.error() << "Failed to open json output `" << json_file_name.value()
386+
<< "'" << messaget::eom;
387387
return true;
388388
}
389389

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

393393
json_out << json_result << '\n';
394394
}
@@ -418,7 +418,7 @@ bool taint_analysis(
418418
const std::string &taint_file_name,
419419
message_handlert &message_handler,
420420
bool show_full,
421-
const std::string &json_file_name)
421+
const optionalt<std::string> &json_file_name)
422422
{
423423
taint_analysist taint_analysis(message_handler);
424424
return taint_analysis(

src/goto-analyzer/taint_analysis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ bool taint_analysis(
2222
const std::string &taint_file_name,
2323
message_handlert &,
2424
bool show_full,
25-
const std::string &json_output_file_name = "");
25+
const optionalt<std::string> &json_output_file_name = {});
2626

2727
#endif // CPROVER_GOTO_ANALYZER_TAINT_ANALYSIS_H

0 commit comments

Comments
 (0)