1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02: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. 

llvm-svn: 237942
This commit is contained in:
Alex Lorenz 2015-05-21 19:45:02 +00:00
parent dda6a07fcf
commit c25022ea5f
2 changed files with 14 additions and 1 deletions

View File

@ -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);

View File

@ -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", "[\" ");