Skip to content

Commit 2801f0f

Browse files
author
martin
committed
Avoid crashing when --dependence-graph is used by correcting namespace scoping.
The namespace has to last as long as the domain does, otherwise the dependence graph will wind up with a reference to a dead, stack allocated object, leading to some exciting crashes.
1 parent a22dd1c commit 2801f0f

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/goto-analyzer/goto_analyzer_parse_options.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ void goto_analyzer_parse_optionst::get_command_line_options(optionst &options)
311311
/// For the task, build the appropriate kind of analyzer
312312
/// Ideally this should be a pure function of options.
313313
/// However at the moment some domains require the goto_model
314-
ai_baset *goto_analyzer_parse_optionst::build_analyzer(const optionst &options)
314+
ai_baset *goto_analyzer_parse_optionst::build_analyzer(
315+
const optionst &options,
316+
const namespacet &ns)
315317
{
316318
ai_baset *domain = nullptr;
317319

@@ -324,7 +326,7 @@ ai_baset *goto_analyzer_parse_optionst::build_analyzer(const optionst &options)
324326
}
325327
else if(options.get_bool_option("dependence-graph"))
326328
{
327-
domain=new dependence_grapht(namespacet(goto_model.symbol_table));
329+
domain=new dependence_grapht(ns);
328330
}
329331
else if(options.get_bool_option("intervals"))
330332
{
@@ -348,7 +350,7 @@ ai_baset *goto_analyzer_parse_optionst::build_analyzer(const optionst &options)
348350
}
349351
else if(options.get_bool_option("dependence-graph"))
350352
{
351-
domain=new dependence_grapht(namespacet(goto_model.symbol_table));
353+
domain=new dependence_grapht(ns);
352354
}
353355
else if(options.get_bool_option("intervals"))
354356
{
@@ -611,7 +613,8 @@ int goto_analyzer_parse_optionst::perform_analysis(const optionst &options)
611613

612614
// Build analyzer
613615
status() << "Selecting abstract domain" << eom;
614-
std::unique_ptr<ai_baset> analyzer(build_analyzer(options));
616+
namespacet ns(goto_model.symbol_table); // Must live as long as the domain.
617+
std::unique_ptr<ai_baset> analyzer(build_analyzer(options, ns));
615618

616619
if(analyzer == nullptr)
617620
{

src/goto-analyzer/goto_analyzer_parse_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class goto_analyzer_parse_optionst:
168168

169169
virtual int perform_analysis(const optionst &options);
170170

171-
ai_baset *build_analyzer(const optionst &options);
171+
ai_baset *build_analyzer(const optionst &, const namespacet &ns);
172172

173173
void eval_verbosity();
174174

0 commit comments

Comments
 (0)