@@ -329,13 +329,49 @@ std::pair<taint_slicing_taskt,std::string> build_slicing_task(
329
329
// Before return we compute and same basic statistics of the saved
330
330
// GOTO program (i.e. the slicing task). These statistics will later
331
331
// 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 )
333
333
// 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);
338
334
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
+ }
339
375
return {{props.get_root (), sink_locations, pathname}, " " };
340
376
}
341
377
}
0 commit comments