Bug 456427 - code import crash
Summary: code import crash
Status: RESOLVED FIXED
Alias: None
Product: umbrello
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: Umbrello Development Group
URL:
Keywords:
: 461738 (view as bug list)
Depends on:
Blocks:
 
Reported: 2022-07-07 02:27 UTC by justin_wu
Modified: 2022-12-27 19:02 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 2.36.80 (KDE releases 22.11.80)
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description justin_wu 2022-07-07 02:27:53 UTC
SUMMARY
***
NOTE: If you are reporting a crash, please try to attach a backtrace with debug symbols.
See https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports
***
recently I study live555, then using umbrello5 to create uml graph.
but when I import source code, the umbrello will crash.

crash log output:
```/usr/include/c++/12.1.0/bits/unique_ptr.h:445: typename std::add_lvalue_reference<_Tp>::type std::unique_ptr<_Tp, _Dp>::operator*() const [with _Tp = InitDeclaratorAST; _Dp = std::default_delete<InitDeclaratorAST>; typename std::add_lvalue_reference<_Tp>::type = InitDeclaratorAST&]: Assertion 'get() != pointer()' failed.
Aborted (core dumped)
```
STEPS TO REPRODUCE
1. download live555 source code, http://www.live555.com/liveMedia/public/live.2022.06.16.tar.gz
2. start umbrello5, select menu "Code --> Code importing wizard",
3.  select `live555/liveMedia/include/` directory, press button "start import"
4. the umbrello5 crash.

OBSERVED RESULT


EXPECTED RESULT


SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma:  Linux justin 5.18.9-zen1-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Sat, 02 Jul 2022 21:03:08 +0000 x86_64 GNU/Linux
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version:  Qt6

ADDITIONAL INFORMATION
Comment 1 Xuxu 2022-10-24 17:46:39 UTC
I have a patch to fix this. you should patch `lib/cppparser/parser.cpp` with below. 

>> I think use `&(*std::unique_ptr)` is superfluous. `std::unique_ptr.get()` have the same effect. Hope the maintainer fix this as soon as possible

***
umbrello branch release/22.08 
***

```
diff --color -uprN a/lib/cppparser/parser.cpp b/lib/cppparser/parser.cpp
--- a/lib/cppparser/parser.cpp	2022-10-11 03:38:32.000000000 +0800
+++ b/lib/cppparser/parser.cpp	2022-10-25 00:45:11.678067641 +0800
@@ -1844,7 +1844,7 @@ template<class Type>
 void Parser::eventuallyTakeComment(int startLn, int endLn, Type& ast)
 {
     if (comment().line() >= startLn && comment().line() <= endLn) {
-        if (&(*ast)) {
+        if (ast.get()) {
             if (comment()) {
                 ast->setComment(comment());
             }
@@ -1860,7 +1860,7 @@ void Parser::eventuallyTakeComment(Type&
     int line = currentLine();
     Comment c = m_commentStore.getCommentsInRange(line, true);
 
-    if (&(*ast) && c) {
+    if (ast.get() && c) {
         ast->setComment(c);
     }
 }
@@ -3158,7 +3158,7 @@ bool Parser::parseDeclarationInternal(De
             int endSignature = m_lexer->index();
 
             Comment mcomment;
-            if (&(*declarator)) {
+            if (declarator.get()) {
                 int endLine, endColumn;
                 declarator->getEndPosition(&endLine, &endColumn);
                 mcomment = m_commentStore.getCommentsInRange(endLine);
@@ -3294,7 +3294,7 @@ start_decl:
         }
 
         Comment mcomment;
-        if (&(*decl)) {
+        if (decl.get()) {
             int line, col;
             decl->getEndPosition(&line, &col);
             mcomment = m_commentStore.getCommentsInRange(line);
@@ -3311,7 +3311,7 @@ start_decl:
             SimpleDeclarationAST::Node ast = CreateNode<SimpleDeclarationAST>();
             int line, col;
             ast->setComment(mcomment);
-            if (&(*decl)) {
+            if (decl.get()) {
                 decl->getEndPosition(&line, &col);
 
                 preparseLineComments(line);
@@ -3343,7 +3343,7 @@ start_decl:
                 FunctionDefinitionAST::Node ast = CreateNode<FunctionDefinitionAST>();
 
                 ast->setComment(mcomment);
-                if (&(*decl)) {
+                if (decl.get()) {
                     int line, col;
                     decl->getEndPosition(&line, &col);
 
```
Comment 2 Robert Hairgrove 2022-10-24 18:53:45 UTC
I think the problem is that these classes depend on some KDE stuff which define AST as a macro which formerly was probably std::auto_ptr, but in more recent versions uses std::unique_ptr.

If the unique_ptr is wrapping a NULL pointer, then of course the &(*) etc. will crash hbecause this is dereferencing a NULL pointer. However, `operator bool()` is overloaded in `std::unique_ptr`, so one could also write simply:
```
if (declarator) { // etc.
```
instead of:
```
if (&(*declarator)) {
```
or
```
if (declarator.get())) {
```
Comment 3 Xuxu 2022-10-25 12:48:18 UTC
As you said, source code change std::auto_prt to std::unique_ptr serveral release ago, but forgot to fix `&(*declarator)`.

Your advice is very useful.
Comment 4 Oliver Kellogg 2022-11-19 19:35:58 UTC
Git commit 035c942f83e0d8d39b31c531f237e8ccc0895656 by Oliver Kellogg.
Committed on 19/11/2022 at 19:35.
Pushed by okellogg into branch 'release/22.12'.

lib/cppparser/parser.cpp : Apply patch of comment #1 by Xuxu. Thanks.
FIXED-IN: 2.36.80 (KDE releases 22.11.80)

M  +6    -6    lib/cppparser/parser.cpp

https://invent.kde.org/sdk/umbrello/commit/035c942f83e0d8d39b31c531f237e8ccc0895656
Comment 5 Oliver Kellogg 2022-11-19 20:42:52 UTC
(In reply to justin_wu from comment #0)
> [...]
> STEPS TO REPRODUCE
> 1. download live555 source code,
> http://www.live555.com/liveMedia/public/live.2022.06.16.tar.gz

That version is no longer available but I downloaded live.2022.10.01.tar.gz
and with this version and Xuxu's patch applied, that problem did not happen.
Comment 6 Oliver Kellogg 2022-11-27 20:33:57 UTC
Git commit ef7e41fe2c99045a5fe6301c5aed92267a410d9c by Oliver Kellogg.
Committed on 27/11/2022 at 20:32.
Pushed by okellogg into branch 'master'.

lib/cppparser/parser.cpp : Apply patch of comment #1 by Xuxu. Thanks.
FIXED-IN: 2.36.80 (KDE releases 22.11.80)

M  +6    -6    lib/cppparser/parser.cpp

https://invent.kde.org/sdk/umbrello/commit/ef7e41fe2c99045a5fe6301c5aed92267a410d9c
Comment 7 Oliver Kellogg 2022-12-27 19:02:35 UTC
*** Bug 461738 has been marked as a duplicate of this bug. ***