Skip to content

Commit b43cae6

Browse files
Fix a bunch of crashes discovered by fuzzing cppfront (#1383)
* Three more fuzz crashes. * Add regression test for crash 10. * Error instead of crash if users write silly things in aliases. * Fix assertion on comments near end of file. * Disallow declarations of parents after functions. * Fix more fuzz crashes. * Rename error test cases to `*-error.cpp2` * Minor tidying to fit house style `exit(1)` -> `exit(EXIT_FAILURE)` Branch and loop bodies are always enclosed in `{` `}` even when they contain a single line --------- Co-authored-by: Herb Sutter <[email protected]>
1 parent 2f3634d commit b43cae6

29 files changed

+242
-40
lines changed

include/cpp2util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ class contract_group {
561561
std::cerr << ": " << msg;
562562
}
563563
std::cerr << "\n";
564-
std::terminate();
564+
std::exit(EXIT_FAILURE);
565565
}
566566

567567
auto inline cpp2_default = contract_group(
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#else
2+
#else
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
crash_10: (foo: i32) = {
2+
assert( 10LL as i32 == foo$);
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
crash_10: (foo: i32) = {
2+
assert( 10LL as i32 == foo$);
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
crash_89: () = {
2+
f := new<int>(0);
3+
_ = f is decltype.f);
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print: <T: type> (inout out: std::ostream=args: T) requires true = {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
crash_m0b: type = {
2+
}
3+
4+
crash_m0c: type = {
5+
name: i32;
6+
get_name: (this) -> i32 = { return name; }
7+
this: crash_m0b;
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
outer: type = {
2+
x: requires true == 42;
3+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
main: () -> int = {
3+
x := crash_m0();
4+
_ = x;
5+
}
6+
7+
crash_m0: type = {
8+
operator-: (this, _) -> int = 0;/* Comment starts here
9+
And continues here
10+
*/
11+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
main: () = {
2+
e: unsigned char
3+
}

0 commit comments

Comments
 (0)