[PATCH] D91462: [YAMLIO] Correctly diagnose empty alias/anchor
Scott Linder via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 13 14:09:28 PST 2020
scott.linder created this revision.
Herald added subscribers: llvm-commits, dexonsmith, hiraditya.
Herald added a project: LLVM.
scott.linder requested review of this revision.
The `Range` of an alias/anchor token includes the leading `&` or `*`,
but it is skipped while parsing the name. The check for an empty name
fails to account for the skipped leading character and so the error is
never hit.
Fix the off-by-one and add a couple regression tests.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D91462
Files:
llvm/lib/Support/YAMLParser.cpp
llvm/unittests/Support/YAMLIOTest.cpp
Index: llvm/unittests/Support/YAMLIOTest.cpp
===================================================================
--- llvm/unittests/Support/YAMLIOTest.cpp
+++ llvm/unittests/Support/YAMLIOTest.cpp
@@ -3101,3 +3101,15 @@
EXPECT_FALSE(yin2.setCurrentDocument());
EXPECT_TRUE(yin2.error());
}
+
+TEST(YAMLIO, TestEmptyAlias) {
+ Input yin("&");
+ EXPECT_FALSE(yin.setCurrentDocument());
+ EXPECT_TRUE(yin.error());
+}
+
+TEST(YAMLIO, TestEmptyAnchor) {
+ Input yin("*");
+ EXPECT_FALSE(yin.setCurrentDocument());
+ EXPECT_TRUE(yin.error());
+}
Index: llvm/lib/Support/YAMLParser.cpp
===================================================================
--- llvm/lib/Support/YAMLParser.cpp
+++ llvm/lib/Support/YAMLParser.cpp
@@ -1423,7 +1423,7 @@
++Column;
}
- if (Start == Current) {
+ if (Start + 1 == Current) {
setError("Got empty alias or anchor", Start);
return false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91462.305262.patch
Type: text/x-patch
Size: 910 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201113/ea608197/attachment.bin>
More information about the llvm-commits
mailing list