Skip to content

Commit 5f35a0e

Browse files
committed
Updates requested in the PR.
1 parent 829bc5b commit 5f35a0e

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

src/taint-slicer/slicing_tasks_builder.cpp

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,49 @@ std::pair<taint_slicing_taskt,std::string> build_slicing_task(
329329
// Before return we compute and same basic statistics of the saved
330330
// GOTO program (i.e. the slicing task). These statistics will later
331331
// be used by the Python driver script to compare them with similar
332-
// statistics from the full slicer (implemented in goto-instrumet)
332+
// statistics from the full slicer (implemented in goto-instrument)
333333
// in order to get the efficiency of the slicing.
334-
goto_statisticst stats;
335-
stats.extend(goto_model);
336-
std::ofstream ofile(fileutl_remove_extension(pathname) + ".stats.json");
337-
ofile << to_json(stats);
338334

335+
const std::string out_json_file_pathname=
336+
fileutl_remove_extension(pathname) + ".stats.json";
337+
338+
// We start with safety check related to the file to be written.
339+
bool can_write_stats=true;
340+
if(fileutl_is_directory(out_json_file_pathname))
341+
{
342+
logger->error()
343+
<< "The path-name '"
344+
<< out_json_file_pathname
345+
<< "' for the statistics JSON output is actually an existing "
346+
<< "directory."
347+
<< messaget::eom;
348+
can_write_stats=false;
349+
}
350+
if(fileutl_parse_extension_in_pathname(out_json_file_pathname)!=".json")
351+
{
352+
logger->error()
353+
<< "The file of the path-name '" << out_json_file_pathname
354+
<< "' for the statistics JSON output does not have '.json' extension."
355+
<< messaget::eom;
356+
can_write_stats=false;
357+
}
358+
if(can_write_stats)
359+
{
360+
// And let's compute and save the statistics.
361+
goto_statisticst stats;
362+
stats.extend(goto_model);
363+
std::ofstream ofile(out_json_file_pathname);
364+
if(!ofile)
365+
{
366+
logger->error()
367+
<< "Failed to open the JSON file '" << out_json_file_pathname
368+
<< "' for writing. The statistic of the GOTO program won't be "
369+
<< "available."
370+
<< messaget::eom;
371+
}
372+
else
373+
ofile << to_json(stats);
374+
}
339375
return {{props.get_root(), sink_locations, pathname}, ""};
340376
}
341377
}

0 commit comments

Comments
 (0)