Rust: Also add the good example and a couple of other cited good cases to the test.

This commit is contained in:
Geoffrey White
2024-11-25 14:57:30 +00:00
parent 82f2c6075f
commit be5bd1da0a
3 changed files with 25 additions and 1 deletions

View File

@@ -7,4 +7,4 @@
| test.rs:67:4:67:9 | bad2_4 | This function has the $@ attribute but calls $@ in the standard library. | test.rs:66:1:66:7 | Attr | Attr | test.rs:69:9:69:24 | ...::stdin(...) | ...::stdin(...) |
| test.rs:89:4:89:9 | bad2_7 | This function has the $@ attribute but calls $@ in the standard library. | test.rs:88:1:88:7 | Attr | Attr | test.rs:90:5:90:35 | ...::sleep(...) | ...::sleep(...) |
| test.rs:96:4:96:9 | bad2_8 | This function has the $@ attribute but calls $@ in the standard library. | test.rs:95:1:95:7 | Attr | Attr | test.rs:97:5:97:23 | ...::exit(...) | ...::exit(...) |
| test.rs:142:4:142:9 | bad4_1 | This function has the $@ attribute but calls $@ in the standard library. | test.rs:141:1:141:7 | Attr | Attr | test.rs:143:5:143:15 | ...::stdout(...) | ...::stdout(...) |
| test.rs:165:4:165:9 | bad4_1 | This function has the $@ attribute but calls $@ in the standard library. | test.rs:164:1:164:7 | Attr | Attr | test.rs:166:5:166:15 | ...::stdout(...) | ...::stdout(...) |

View File

@@ -1,3 +1,4 @@
qltest_cargo_check: true
qltest_dependencies:
- ctor = { version = "0.2.9" }
- libc-print = { version = "0.1.23" }

View File

@@ -97,6 +97,29 @@ fn bad2_8() { // $ Alert[rust/ctor-initialization]
process::exit(1234);
}
#[ctor::ctor]
fn harmless2_9() {
libc_print::libc_println!("Hello, world!"); // does not use the std library
}
#[ctor::ctor]
fn harmless2_10() {
core::assert!(true); // core library should be OK in this context
}
extern crate alloc;
use alloc::alloc::{alloc, dealloc, Layout};
#[ctor::ctor]
unsafe fn harmless2_11() {
let layout = Layout::new::<u64>();
let ptr = alloc(layout); // alloc library should be OK in this context
if !ptr.is_null() {
dealloc(ptr, layout);
}
}
// --- transitive cases ---
fn call_target3_1() {