3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2026-02-14 04:41:48 +00:00

Check for dimacs nullptr on file creation+fn call

This commit is contained in:
Gus Smith 2026-02-06 18:18:03 -08:00
parent 2bb352a861
commit b2f9ac4fb5
2 changed files with 8 additions and 0 deletions

View file

@ -14,6 +14,9 @@ bool ezCmdlineSAT::solver(const std::vector<int> &modelExpressions, std::vector<
const std::string cnf_filename = Yosys::stringf("%s/problem.cnf", tempdir_name.c_str());
const std::string sat_command = Yosys::stringf("%s %s", command.c_str(), cnf_filename.c_str());
FILE *dimacs = fopen(cnf_filename.c_str(), "w");
if (dimacs == nullptr) {
Yosys::log_cmd_error("Failed to create CNF file `%s`.\n", cnf_filename.c_str());
}
std::vector<int> modelIdx;
for (auto id : modelExpressions)

View file

@ -1224,6 +1224,11 @@ ezSATvec ezSAT::vec(const std::vector<int> &vec)
void ezSAT::printDIMACS(FILE *f, bool verbose, const std::vector<std::vector<int>> &extraClauses) const
{
if (f == nullptr) {
fprintf(stderr, "Usage error: printDIMACS() must not be called with a null FILE pointer\n");
abort();
}
if (cnfConsumed) {
fprintf(stderr, "Usage error: printDIMACS() must not be called after cnfConsumed()!\n");
abort();