From cf78adc72927aefd49b9038b10594e4b68f81301 Mon Sep 17 00:00:00 2001 From: AdvaySingh1 Date: Fri, 10 Apr 2026 13:10:26 -0700 Subject: [PATCH] Made file opening more safe --- passes/silimate/report_fanout.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/passes/silimate/report_fanout.cc b/passes/silimate/report_fanout.cc index dd82bcdfb..b8377a107 100644 --- a/passes/silimate/report_fanout.cc +++ b/passes/silimate/report_fanout.cc @@ -17,6 +17,7 @@ * */ +#include #include "kernel/yosys.h" #include "kernel/sigtools.h" @@ -249,9 +250,9 @@ struct ReportFanoutPass : public Pass { log_cmd_error("Missing required -limit option (must be a non-negative integer).\n"); // Open output file if requested - FILE *f = nullptr; + std::unique_ptr f(nullptr, &fclose); if (!filename.empty()) { - f = fopen(filename.c_str(), "w"); + f.reset(fopen(filename.c_str(), "w")); if (!f) log_cmd_error("Cannot open file '%s' for writing.\n", filename.c_str()); } @@ -261,11 +262,8 @@ struct ReportFanoutPass : public Pass { { log("Analyzing fanout for module %s...\n", log_id(module)); ReportFanoutWorker worker(module, skip_clk_rst); - worker.report(limit, f); + worker.report(limit, f.get()); } - - if (f) - fclose(f); } } ReportFanoutPass;