Skip to content

Commit 2791d26

Browse files
author
Enrico Steffinlongo
authored
Merge pull request #8101 from thomasspriggs/tas/default-malloc-failure
Use malloc-fail-null by default
2 parents 92e3c0f + c3c7bc0 commit 2791d26

File tree

11 files changed

+61
-22
lines changed

11 files changed

+61
-22
lines changed

Diff for: doc/man/cbmc.1

-3
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@ disable signed arithmetic over\- and underflow checks
105105
\fB\-\-no\-malloc\-may\-fail\fR
106106
do not allow malloc calls to fail by default
107107
.TP
108-
\fB\-\-no\-malloc\-fail\-null\fR
109-
do not set malloc failure mode to return null pointer
110-
.TP
111108
\fB\-\-no\-unwinding\-assertions\fR (\fBcbmc\fR\-only)
112109
do not generate unwinding assertions (cannot be
113110
used with \fB\-\-cover\fR)

Diff for: doc/man/goto-analyzer.1

-3
Original file line numberDiff line numberDiff line change
@@ -637,9 +637,6 @@ disable signed arithmetic over\- and underflow checks
637637
\fB\-\-no\-malloc\-may\-fail\fR
638638
do not allow malloc calls to fail by default
639639
.TP
640-
\fB\-\-no\-malloc\-fail\-null\fR
641-
do not set malloc failure mode to return null pointer
642-
.TP
643640
\fB\-\-no\-unwinding\-assertions\fR (\fBcbmc\fR\-only)
644641
do not generate unwinding assertions (cannot be
645642
used with \fB\-\-cover\fR)

Diff for: doc/man/goto-instrument.1

+3
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,9 @@ set malloc failure mode to assert\-then\-assume
697697
\fB\-\-malloc\-fail\-null\fR
698698
set malloc failure mode to return null
699699
.TP
700+
\fB\-\-no\-malloc\-may\-fail\fR
701+
do not allow malloc calls to fail by default
702+
.TP
700703
\fB\-\-string\-abstraction\fR
701704
track C string lengths and zero\-termination
702705
.TP

Diff for: regression/contracts-dfcc/chain.sh

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ else
4343
$goto_cc -o "${name}${dfcc_suffix}.gb" "${name}.c"
4444
fi
4545

46+
if [[ "${args_inst}" != *"malloc"* ]]; then
47+
args_inst="--no-malloc-may-fail $args_inst"
48+
fi
49+
4650
rm -f "${name}${dfcc_suffix}-mod.gb"
4751
$goto_instrument ${args_inst} "${name}${dfcc_suffix}.gb" "${name}${dfcc_suffix}-mod.gb"
4852
if [ ! -e "${name}${dfcc_suffix}-mod.gb" ] ; then

Diff for: regression/goto-instrument/chain.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ else
2121
fi
2222

2323
rm -f "${target}-mod.gb"
24-
$goto_instrument ${args} "${target}.gb" "${target}-mod.gb"
24+
$goto_instrument --no-malloc-may-fail ${args} "${target}.gb" "${target}-mod.gb"
2525
if [ ! -e "${target}-mod.gb" ] ; then
2626
cp "${target}.gb" "${target}-mod.gb"
2727
elif echo $args | grep -q -- "--dump-c-type-header" ; then
@@ -39,5 +39,5 @@ elif echo $args | grep -q -- "--dump-c" ; then
3939

4040
rm "${target}-mod.c"
4141
fi
42-
$goto_instrument --show-goto-functions "${target}-mod.gb"
42+
$goto_instrument --no-malloc-may-fail --show-goto-functions "${target}-mod.gb"
4343
$cbmc --no-standard-checks "${target}-mod.gb"

