3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 09:05:31 +00:00

fix a couple hundred deref-after-free bugs due to .c_str() on a temporary string

This commit is contained in:
Nuno Lopes 2020-07-11 20:24:45 +01:00
parent 48a9defb0d
commit 23e6adcad3
64 changed files with 248 additions and 229 deletions

View file

@ -251,7 +251,8 @@ namespace opt {
m_msolver = mk_sortmax(m_c, m_weights, m_soft_constraints);
}
else {
warning_msg("solver %s is not recognized, using default 'maxres'", maxsat_engine.str().c_str());
auto str = maxsat_engine.str();
warning_msg("solver %s is not recognized, using default 'maxres'", str.c_str());
m_msolver = mk_maxres(m_c, m_index, m_weights, m_soft_constraints);
}

View file

@ -665,9 +665,8 @@ namespace opt {
opt_params p(m_params);
if (p.optsmt_engine() == symbol("symba") ||
p.optsmt_engine() == symbol("farkas")) {
std::stringstream strm;
strm << AS_OPTINF;
gparams::set("smt.arith.solver", strm.str().c_str());
auto str = std::to_string(AS_OPTINF);
gparams::set("smt.arith.solver", str.c_str());
}
}
@ -693,7 +692,7 @@ namespace opt {
expr_ref_vector fmls(m);
get_solver().get_assertions(fmls);
m_sat_solver->assert_expr(fmls);
m_solver = m_sat_solver.get();
m_solver = m_sat_solver.get();
}
void context::enable_sls(bool force) {
@ -950,8 +949,8 @@ namespace opt {
tout << "offset: " << offset << "\n";
);
std::ostringstream out;
out << orig_term << ":" << index;
id = symbol(out.str().c_str());
out << orig_term << ':' << index;
id = symbol(out.str());
return true;
}
if (is_max && get_pb_sum(term, terms, weights, offset)) {
@ -973,8 +972,8 @@ namespace opt {
}
neg = true;
std::ostringstream out;
out << orig_term << ":" << index;
id = symbol(out.str().c_str());
out << orig_term << ':' << index;
id = symbol(out.str());
return true;
}
if ((is_max || is_min) && m_bv.is_bv(term)) {
@ -992,9 +991,9 @@ namespace opt {
}
neg = is_max;
std::ostringstream out;
out << orig_term << ":" << index;
id = symbol(out.str().c_str());
return true;
out << orig_term << ':' << index;
id = symbol(out.str());
return true;
}
return false;
}

View file

@ -175,7 +175,7 @@ namespace opt {
w.start();
std::stringstream file_name;
file_name << "opt_solver" << ++m_dump_count << ".smt2";
std::ofstream buffer(file_name.str().c_str());
std::ofstream buffer(file_name.str());
to_smt2_benchmark(buffer, num_assumptions, assumptions, "opt_solver");
buffer.close();
IF_VERBOSE(1, verbose_stream() << "(created benchmark: " << file_name.str() << "...";