Auto merge of #76598 - ad-anssi:diagnostic_errors_fix, r=estebank
Fixing memory exhaustion when formatting short code suggestion Details can be found in issue #76597. This PR replaces substractions with `saturating_sub`'s to avoid usize wrapping leading to memory exhaustion when formatting short suggestion messages.
This commit is contained in:
commit
17d3277064
5 changed files with 43 additions and 4 deletions
|
@ -959,15 +959,15 @@ impl EmitterWriter {
|
||||||
'_',
|
'_',
|
||||||
line_offset + pos,
|
line_offset + pos,
|
||||||
width_offset + depth,
|
width_offset + depth,
|
||||||
code_offset + annotation.start_col - left,
|
(code_offset + annotation.start_col).saturating_sub(left),
|
||||||
style,
|
style,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_ if self.teach => {
|
_ if self.teach => {
|
||||||
buffer.set_style_range(
|
buffer.set_style_range(
|
||||||
line_offset,
|
line_offset,
|
||||||
code_offset + annotation.start_col - left,
|
(code_offset + annotation.start_col).saturating_sub(left),
|
||||||
code_offset + annotation.end_col - left,
|
(code_offset + annotation.end_col).saturating_sub(left),
|
||||||
style,
|
style,
|
||||||
annotation.is_primary,
|
annotation.is_primary,
|
||||||
);
|
);
|
||||||
|
|
|
@ -694,9 +694,13 @@ impl<'a> Parser<'a> {
|
||||||
Ok(t) => {
|
Ok(t) => {
|
||||||
// Parsed successfully, therefore most probably the code only
|
// Parsed successfully, therefore most probably the code only
|
||||||
// misses a separator.
|
// misses a separator.
|
||||||
|
let mut exp_span = self.sess.source_map().next_point(sp);
|
||||||
|
if self.sess.source_map().is_multiline(exp_span) {
|
||||||
|
exp_span = sp;
|
||||||
|
}
|
||||||
expect_err
|
expect_err
|
||||||
.span_suggestion_short(
|
.span_suggestion_short(
|
||||||
self.sess.source_map().next_point(sp),
|
exp_span,
|
||||||
&format!("missing `{}`", token_str),
|
&format!("missing `{}`", token_str),
|
||||||
token_str,
|
token_str,
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
|
|
11
src/test/ui/issue-76597.fixed
Normal file
11
src/test/ui/issue-76597.fixed
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
// run-rustfix
|
||||||
|
|
||||||
|
#![allow(dead_code)]
|
||||||
|
#![allow(unused_variables)]
|
||||||
|
fn f(
|
||||||
|
x: u8,
|
||||||
|
y: u8,
|
||||||
|
) {}
|
||||||
|
//~^^ ERROR: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `y`
|
||||||
|
|
||||||
|
fn main() {}
|
11
src/test/ui/issue-76597.rs
Normal file
11
src/test/ui/issue-76597.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
// run-rustfix
|
||||||
|
|
||||||
|
#![allow(dead_code)]
|
||||||
|
#![allow(unused_variables)]
|
||||||
|
fn f(
|
||||||
|
x: u8
|
||||||
|
y: u8,
|
||||||
|
) {}
|
||||||
|
//~^^ ERROR: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `y`
|
||||||
|
|
||||||
|
fn main() {}
|
13
src/test/ui/issue-76597.stderr
Normal file
13
src/test/ui/issue-76597.stderr
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
error: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `y`
|
||||||
|
--> $DIR/issue-76597.rs:7:38
|
||||||
|
|
|
||||||
|
LL | ... x: u8
|
||||||
|
| -
|
||||||
|
| |
|
||||||
|
| expected one of 7 possible tokens
|
||||||
|
| help: missing `,`
|
||||||
|
LL | ... y: u8,
|
||||||
|
| ^ unexpected token
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue