Skip to content

Commit bc30987

Browse files
author
Joel Allred
authored
Merge pull request #1235 from romainbrenguier/feature/string-max-input-length#948
String max input length option
2 parents 0323ed0 + 621da87 commit bc30987

18 files changed

+173
-107
lines changed
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
MemberTest.class
3+
--refine-strings --string-max-length 29 --java-assume-inputs-non-null
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public class MemberTest {
2+
String foo;
3+
public void main() {
4+
// Causes this function to be ignored if string-max-length is
5+
// less than 40
6+
String t = new String("0123456789012345678901234567890123456789");
7+
assert foo != null && foo.length() < 30;
8+
}
9+
}
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class Test {
2+
public static void main(String s) {
3+
// This prevent anything from happening if string-max-length is smaller
4+
// than 40
5+
String t = new String("0123456789012345678901234567890123456789");
6+
if (s.length() >= 30)
7+
// This should not happen when string-max-input length is smaller
8+
// than 30
9+
assert false;
10+
}
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
Test.class
3+
--refine-strings --string-max-length 30
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
Test.class
3+
--refine-strings --string-max-length 45 --string-max-input-length 31
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
Test.class
3+
--refine-strings --string-max-length 45 --string-max-input-length 20
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--

src/cbmc/cbmc_parse_options.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -793,11 +793,16 @@ bool cbmc_parse_optionst::process_goto_program(
793793
// Similar removal of java nondet statements:
794794
// TODO Should really get this from java_bytecode_language somehow, but we
795795
// don't have an instance of that here.
796-
const size_t max_nondet_array_length=
796+
object_factory_parameterst factory_params;
797+
factory_params.max_nondet_array_length=
797798
cmdline.isset("java-max-input-array-length")
798799
? std::stoul(cmdline.get_value("java-max-input-array-length"))
799800
: MAX_NONDET_ARRAY_LENGTH_DEFAULT;
800-
const size_t max_nondet_tree_depth=
801+
factory_params.max_nondet_string_length=
802+
cmdline.isset("string-max-input-length")
803+
? std::stoul(cmdline.get_value("string-max-input-length"))
804+
: MAX_NONDET_STRING_LENGTH;
805+
factory_params.max_nondet_tree_depth=
801806
cmdline.isset("java-max-input-tree-depth")
802807
? std::stoul(cmdline.get_value("java-max-input-tree-depth"))
803808
: MAX_NONDET_TREE_DEPTH;
@@ -807,8 +812,7 @@ bool cbmc_parse_optionst::process_goto_program(
807812
convert_nondet(
808813
goto_model,
809814
get_message_handler(),
810-
max_nondet_array_length,
811-
max_nondet_tree_depth);
815+
factory_params);
812816

813817
// add generic checks
814818
status() << "Generic Property Instrumentation" << eom;
@@ -1067,7 +1071,8 @@ void cbmc_parse_optionst::help()
10671071
" --refine-strings use string refinement (experimental)\n"
10681072
" --string-non-empty add constraint that strings are non empty (experimental)\n" // NOLINT(*)
10691073
" --string-printable add constraint that strings are printable (experimental)\n" // NOLINT(*)
1070-
" --string-max-length add constraint on the length of strings (experimental)\n" // NOLINT(*)
1074+
" --string-max-length add constraint on the length of strings\n" // NOLINT(*)
1075+
" --string-max-input-length add constraint on the length of input strings\n" // NOLINT(*)
10711076
" --outfile filename output formula to given file\n"
10721077
" --arrays-uf-never never turn arrays into uninterpreted functions\n" // NOLINT(*)
10731078
" --arrays-uf-always always turn arrays into uninterpreted functions\n" // NOLINT(*)

src/cbmc/cbmc_parse_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class optionst;
4848
"(string-non-empty)" \
4949
"(string-printable)" \
5050
"(string-max-length):" \
51+
"(string-max-input-length):" \
5152
"(aig)(16)(32)(64)(LP64)(ILP64)(LLP64)(ILP32)(LP32)" \
5253
"(little-endian)(big-endian)" \
5354
"(show-goto-functions)(show-loops)" \

0 commit comments

Comments
 (0)