mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Fix handling of null StringRef file buffers (#5428)
The current behavior hits UBSAN and ASAN issues. Note, `RequiresNullTerminator` is already set to `false` in `source_buffer.cpp`; setting it in `compile_helper.cpp` is making things more consistent. The related logic is an [assert fail](https://github.com/llvm/llvm-project/blob/main/llvm/lib/Support/MemoryBuffer.cpp#L52). This was fuzzer-discovered.
This commit is contained in:
@@ -50,6 +50,14 @@ TEST_F(LexerTest, HandlesEmptyBuffer) {
|
||||
{.kind = TokenKind::FileEnd}}));
|
||||
}
|
||||
|
||||
TEST_F(LexerTest, NullStringRef) {
|
||||
auto& buffer = compile_helper_.GetTokenizedBuffer(llvm::StringRef());
|
||||
EXPECT_FALSE(buffer.has_errors());
|
||||
EXPECT_THAT(buffer, HasTokens(llvm::ArrayRef<ExpectedToken>{
|
||||
{.kind = TokenKind::FileStart},
|
||||
{.kind = TokenKind::FileEnd}}));
|
||||
}
|
||||
|
||||
TEST_F(LexerTest, TracksLinesAndColumns) {
|
||||
auto& buffer = compile_helper_.GetTokenizedBuffer(
|
||||
"\n ;;\n ;;;\n x\"foo\" '''baz\n a\n ''' y");
|
||||
|
||||
Reference in New Issue
Block a user