-
Notifications
You must be signed in to change notification settings - Fork 5
/
0142-toodee.rs
87 lines (67 loc) · 1.73 KB
/
0142-toodee.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*!
```rudra-poc
[target]
crate = "toodee"
version = "0.2.1"
[report]
issue_date = 2021-02-19
issue_url = "https://github.com/antonmarsden/toodee/issues/13"
rustsec_url = "https://github.com/RustSec/advisory-db/pull/784"
rustsec_id = "RUSTSEC-2021-0028"
[[bugs]]
analyzer = "UnsafeDataflow"
bug_class = "PanicSafety"
rudra_report_locations = ['src/toodee.rs:561:5: 590:6']
[[bugs]]
analyzer = "UnsafeDataflow"
bug_class = "HigherOrderInvariant"
rudra_report_locations = ['src/toodee.rs:561:5: 590:6']
```
!*/
#![forbid(unsafe_code)]
use toodee::TooDee;
struct DropDetector(u32);
impl Drop for DropDetector {
fn drop(&mut self) {
println!("Dropping {}", self.0);
}
}
// An iterator that panics.
// -----
struct PanickingIterator();
impl Iterator for PanickingIterator {
type Item = DropDetector;
fn next(&mut self) -> Option<Self::Item> {
panic!("Iterator panicked");
}
}
impl ExactSizeIterator for PanickingIterator {
fn len(&self) -> usize {
1
}
}
// -----
fn main() {
reserves_based_on_iterator_length();
//let vec = vec![DropDetector(1), DropDetector(2), DropDetector(3)];
//let mut toodee : TooDee<_> = TooDee::from_vec(1, 3, vec);
//toodee.insert_row(0, PanickingIterator());
}
struct IteratorWithWrongLength();
impl Iterator for IteratorWithWrongLength {
type Item = Box<u8>;
fn next(&mut self) -> Option<Self::Item> {
None
}
}
impl ExactSizeIterator for IteratorWithWrongLength {
fn len(&self) -> usize {
1
}
}
fn reserves_based_on_iterator_length() {
let vec = vec![Box::<u8>::new(1)];
let mut toodee: TooDee<_> = TooDee::from_vec(1, 1, vec);
toodee.insert_row(1, IteratorWithWrongLength());
println!("{}", toodee[1][0]);
}