diagnostic: Fix stupid bug in Formatter::format
That would cause OOB reads. Fixed: tint:836 Change-Id: I6e44ab5d140e99a701c190c13ed6aaba762e19d4 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/53660 Auto-Submit: Ben Clayton <bclayton@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
224ce729cc
commit
b2a7d8b9b0
|
@ -212,7 +212,8 @@ void Formatter::format(const Diagnostic& diag, State& state) const {
|
||||||
state.set_style({Color::kDefault, false});
|
state.set_style({Color::kDefault, false});
|
||||||
|
|
||||||
for (size_t line_num = rng.begin.line;
|
for (size_t line_num = rng.begin.line;
|
||||||
(line_num <= rng.end.line) && (src.file_content->lines.size() + 1);
|
(line_num <= rng.end.line) &&
|
||||||
|
(line_num <= src.file_content->lines.size());
|
||||||
line_num++) {
|
line_num++) {
|
||||||
auto& line = src.file_content->lines[line_num - 1];
|
auto& line = src.file_content->lines[line_num - 1];
|
||||||
auto line_len = line.size();
|
auto line_len = line.size();
|
||||||
|
|
|
@ -216,6 +216,17 @@ the snail says ???
|
||||||
ASSERT_EQ(expect, got);
|
ASSERT_EQ(expect, got);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(DiagFormatterTest, RangeOOB) {
|
||||||
|
Formatter fmt{{true, true, true, true}};
|
||||||
|
diag::List list;
|
||||||
|
list.add_error("oob", Source{{{10, 20}, {30, 20}}, &file});
|
||||||
|
auto got = fmt.format(list);
|
||||||
|
auto* expect = R"(file.name:10:20 error: oob
|
||||||
|
|
||||||
|
)";
|
||||||
|
ASSERT_EQ(expect, got);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace diag
|
} // namespace diag
|
||||||
} // namespace tint
|
} // namespace tint
|
||||||
|
|
Loading…
Reference in New Issue