mirror of
https://github.com/github/codeql.git
synced 2026-04-27 17:55:19 +02:00
Rust: Add data flow tests for operator overloading
This commit is contained in:
@@ -91,6 +91,37 @@ fn data_through_method() {
|
||||
sink(b); // $ hasValueFlow=4
|
||||
}
|
||||
|
||||
use std::ops::Add;
|
||||
|
||||
struct MyInt {
|
||||
value: i64,
|
||||
}
|
||||
|
||||
impl Add for MyInt {
|
||||
type Output = MyInt;
|
||||
|
||||
fn add(self, other: MyInt) -> MyInt {
|
||||
MyInt { value: self.value }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test_operator_overloading() {
|
||||
let a = MyInt { value: source(5) };
|
||||
let b = MyInt { value: 2 };
|
||||
let c = a + b;
|
||||
sink(c.value); // $ MISSING: hasValueFlow=5
|
||||
|
||||
let a = MyInt { value: source(6) };
|
||||
let b = MyInt { value: 2 };
|
||||
let d = b + a;
|
||||
sink(d.value);
|
||||
|
||||
let a = MyInt { value: source(7) };
|
||||
let b = MyInt { value: 2 };
|
||||
let d = a.add(b);
|
||||
sink(d.value); // $ MISSING: hasValueFlow=7
|
||||
}
|
||||
|
||||
fn main() {
|
||||
data_out_of_call();
|
||||
data_in_to_call();
|
||||
@@ -99,4 +130,6 @@ fn main() {
|
||||
data_out_of_method();
|
||||
data_in_to_method_call();
|
||||
data_through_method();
|
||||
|
||||
test_operator_overloading();
|
||||
}
|
||||
|
||||
@@ -19,9 +19,17 @@
|
||||
| main.rs:89:13:89:21 | source(...) | main.rs:1:1:3:1 | fn source |
|
||||
| main.rs:90:13:90:30 | mn.data_through(...) | main.rs:66:5:72:5 | fn data_through |
|
||||
| main.rs:91:5:91:11 | sink(...) | main.rs:5:1:7:1 | fn sink |
|
||||
| main.rs:95:5:95:22 | data_out_of_call(...) | main.rs:16:1:19:1 | fn data_out_of_call |
|
||||
| main.rs:96:5:96:21 | data_in_to_call(...) | main.rs:25:1:28:1 | fn data_in_to_call |
|
||||
| main.rs:97:5:97:23 | data_through_call(...) | main.rs:34:1:38:1 | fn data_through_call |
|
||||
| main.rs:99:5:99:24 | data_out_of_method(...) | main.rs:75:1:79:1 | fn data_out_of_method |
|
||||
| main.rs:100:5:100:28 | data_in_to_method_call(...) | main.rs:81:1:85:1 | fn data_in_to_method_call |
|
||||
| main.rs:101:5:101:25 | data_through_method(...) | main.rs:87:1:92:1 | fn data_through_method |
|
||||
| main.rs:109:28:109:36 | source(...) | main.rs:1:1:3:1 | fn source |
|
||||
| main.rs:112:5:112:17 | sink(...) | main.rs:5:1:7:1 | fn sink |
|
||||
| main.rs:114:28:114:36 | source(...) | main.rs:1:1:3:1 | fn source |
|
||||
| main.rs:117:5:117:17 | sink(...) | main.rs:5:1:7:1 | fn sink |
|
||||
| main.rs:119:28:119:36 | source(...) | main.rs:1:1:3:1 | fn source |
|
||||
| main.rs:121:13:121:20 | a.add(...) | main.rs:103:5:105:5 | fn add |
|
||||
| main.rs:122:5:122:17 | sink(...) | main.rs:5:1:7:1 | fn sink |
|
||||
| main.rs:126:5:126:22 | data_out_of_call(...) | main.rs:16:1:19:1 | fn data_out_of_call |
|
||||
| main.rs:127:5:127:21 | data_in_to_call(...) | main.rs:25:1:28:1 | fn data_in_to_call |
|
||||
| main.rs:128:5:128:23 | data_through_call(...) | main.rs:34:1:38:1 | fn data_through_call |
|
||||
| main.rs:130:5:130:24 | data_out_of_method(...) | main.rs:75:1:79:1 | fn data_out_of_method |
|
||||
| main.rs:131:5:131:28 | data_in_to_method_call(...) | main.rs:81:1:85:1 | fn data_in_to_method_call |
|
||||
| main.rs:132:5:132:25 | data_through_method(...) | main.rs:87:1:92:1 | fn data_through_method |
|
||||
| main.rs:134:5:134:31 | test_operator_overloading(...) | main.rs:108:1:123:1 | fn test_operator_overloading |
|
||||
|
||||
Reference in New Issue
Block a user