[bugfix]Cpp::TemplateDeclaration::setSpecializedFrom

Artur Bać artur at ebasoft.com.pl
Sat Feb 9 16:36:34 UTC 2013


in Cpp::TemplateDeclaration::setSpecializedFrom (repo 1.5) has bug which
allow cycling call of the same object, and this casuses SIGSEGV,
propably stack overflow. See bellow stacktrace.

Bellow patch fixes crashing, but i think such situation should not
happen at all, an object pointing at it self

diff --git languages/cpp/cppduchain/templatedeclaration.cpp
languages/cpp/cppduchain/templatedeclaration.cpp
index 9d8ba4c..4787361 100644
--- languages/cpp/cppduchain/templatedeclaration.cpp
+++ languages/cpp/cppduchain/templatedeclaration.cpp
@@ -381,7 +381,10 @@ void
TemplateDeclaration::setSpecializedFrom(TemplateDeclaration* other) {
     return;
   }
   if(other && other->specializedFrom().data()) {
-
setSpecializedFrom(dynamic_cast<TemplateDeclaration*>(other->specializedFrom().data()));
+    Declaration* data_ptr = other->specializedFrom().data();
+    TemplateDeclaration* tdecl =
dynamic_cast<TemplateDeclaration*>(data_ptr);
+    if( tdecl != this )
+      setSpecializedFrom(tdecl);
     return;
   }


Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffad3d5700 (LWP 1438)]
0x00007ffff56c7c42 in
__cxxabiv1::__si_class_type_info::__do_dyncast(long,
__cxxabiv1::__class_type_info::__sub_kind, __cxxabiv1::__class_type_info
const*, void const*, __cxxabiv1::__class_type_info const*, void const*,
__cxxabiv1::__class_type_info::__dyncast_result&) const () from
/usr/lib/x86_64-linux-gnu/libstdc++.so.6

#4  0x00007fffc4cb140a in Cpp::TemplateDeclaration::setSpecializedFrom
(this=0x7fff5c2bbdf8, other=0x7fff5c2bbb88) at
../languages/cpp/cppduchain/templatedeclaration.cpp:384
#5  0x00007fffc4cb1415 in Cpp::TemplateDeclaration::setSpecializedFrom
(this=0x7fff5c2bbdf8, other=0x7fff5c2bbb88) at
../languages/cpp/cppduchain/templatedeclaration.cpp:384

[...]

#74641 0x00007fffc4cb1415 in
Cpp::TemplateDeclaration::setSpecializedFrom (this=0x7fff5c2bbdf8,
other=0x7fff5c2bbb88) at
../languages/cpp/cppduchain/templatedeclaration.cpp:384


#74642 0x00007fffc4cb1415 in
Cpp::TemplateDeclaration::setSpecializedFrom (this=0x7fff5c2bbdf8,
other=0x7fff5c2bbb88) at
../languages/cpp/cppduchain/templatedeclaration.cpp:384
#74643 0x00007fffc4c72440 in
DeclarationBuilder::openDeclaration<KDevelop::FunctionDefinition>
(this=0x7fffad3cf9b0, name=0x7fff5d6b05b8, rangeNode=<optimized out>,
customName=..., collapseRangeAtStart=<optimized out>,
    collapseRangeAtEnd=<optimized out>) at
../languages/cpp/cppduchain/declarationbuilder.cpp:656
#74644 0x00007fffc4c61efe in DeclarationBuilder::openFunctionDeclaration
(this=0x7fffad3cf9b0, name=0x7fff5d6b05b8, rangeNode=0x7fff5d6b0440) at
../languages/cpp/cppduchain/declarationbuilder.cpp:867
#74645 0x00007fffc4c62c87 in DeclarationBuilder::visitDeclarator
(this=0x7fffad3cf9b0, node=0x7fff5d6b0440) at
../languages/cpp/cppduchain/declarationbuilder.cpp:497
#74646 0x00007fffc4c5f7ba in
DeclarationBuilder::visitFunctionDeclaration (this=0x7fffad3cf9b0,
node=0x7fff5d6b15c0) at
../languages/cpp/cppduchain/declarationbuilder.cpp:181
#74647 0x00007fffc4c4ee23 in ContextBuilder::visitFunctionDefinition
(this=0x7fffad3cf9b0, node=0x7fff5d6b15c0) at
../languages/cpp/cppduchain/contextbuilder.cpp:576
#74648 0x00007fffc4c4e477 in ContextBuilder::visitTemplateDeclaration
(this=0x7fffad3cf9b0, ast=0x7fff5d6b1620) at
../languages/cpp/cppduchain/contextbuilder.cpp:292
#74649 0x00007fffc49a823e in visitNodes<DeclarationAST*>
(v=0x7fffad3cfa10, nodes=<optimized out>) at
../languages/cpp/parser/visitor.h:139
#74650 0x00007fffc4c51d31 in KDevelop::AbstractContextBuilder<AST,
NameAST>::supportBuild (this=0x7fffad3cf9b0, node=0x7fff5d685170,
context=<optimized out>)
    at
/usr/include/kdevplatform/language/duchain/builders/abstractcontextbuilder.h:133
#74651 0x00007fffc4c4fe5d in ContextBuilder::buildContexts
(this=0x7fffad3cf9b0, file=..., node=0x7fff5d685170, includes=<optimized
out>, updateContext=..., removeOldImports=false)
    at ../languages/cpp/cppduchain/contextbuilder.cpp:421
#74652 0x00007fffc4c5b3a1 in DeclarationBuilder::buildDeclarations
(this=<optimized out>, file=..., node=<optimized out>,
includes=<optimized out>, updateContext=..., removeOldImports=false)
    at ../languages/cpp/cppduchain/declarationbuilder.cpp:96
#74653 0x00007fffc517e62d in CPPInternalParseJob::run
(this=0x7fff5d7cba60) at ../languages/cpp/cppparsejob.cpp:644
#74654 0x00007fffc51848b7 in PreprocessJob::sourceNeeded
(this=0x7fff5d2e9860, _fileName=..., type=<optimized out>,
sourceLine=12, skipCurrentPath=<optimized out>) at
../languages/cpp/preprocessjob.cpp:581
#74655 0x00007fffc4f3b43e in rpp::pp::handle_include
(this=0x7fffad3d15b0, skip_current_path=false, input=..., output=...) at
../languages/cpp/parser/rpp/pp-engine.cpp:219
#74656 0x00007fffc4f3ceb7 in rpp::pp::handle_directive
(this=0x7fffad3d15b0, directive=352492, input=..., output=...) at
../languages/cpp/parser/rpp/pp-engine.cpp:137
#74657 0x00007fffc4f3d5a3 in rpp::pp::operator() (this=0x7fffad3d15b0,
input=..., output=...) at ../languages/cpp/parser/rpp/pp-engine.cpp:272
#74658 0x00007fffc4f3d822 in rpp::pp::processFileInternal
(this=0x7fffad3d15b0, fileName=..., fileContents=..., result=...) at
../languages/cpp/parser/rpp/pp-engine.cpp:98
#74659 0x00007fffc4f3d8c5 in rpp::pp::processFile (this=<optimized out>,
fileName=..., data=...) at ../languages/cpp/parser/rpp/pp-engine.cpp:85
#74660 0x00007fffc5185c99 in PreprocessJob::run (this=0x7fff5d2e9860) at
../languages/cpp/preprocessjob.cpp:245
#74661 0x00007fffc517baae in CPPParseJob::parseForeground
(this=0x7fff5d489520) at ../languages/cpp/cppparsejob.cpp:181
#74662 0x00007fffc51848b7 in PreprocessJob::sourceNeeded
(this=0x4f28960, _fileName=..., type=<optimized out>, sourceLine=23,
skipCurrentPath=<optimized out>) at ../languages/cpp/preprocessjob.cpp:581
#74663 0x00007fffc4f3b43e in rpp::pp::handle_include
(this=0x7fffad3d3810, skip_current_path=false, input=..., output=...) at
../languages/cpp/parser/rpp/pp-engine.cpp:219
#74664 0x00007fffc4f3ceb7 in rpp::pp::handle_directive
(this=0x7fffad3d3810, directive=352492, input=..., output=...) at
../languages/cpp/parser/rpp/pp-engine.cpp:137
#74665 0x00007fffc4f3d5a3 in rpp::pp::operator() (this=0x7fffad3d3810,
input=..., output=...) at ../languages/cpp/parser/rpp/pp-engine.cpp:272
#74666 0x00007fffc4f3d822 in rpp::pp::processFileInternal
(this=0x7fffad3d3810, fileName=..., fileContents=..., result=...) at
../languages/cpp/parser/rpp/pp-engine.cpp:98
#74667 0x00007fffc4f3d8c5 in rpp::pp::processFile (this=<optimized out>,
fileName=..., data=...) at ../languages/cpp/parser/rpp/pp-engine.cpp:85
#74668 0x00007fffc5185c99 in PreprocessJob::run (this=0x4f28960) at
../languages/cpp/preprocessjob.cpp:245


More information about the KDevelop-devel mailing list