From cfe-commits Sun Jan 26 18:18:27 2014 From: Olivier Goffart Date: Sun, 26 Jan 2014 18:18:27 +0000 To: cfe-commits Subject: [PATCH] Fix crash in comments::Sema::checkDeprecatedCommand Message-Id: <1641863.3YTRKMr479 () finn> X-MARC-Message: https://marc.info/?l=cfe-commits&m=139076049605077 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--nextPart2630852.MVdc5ZYN2p" This is a multi-part message in MIME format. --nextPart2630852.MVdc5ZYN2p Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" --nextPart2630852.MVdc5ZYN2p Content-Disposition: attachment; filename="0001-CommentParser-Fix-crash-in-parsing-deprecated-comman.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0001-CommentParser-Fix-crash-in-parsing-deprecated-comman.patch" From 44f9deeecbcdef32096f0ac692be80ab9dd17fae Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Sun, 26 Jan 2014 19:10:59 +0100 Subject: [PATCH] CommentParser: Fix crash in parsing @deprecated command If there is no declaration, ThisDeclInfo is 0. All the others function check if ThisDeclInfo is not null, so should checkDeprecatedCommand. --- lib/AST/CommentSema.cpp | 3 +++ unittests/AST/CommentParser.cpp | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/AST/CommentSema.cpp b/lib/AST/CommentSema.cpp index d324c5c..2400ecc 100644 --- a/lib/AST/CommentSema.cpp +++ b/lib/AST/CommentSema.cpp @@ -636,6 +636,9 @@ void Sema::checkDeprecatedCommand(const BlockCommandComment *Command) { if (!Traits.getCommandInfo(Command->getCommandID())->IsDeprecatedCommand) return; + if (!ThisDeclInfo) + return; + const Decl *D = ThisDeclInfo->CommentDecl; if (!D) return; diff --git a/unittests/AST/CommentParser.cpp b/unittests/AST/CommentParser.cpp index f75c636..6f2824b 100644 --- a/unittests/AST/CommentParser.cpp +++ b/unittests/AST/CommentParser.cpp @@ -1420,6 +1420,20 @@ TEST_F(CommentParserTest, VerbatimLine2) { } } +TEST_F(CommentParserTest, Deprecated) { + const char *Sources[] = { + "/** @deprecated */", + "/// @deprecated \n" + }; + + for (size_t i = 0, e = array_lengthof(Sources); i != e; i++) { + FullComment *FC = parseString(Sources[i]); + ASSERT_TRUE(HasChildCount(FC, 2)); + + ASSERT_TRUE(HasParagraphCommentAt(FC, 0, " ")); + } +} + } // unnamed namespace } // end namespace comments -- 1.8.5.3 --nextPart2630852.MVdc5ZYN2p Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits --nextPart2630852.MVdc5ZYN2p--