diff options
| author | bors <bors@rust-lang.org> | 2019-06-17 23:30:37 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-06-17 23:30:37 +0000 |
| commit | 9f22ddf6bb7001b884006b9528f8fc8c5b94ae8f (patch) | |
| tree | f1dc22e419adbdb3e281ab35975a513846fdde2e /src/libsyntax_pos | |
| parent | b25ee644971a168287ee166edbd11642dbcfeab8 (diff) | |
| parent | 6fe265315626be4f5c3116217dfebd4435fbc14e (diff) | |
| download | rust-9f22ddf6bb7001b884006b9528f8fc8c5b94ae8f.tar.gz rust-9f22ddf6bb7001b884006b9528f8fc8c5b94ae8f.zip | |
Auto merge of #61915 - Centril:rollup-oire3i8, r=Centril
Rollup of 5 pull requests Successful merges: - #61702 (test more variants of enum-int-casting) - #61836 (Replace some uses of NodeId with HirId) - #61885 (Help LLVM better optimize slice::Iter(Mut)::len) - #61893 (make `Weak::ptr_eq`s into methods) - #61908 (don't ICE on large files) Failed merges: r? @ghost
Diffstat (limited to 'src/libsyntax_pos')
| -rw-r--r-- | src/libsyntax_pos/lib.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index e7158372762..2dd409bf5be 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -859,6 +859,9 @@ impl ExternalSource { } } +#[derive(Debug)] +pub struct OffsetOverflowError; + /// A single source in the `SourceMap`. #[derive(Clone)] pub struct SourceFile { @@ -1040,7 +1043,7 @@ impl SourceFile { name_was_remapped: bool, unmapped_path: FileName, mut src: String, - start_pos: BytePos) -> SourceFile { + start_pos: BytePos) -> Result<SourceFile, OffsetOverflowError> { remove_bom(&mut src); let src_hash = { @@ -1054,11 +1057,14 @@ impl SourceFile { hasher.finish() }; let end_pos = start_pos.to_usize() + src.len(); + if end_pos > u32::max_value() as usize { + return Err(OffsetOverflowError); + } let (lines, multibyte_chars, non_narrow_chars) = analyze_source_file::analyze_source_file(&src[..], start_pos); - SourceFile { + Ok(SourceFile { name, name_was_remapped, unmapped_path: Some(unmapped_path), @@ -1072,7 +1078,7 @@ impl SourceFile { multibyte_chars, non_narrow_chars, name_hash, - } + }) } /// Returns the `BytePos` of the beginning of the current line. |
