Skip to content

Commit 06a48de

Browse files
thomasspriggsEnrico Steffinlongo
authored andcommitted
Make --no-standard-checks reinstate old malloc behaviour
The calls to the `set_default_analysis_flags` functions need to be before the call to `config.set(cmdline)` so that the malloc defaults can be set before being overridden by any command line specified malloc behaviour.
1 parent 3696020 commit 06a48de

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

src/cbmc/cbmc_parse_options.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,28 @@ void cbmc_parse_optionst::set_default_analysis_flags(
126126
{
127127
options.set_option("unwinding-assertions", enabled);
128128
}
129+
130+
if(enabled)
131+
{
132+
config.ansi_c.malloc_may_fail = true;
133+
config.ansi_c.malloc_failure_mode =
134+
configt::ansi_ct::malloc_failure_modet::malloc_failure_mode_return_null;
135+
}
136+
else
137+
{
138+
config.ansi_c.malloc_may_fail = false;
139+
config.ansi_c.malloc_failure_mode =
140+
configt::ansi_ct::malloc_failure_modet::malloc_failure_mode_none;
141+
}
129142
}
130143

131144
void cbmc_parse_optionst::get_command_line_options(optionst &options)
132145
{
146+
// Enable flags that in combination provide analysis with no surprises
147+
// (expected checks and no unsoundness by missing checks).
148+
cbmc_parse_optionst::set_default_analysis_flags(
149+
options, !cmdline.isset("no-standard-checks"));
150+
133151
if(config.set(cmdline))
134152
{
135153
usage_error();
@@ -366,11 +384,6 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
366384
"self-loops-to-assumptions",
367385
!cmdline.isset("no-self-loops-to-assumptions"));
368386

369-
// Enable flags that in combination provide analysis with no surprises
370-
// (expected checks and no unsoundness by missing checks).
371-
cbmc_parse_optionst::set_default_analysis_flags(
372-
options, !cmdline.isset("no-standard-checks"));
373-
374387
// all (other) checks supported by goto_check
375388
PARSE_OPTIONS_GOTO_CHECK(cmdline, options);
376389

src/goto-analyzer/goto_analyzer_parse_options.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,29 @@ void goto_analyzer_parse_optionst::set_default_analysis_flags(
6868
options.set_option("signed-overflow-check", enabled);
6969
options.set_option("undefined-shift-check", enabled);
7070

71+
if(enabled)
72+
{
73+
config.ansi_c.malloc_may_fail = true;
74+
config.ansi_c.malloc_failure_mode =
75+
configt::ansi_ct::malloc_failure_modet::malloc_failure_mode_return_null;
76+
}
77+
else
78+
{
79+
config.ansi_c.malloc_may_fail = false;
80+
config.ansi_c.malloc_failure_mode =
81+
configt::ansi_ct::malloc_failure_modet::malloc_failure_mode_none;
82+
}
83+
7184
// This is in-line with the options we set for CBMC in cbmc_parse_optionst
7285
// with the exception of unwinding-assertions, which don't make sense in
7386
// the context of abstract interpretation.
7487
}
7588

7689
void goto_analyzer_parse_optionst::get_command_line_options(optionst &options)
7790
{
91+
goto_analyzer_parse_optionst::set_default_analysis_flags(
92+
options, !cmdline.isset("no-standard-checks"));
93+
7894
if(config.set(cmdline))
7995
{
8096
usage_error();
@@ -84,9 +100,6 @@ void goto_analyzer_parse_optionst::get_command_line_options(optionst &options)
84100
if(cmdline.isset("function"))
85101
options.set_option("function", cmdline.get_value("function"));
86102

87-
goto_analyzer_parse_optionst::set_default_analysis_flags(
88-
options, !cmdline.isset("no-standard-checks"));
89-
90103
// all (other) checks supported by goto_check
91104
PARSE_OPTIONS_GOTO_CHECK(cmdline, options);
92105

0 commit comments

Comments
 (0)