[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kdevelop-bugs
Subject:    [Bug 258972] Crash when parsing incomplete #include
From:       Milian Wolff <mail () milianw ! de>
Date:       2010-12-06 11:03:23
Message-ID: 20101206110323.DD7B776E43 () immanuel ! kde ! org
[Download RAW message or body]

https://bugs.kde.org/show_bug.cgi?id=258972


Milian Wolff <mail@milianw.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




--- Comment #1 from Milian Wolff <mail milianw de>  2010-12-06 12:03:21 ---
commit bbcc13aa26ae85976357355367d14b2f29b52b6b
branch master
Author: Milian Wolff <mail@milianw.de>
Date:   Mon Dec 6 12:02:24 2010 +0100

    don't crash/assert on empty include directives

    BUG: 258972

diff --git a/languages/cpp/parser/rpp/pp-engine.cpp
b/languages/cpp/parser/rpp/pp-engine.cpp
index 0336a03..2d0e9ea 100644
--- a/languages/cpp/parser/rpp/pp-engine.cpp
+++ b/languages/cpp/parser/rpp/pp-engine.cpp
@@ -155,6 +155,10 @@ void pp::handle_directive(uint directive, Stream& input,
Stream& output)

 void pp::handle_include(bool skip_current_path, Stream& input, Stream& output)
 {
+  if (input.atEnd()) {
+    createProblem(input, i18n("invalid include directive"));
+    return;
+  }
   QByteArray bytes =
KDevelop::IndexedString::fromIndex(input.current()).byteArray();
   if (bytes.size() > 0 && (isLetter(bytes.at(0)) || bytes.at(0) == '_')) {
     pp_macro_expander expand_include(this);
diff --git a/languages/cpp/parser/tests/test_parser.cpp
b/languages/cpp/parser/tests/test_parser.cpp
index c03ede3..b4dddc2 100644
--- a/languages/cpp/parser/tests/test_parser.cpp
+++ b/languages/cpp/parser/tests/test_parser.cpp
@@ -458,7 +458,6 @@ private slots:

   void testStringConcatenation()
   {
-    rpp::Preprocessor preprocessor;
     QCOMPARE(preprocess("Hello##You"), QString("HelloYou"));
     QCOMPARE(preprocess("#define CONCAT(Var1, Var2) Var1##Var2\nCONCAT(var1,
)").trimmed(), QString("var1"));
     QCOMPARE(preprocess("#define CONCAT(Var1, Var2) Var1##Var2\nCONCAT(,
var2)").trimmed(), QString("var2"));
@@ -470,6 +469,18 @@ private slots:
     QCOMPARE(preprocess("#define GLUE(a, b, c) k ## l ## m\nGLUE(a, b,
c)").trimmed(), QString("klm"));
   }

+  void testEmptyInclude()
+  {
+    // testcase for https://bugs.kde.org/show_bug.cgi?id=258972
+    rpp::Preprocessor preprocessor;
+    rpp::pp pp(&preprocessor);
+    pp.processFile("anonymous", QByteArray("#include\n\nint main(){\n   
;\n}\n"));
+    QCOMPARE(pp.problems().count(), 1);
+    qDebug() << pp.problems().first()->description();
+    QCOMPARE(pp.problems().first()->finalLocation().start,
KDevelop::SimpleCursor(0, 8));
+    QCOMPARE(pp.problems().first()->finalLocation().end,
KDevelop::SimpleCursor(0, 8));
+  }
+
   void testCondition()
   {
     QByteArray method("bool i = (small < big || big > small);");

-- 
Configure bugmail: https://bugs.kde.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

_______________________________________________
KDevelop-bugs mailing list
KDevelop-bugs@kdevelop.org
https://barney.cs.uni-potsdam.de/mailman/listinfo/kdevelop-bugs
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic