mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 21:31:24 +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:
@@ -40,6 +40,11 @@ TEST_F(TreeTest, IsValid) {
|
||||
EXPECT_TRUE((*tree.postorder().begin()).has_value());
|
||||
}
|
||||
|
||||
TEST_F(TreeTest, NullStringRef) {
|
||||
Tree& tree = compile_helper_.GetTree(llvm::StringRef());
|
||||
EXPECT_TRUE((*tree.postorder().begin()).has_value());
|
||||
}
|
||||
|
||||
TEST_F(TreeTest, AsAndTryAs) {
|
||||
auto [tokens, tree_and_subtrees] =
|
||||
compile_helper_.GetTokenizedBufferWithTreeAndSubtrees("fn F();");
|
||||
|
||||
Reference in New Issue
Block a user