0xMiden / 0xMiden/miden-diagnostics

SourceFile location and source_slice panic with subtract overflow on empty files

Offen
#7 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Rust
Sterne
0
Forks
4
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

`SourceFile::location()` and `SourceFile::source_slice()` can panic for empty source files while building their `IndexTooLarge` errors.

File evidence:

- `diagnostics/src/source.rs` computes `self.source().len() - 1` in `location()` when `line_start()` fails.
- The same `len() - 1` pattern is used in the `location()` invalid-slice error path.
- `source_slice()` also computes `self.source().len() - 1` when the requested range is invalid.

For an empty file, `self.source().len()` is `0`, so these error paths underflow before returning the expected `Result::Err`. Empty files are reasonable inputs for diagnostics tooling, parsers, and editor integrations.

Expected behavior: out-of-range locations/slices for empty files should return `Error::IndexTooLarge` rather than panicking with subtract overflow.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.