Skip to content

main.rs:1925: lossy u128→u64 cast for elapsed duration #591

@EffortlessSteven

Description

@EffortlessSteven

Location: crates/diffguard/src/main.rs:1925

Problem:

let duration_ms = start_time.elapsed().as_millis() as u64;

Duration::as_millis() returns u128. The as u64 cast silently truncates on targets where the elapsed duration exceeds u64::MAX milliseconds. This is distinct from the i64→u64 sign cast at line 2609 (covered by issue #582).

Fix: Use try_into() with a checked/saturated conversion:

let duration_ms = u64::try_from(start_time.elapsed().as_millis())
    .unwrap_or(u64::MAX);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions