From 46b407f26cf98c494f646609a37d03be4c41e11a Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Wed, 31 Jan 2024 12:59:03 +0900 Subject: Fix SEGV when hovering on symbols after creating a new project. This resolves issue #40. Signed-off-by: Michele Calgaro --- languages/cpp/cppsupportpart.cpp | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'languages/cpp/cppsupportpart.cpp') diff --git a/languages/cpp/cppsupportpart.cpp b/languages/cpp/cppsupportpart.cpp index 01b34a43..c94539de 100644 --- a/languages/cpp/cppsupportpart.cpp +++ b/languages/cpp/cppsupportpart.cpp @@ -1699,25 +1699,29 @@ void CppSupportPart::slotNeedTextHint( int line, int column, TQString& textHint return ; m_backgroundParser->lock(); - TranslationUnitAST* ast = *m_backgroundParser->translationUnit( m_activeFileName ); - AST* node = 0; - if ( ast && ( node = findNodeAt( ast, line, column ) ) ) + ParsedFilePointer pTransUnit = m_backgroundParser->translationUnit(m_activeFileName); + if (pTransUnit) { + TranslationUnitAST* ast = *pTransUnit; + AST* node = 0; + if ( ast && ( node = findNodeAt( ast, line, column ) ) ) + { - while ( node && node->nodeType() != NodeType_FunctionDefinition ) - node = node->parent(); + while ( node && node->nodeType() != NodeType_FunctionDefinition ) + node = node->parent(); - if ( node ) - { - int startLine, startColumn; - int endLine, endColumn; - node->getStartPosition( &startLine, &startColumn ); - node->getEndPosition( &endLine, &endColumn ); + if ( node ) + { + int startLine, startColumn; + int endLine, endColumn; + node->getStartPosition( &startLine, &startColumn ); + node->getEndPosition( &endLine, &endColumn ); - if ( !node->text().isNull() ) - textHint = node->text(); - else - textHint = m_activeEditor->textLine( startLine ).simplifyWhiteSpace(); + if ( !node->text().isNull() ) + textHint = node->text(); + else + textHint = m_activeEditor->textLine( startLine ).simplifyWhiteSpace(); + } } } m_backgroundParser->unlock(); -- cgit v1.2.3