mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-04-09 01:38:03 +00:00
YAML: Null terminate block scalar's value.
The commit null terminates the string value in the `yaml::BlockScalarNode` class. This change is motivated by the initial MIR serialization commit (r237708) that I reverted in r237730 because the LLVM IR source from the block scalar node wasn't terminated by a null character and thus the buildbots failed on one testcase sometimes. This change enables me to recommit the reverted commit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237942 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
7e452b8b73
commit
802ab073da
@ -2379,7 +2379,8 @@ parse_property:
|
||||
, T.Range);
|
||||
case Token::TK_BlockScalar: {
|
||||
getNext();
|
||||
StringRef StrCopy = StringRef(T.Value).copy(NodeAllocator);
|
||||
StringRef NullTerminatedStr(T.Value.c_str(), T.Value.length() + 1);
|
||||
StringRef StrCopy = NullTerminatedStr.copy(NodeAllocator).drop_back();
|
||||
return new (NodeAllocator)
|
||||
BlockScalarNode(stream.CurrentDoc, AnchorInfo.Range.substr(1),
|
||||
TagInfo.Range, StrCopy, T.Range);
|
||||
|
@ -157,6 +157,18 @@ TEST(YAMLParser, ParsesBlockLiteralScalars) {
|
||||
ExpectParseError("Long leading space line", "test: |\n \n Test\n");
|
||||
}
|
||||
|
||||
TEST(YAMLParser, NullTerminatedBlockScalars) {
|
||||
SourceMgr SM;
|
||||
yaml::Stream Stream("test: |\n Hello\n World\n", SM);
|
||||
yaml::Document &Doc = *Stream.begin();
|
||||
yaml::MappingNode *Map = cast<yaml::MappingNode>(Doc.getRoot());
|
||||
StringRef Value =
|
||||
cast<yaml::BlockScalarNode>(Map->begin()->getValue())->getValue();
|
||||
|
||||
EXPECT_EQ(Value, "Hello\nWorld\n");
|
||||
EXPECT_EQ(Value.data()[Value.size()], '\0');
|
||||
}
|
||||
|
||||
TEST(YAMLParser, HandlesEndOfFileGracefully) {
|
||||
ExpectParseError("In string starting with EOF", "[\"");
|
||||
ExpectParseError("In string hitting EOF", "[\" ");
|
||||
|
Loading…
x
Reference in New Issue
Block a user