diff options
author | Hugo Lima <hugo.lima@openbossa.org> | 2009-10-29 20:02:53 -0200 |
---|---|---|
committer | Hugo Lima <hugo.lima@openbossa.org> | 2009-10-29 20:02:53 -0200 |
commit | 5ccbce7a917a2a602ad1fa32d8682afe32dd68bc (patch) | |
tree | 942b5597debf365a140c072816cb2726782937b6 | |
parent | 64f7ae3334171168ff803f339d55a179a6e06001 (diff) |
Fix a crash when the function signature provided by add-function tag does not
have parenteses.
Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
-rw-r--r-- | tests/testaddfunction.cpp | 8 | ||||
-rw-r--r-- | tests/testaddfunction.h | 1 | ||||
-rw-r--r-- | typesystem.cpp | 27 |
3 files changed, 25 insertions, 11 deletions
diff --git a/tests/testaddfunction.cpp b/tests/testaddfunction.cpp index 0637eb5c9..d02fc67e1 100644 --- a/tests/testaddfunction.cpp +++ b/tests/testaddfunction.cpp @@ -144,6 +144,14 @@ void TestAddFunction::testAddFunctionCodeSnippets() QVERIFY(addedFunc->hasInjectedCode()); } +void TestAddFunction::testFunctionWithoutParenteses() +{ + const char sig1[] = "func"; + AddedFunction f1(sig1, "void"); + QCOMPARE(f1.name(), QString("func")); + QCOMPARE(f1.arguments().count(), 0); + QCOMPARE(f1.isConstant(), false); +} QTEST_APPLESS_MAIN(TestAddFunction) diff --git a/tests/testaddfunction.h b/tests/testaddfunction.h index 45a562d4b..a8082a4b5 100644 --- a/tests/testaddfunction.h +++ b/tests/testaddfunction.h @@ -33,6 +33,7 @@ private slots: void testAddFunction(); void testAddFunctionTagDefaultValues(); void testAddFunctionCodeSnippets(); + void testFunctionWithoutParenteses(); }; #endif
\ No newline at end of file diff --git a/typesystem.cpp b/typesystem.cpp index 1046aed6d..6d9cbe918 100644 --- a/typesystem.cpp +++ b/typesystem.cpp @@ -2109,18 +2109,23 @@ AddedFunction::AddedFunction(QString signature, QString returnType) : m_access(P m_returnType = parseType(returnType); signature = signature.trimmed(); int endPos = signature.indexOf('('); - m_name = signature.left(endPos).trimmed(); - int signatureLength = signature.length(); - while (endPos < signatureLength) { - TypeInfo arg = parseType(signature, endPos, &endPos); - if (!arg.name.isEmpty()) - m_arguments.append(arg); - // end of parameters... - if (signature[endPos] == ')') - break; + if (endPos < 0) { + m_isConst = false; + m_name = signature; + } else { + m_name = signature.left(endPos).trimmed(); + int signatureLength = signature.length(); + while (endPos < signatureLength) { + TypeInfo arg = parseType(signature, endPos, &endPos); + if (!arg.name.isEmpty()) + m_arguments.append(arg); + // end of parameters... + if (signature[endPos] == ')') + break; + } + // is const? + m_isConst = signature.right(signatureLength - endPos).contains("const"); } - // is const? - m_isConst = signature.right(signatureLength - endPos).contains("const"); } /* |