Diff for: regression/goto-synthesizer/chain.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fi
3737
rm -f "${name}-mod.gb"
3838
rm -f "${name}-mod-2.gb"
3939
echo "Running goto-instrument: "
40-
$goto_instrument ${args_inst} "${name}.gb" "${name}-mod.gb"
40+
$goto_instrument --no-malloc-may-fail ${args_inst} "${name}.gb" "${name}-mod.gb"
4141
if [ ! -e "${name}-mod.gb" ] ; then
4242
cp "$name.gb" "${name}-mod.gb"
4343
elif echo $args_inst | grep -q -- "--dump-c" ; then
@@ -53,9 +53,9 @@ elif echo $args_inst | grep -q -- "--dump-c" ; then
5353
fi
5454
echo "Running goto-synthesizer: "
5555
if echo $args_synthesizer | grep -q -- "--dump-loop-contracts" ; then
56-
$goto_synthesizer ${args_synthesizer} "${name}-mod.gb"
56+
$goto_synthesizer ${args_synthesizer} --no-malloc-may-fail "${name}-mod.gb"
5757
else
58-
$goto_synthesizer ${args_synthesizer} "${name}-mod.gb" "${name}-mod-2.gb"
58+
$goto_synthesizer ${args_synthesizer} --no-malloc-may-fail "${name}-mod.gb" "${name}-mod-2.gb"
5959
echo "Running CBMC: "
6060
$cbmc --no-standard-checks ${args_cbmc} "${name}-mod-2.gb"
6161
fi

Diff for: src/cbmc/cbmc_parse_options.cpp

+18-5
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

Diff for: src/goto-analyzer/goto_analyzer_parse_options.cpp

+16-3
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

Diff for: src/goto-analyzer/goto_analyzer_parse_options.h

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ Author: Daniel Kroening, [email protected]
8989
#ifndef CPROVER_GOTO_ANALYZER_GOTO_ANALYZER_PARSE_OPTIONS_H
9090
#define CPROVER_GOTO_ANALYZER_GOTO_ANALYZER_PARSE_OPTIONS_H
9191

92+
#include <util/config.h>
9293
#include <util/parse_options.h>
9394
#include <util/timestamper.h>
9495
#include <util/ui_message.h>
@@ -152,6 +153,7 @@ class optionst;
152153
OPT_SHOW_GOTO_FUNCTIONS \
153154
OPT_SHOW_PROPERTIES \
154155
OPT_GOTO_CHECK \
156+
OPT_CONFIG_LIBRARY \
155157
"(show-symbol-table)(show-parse-tree)" \
156158
"(property):" \
157159
"(verbosity):(version)" \

Diff for: src/util/config.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,15 @@ bool configt::set(const cmdlinet &cmdline)
11261126
if(cmdline.isset("malloc-fail-assert"))
11271127
ansi_c.malloc_failure_mode = ansi_c.malloc_failure_mode_assert_then_assume;
11281128

1129-
ansi_c.malloc_may_fail = cmdline.isset("malloc-may-fail");
1129+
if(cmdline.isset("malloc-may-fail"))
1130+
{
1131+
ansi_c.malloc_may_fail = true;
1132+
}
1133+
if(cmdline.isset("no-malloc-may-fail"))
1134+
{
1135+
ansi_c.malloc_may_fail = false;
1136+
ansi_c.malloc_failure_mode = ansi_ct::malloc_failure_mode_none;
1137+
}
11301138

11311139
if(cmdline.isset("c89"))
11321140
ansi_c.set_c89();

Diff for: src/util/config.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ class symbol_table_baset;
7171

7272
#define OPT_CONFIG_LIBRARY \
7373
"(malloc-fail-assert)(malloc-fail-null)(malloc-may-fail)" \
74+
"(no-malloc-may-fail)" \
7475
"(string-abstraction)"
7576

7677
#define HELP_CONFIG_LIBRARY \
7778
" {y--malloc-may-fail} \t allow malloc calls to return a null pointer\n" \
79+
" {y--no-malloc-may-fail} \t disable potential malloc failure\n" \
7880
" {y--malloc-fail-assert} \t " \
7981
"set malloc failure mode to assert-then-assume\n" \
8082
" {y--malloc-fail-null} \t set malloc failure mode to return null\n" \
@@ -272,7 +274,7 @@ class configt
272274
libt lib;
273275
274276
bool string_abstraction;
275-
bool malloc_may_fail = false;
277+
bool malloc_may_fail = true;
276278
277279
enum malloc_failure_modet
278280
{
@@ -281,7 +283,7 @@ class configt
281283
malloc_failure_mode_assert_then_assume = 2
282284
};
283285
284-
malloc_failure_modet malloc_failure_mode = malloc_failure_mode_none;
286+
malloc_failure_modet malloc_failure_mode = malloc_failure_mode_return_null;
285287
286288
static const std::size_t default_object_bits = 8;
287289

0 commit comments

Comments
 (0)