fix(small crates): the proof lint now covers every first-party crate but one

Six crates were still unguarded, and all six are OURS — none vendored: pf-console-ui, pf-gpu,
punktfunk-tray, clients/windows, tools/display-disturb, wdk-probe. Two of them ship (the tray and
the Windows client), so "small" was about item count, not exposure.

Five are closed here. Only 17 of their 75 unsafe items actually lacked a proof — pf-gpu,
punktfunk-tray and display-disturb were already fully documented and needed nothing but the deny,
which is the good case: the convention was being followed, just not enforced.

The 17 that were missing are the usual Win32/COM shapes, and two were worth stating properly.
`clients/windows`'s `GetCurrentPackageFullName` is called with `len = 0` and no buffer — that is the
documented identity PROBE, which writes nothing, and reading it as a normal query would be a
mistake. `pf-console-ui`'s two `destroy_image_view` calls are the load-bearing ones: the comment
above one already argued that in-flight sampling of that slot ended two presents ago (the ring
alternates and the presenter waits its fence before each record), which is exactly the kind of
reasoning a `// SAFETY:` should carry and it was sitting there unlabelled.

Also fixes a real Windows-only clippy error this uncovered: `pf-gpu` had a
`#[cfg(target_os = "windows")]` fn AFTER its `mod tests`, tripping `items_after_test_module`. It
never fired on Linux (the item does not exist there) and no CI job clippies pf-gpu on Windows, so it
sat unseen. Moved above the test module.

Remaining: `wdk-probe` (26 items) alone, and only because it needs the WDK to build — .47 cannot,
so nothing here can verify a deny on it.

Verified: Linux .21 fmt + both CI clippy steps rc=0; Windows .47 the four Windows-relevant crates at
`-D warnings` rc=0.
This commit is contained in:
2026-07-29 08:48:42 +02:00
parent 65cd388a52
commit 8a5a5edc37
10 changed files with 92 additions and 36 deletions
+3
View File
@@ -195,6 +195,9 @@ fn apply_window_icon_when_ready() {
};
let _ = std::thread::Builder::new()
.name("pf-window-icon".into())
// SAFETY: every call in this thread is a Win32 window/icon API taking either a static wide
// literal, a handle it just obtained and checked, or the module handle of this process; none
// of them dereference caller memory, and the loop gives up after 100 tries.
.spawn(|| unsafe {
for _ in 0..100 {
if let Ok(hwnd) = FindWindowW(None, windows::core::w!("Punktfunk")) {
+7
View File
@@ -10,6 +10,8 @@ use windows::Win32::Graphics::Dxgi::{CreateDXGIFactory1, IDXGIAdapter, IDXGIFact
/// The adapter's human-readable description.
fn adapter_name(adapter: &IDXGIAdapter) -> String {
// SAFETY: a read-only COM call on the live `adapter` borrow, filling a descriptor returned by
// value; `&IDXGIAdapter` is a reference-counted wrapper, so the borrow IS the liveness.
unsafe {
adapter
.GetDesc()
@@ -24,12 +26,16 @@ fn adapter_name(adapter: &IDXGIAdapter) -> String {
/// Every DXGI adapter, in enumeration order.
fn all_adapters() -> Vec<IDXGIAdapter> {
// SAFETY: DXGI factory creation takes no pointer and returns an owned factory or an error,
// matched on below before anything uses it.
let factory: IDXGIFactory1 = match unsafe { CreateDXGIFactory1() } {
Ok(f) => f,
Err(_) => return Vec::new(),
};
let mut v = Vec::new();
let mut i = 0u32;
// SAFETY: a COM call on the live factory above; it takes an index and yields an owned adapter,
// and the `Ok` pattern is what proves one came back.
while let Ok(a) = unsafe { factory.EnumAdapters1(i) } {
i += 1;
if let Ok(a) = a.cast::<IDXGIAdapter>() {
@@ -54,6 +60,7 @@ pub fn adapter_names() -> Vec<String> {
for a in all_adapters() {
let desc1 = a
.cast::<windows::Win32::Graphics::Dxgi::IDXGIAdapter1>()
// SAFETY: a read-only COM call on the adapter just cast, filling a descriptor by value.
.and_then(|a1| unsafe { a1.GetDesc1() })
.ok();
let name = adapter_name(&a);
+8
View File
@@ -14,6 +14,8 @@
//! punktfunk-client --headless --speed-test --connect host[:port]
//! (measure the path: probe burst → goodput / loss / recommended bitrate)
// Unsafe-proof program: every `unsafe {}` in this client carries a `// SAFETY:` proof.
#![deny(clippy::undocumented_unsafe_blocks)]
// Link as a GUI (windows) subsystem binary so the default windowed launch (MSIX / double-click)
// does NOT pop a console window. The CLI paths (--headless/--discover) reattach to the launching
// terminal's console at startup (see main), so their output is still visible when run from a shell.
@@ -49,6 +51,9 @@ fn main() {
// launch is window-free. AttachConsole only binds to an ALREADY-EXISTING parent console (it
// never creates one), so when launched from a terminal — `--headless`/`--discover` — stdout and
// the tracing writer below land in that terminal; from Explorer/MSIX it's a harmless no-op.
// SAFETY: `AttachConsole` takes a plain process-id constant and binds to an already-existing
// parent console; it allocates nothing and dereferences no caller memory, and failure (no parent
// console) is ignored by design.
unsafe {
use windows::Win32::System::Console::{AttachConsole, ATTACH_PARENT_PROCESS};
let _ = AttachConsole(ATTACH_PARENT_PROCESS);
@@ -170,6 +175,9 @@ fn set_app_user_model_id() {
use windows::Win32::Foundation::APPMODEL_ERROR_NO_PACKAGE;
use windows::Win32::Storage::Packaging::Appx::GetCurrentPackageFullName;
use windows::Win32::UI::Shell::SetCurrentProcessExplicitAppUserModelID;
// SAFETY: `GetCurrentPackageFullName` is called with `len = 0` and no buffer, which is the
// documented identity PROBE — it writes nothing and only reports whether this process is
// packaged; `SetCurrentProcessExplicitAppUserModelID` takes a static wide literal.
unsafe {
let mut len: u32 = 0;
// No buffer: just probe whether the process has package identity.
+8
View File
@@ -18,6 +18,9 @@ use windows::Win32::UI::WindowsAndMessaging::{
static SHELL_HWND: AtomicIsize = AtomicIsize::new(0);
fn shell_hwnd() -> Option<HWND> {
// SAFETY: the cached value is an `HWND` this process obtained itself; it is re-validated with
// `IsWindow` before use (a stale handle is treated as absent), and the lookup calls take only
// static wide literals.
unsafe {
let cached = SHELL_HWND.load(Ordering::Relaxed);
if cached != 0 {
@@ -37,6 +40,8 @@ fn shell_hwnd() -> Option<HWND> {
/// the shell in view with its error banner).
pub(crate) fn hide() {
if let Some(h) = shell_hwnd() {
// SAFETY: `h` is the validated shell window handle from `shell_hwnd`; `ShowWindow` takes it
// plus a plain flag and dereferences nothing.
unsafe {
let _ = ShowWindow(h, SW_HIDE);
}
@@ -47,6 +52,8 @@ pub(crate) fn hide() {
/// it was never hidden — showing a visible window is a no-op.
pub(crate) fn restore() {
if let Some(h) = shell_hwnd() {
// SAFETY: as `hide` — `h` is the validated shell window handle, and both calls take only
// that handle plus a plain flag.
unsafe {
let _ = ShowWindow(h, SW_SHOW);
let _ = SetForegroundWindow(h);
@@ -60,6 +67,7 @@ pub(crate) fn restore() {
pub(crate) fn position() -> Option<(i32, i32)> {
let h = shell_hwnd()?;
let mut r = RECT::default();
// SAFETY: `h` is the validated shell window handle and `r` is a live local the call fills.
unsafe { GetWindowRect(h, &mut r).ok()? };
Some((r.left, r.top))
}