Add tests for double destroying various pthread items
This commit is contained in:
parent
ae120563cc
commit
f0d915703c
4 changed files with 80 additions and 0 deletions
22
tests/compile-fail/sync/libc_pthread_cond_double_destroy.rs
Normal file
22
tests/compile-fail/sync/libc_pthread_cond_double_destroy.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// ignore-windows: No libc on Windows
|
||||
#![feature(rustc_private)]
|
||||
|
||||
/// Test that destroying a pthread_cond twice fails, even without a check for number validity
|
||||
extern crate libc;
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
use core::mem::MaybeUninit;
|
||||
let mut attr = MaybeUninit::<libc::pthread_condattr_t>::uninit();
|
||||
libc::pthread_condattr_init(attr.as_mut_ptr());
|
||||
|
||||
let mut cond = MaybeUninit::<libc::pthread_cond_t>::uninit();
|
||||
|
||||
libc::pthread_cond_init(cond.as_mut_ptr(), attr.as_ptr());
|
||||
|
||||
libc::pthread_cond_destroy(cond.as_mut_ptr());
|
||||
|
||||
libc::pthread_cond_destroy(cond.as_mut_ptr());
|
||||
//~^ Undefined Behavior: using uninitialized data, but this operation requires initialized memory
|
||||
}
|
||||
}
|
||||
23
tests/compile-fail/sync/libc_pthread_mutex_double_destroy.rs
Normal file
23
tests/compile-fail/sync/libc_pthread_mutex_double_destroy.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// ignore-windows: No libc on Windows
|
||||
#![feature(rustc_private)]
|
||||
|
||||
/// Test that destroying a pthread_mutex twice fails, even without a check for number validity
|
||||
extern crate libc;
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
use core::mem::MaybeUninit;
|
||||
|
||||
let mut attr = MaybeUninit::<libc::pthread_mutexattr_t>::uninit();
|
||||
libc::pthread_mutexattr_init(attr.as_mut_ptr());
|
||||
|
||||
let mut mutex = MaybeUninit::<libc::pthread_mutex_t>::uninit();
|
||||
|
||||
libc::pthread_mutex_init(mutex.as_mut_ptr(), attr.as_ptr());
|
||||
|
||||
libc::pthread_mutex_destroy(mutex.as_mut_ptr());
|
||||
|
||||
libc::pthread_mutex_destroy(mutex.as_mut_ptr());
|
||||
//~^ Undefined Behavior: using uninitialized data, but this operation requires initialized memory
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
// ignore-windows: No libc on Windows
|
||||
#![feature(rustc_private)]
|
||||
|
||||
/// Test that destroying a pthread_mutexattr twice fails, even without a check for number validity
|
||||
extern crate libc;
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
use core::mem::MaybeUninit;
|
||||
let mut attr = MaybeUninit::<libc::pthread_mutexattr_t>::uninit();
|
||||
|
||||
libc::pthread_mutexattr_init(attr.as_mut_ptr());
|
||||
|
||||
libc::pthread_mutexattr_destroy(attr.as_mut_ptr());
|
||||
|
||||
libc::pthread_mutexattr_destroy(attr.as_mut_ptr());
|
||||
//~^ Undefined Behavior: using uninitialized data, but this operation requires initialized memory
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
// ignore-windows: No libc on Windows
|
||||
#![feature(rustc_private)]
|
||||
|
||||
/// Test that destroying a pthread_rwlock twice fails, even without a check for number validity
|
||||
extern crate libc;
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
let mut lock = libc::PTHREAD_RWLOCK_INITIALIZER;
|
||||
|
||||
libc::pthread_rwlock_destroy(&mut lock);
|
||||
|
||||
libc::pthread_rwlock_destroy(&mut lock);
|
||||
//~^ Undefined Behavior: using uninitialized data, but this operation requires initialized memory
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue