Fix segfault in getLifetimeVariable#1631
Conversation
prevent infinite recursion, eg from LibreOffice
0 0x0000555555bdc9dd in multiComparePercent (tok=0x5555570916d0, haystack=@0x7fffff7ff0a0: 0x555555d20dd9 "%name% (",
varid=<error reading variable: Cannot access memory at address 0x7fffff7feffc>) at lib/token.cpp:354
1 0x0000555555bdd113 in Token::multiCompare (tok=0x5555570916d0, haystack=0x555555d20dd9 "%name% (", varid=0) at lib/token.cpp:499
2 0x0000555555bdd6c9 in Token::Match (tok=0x5555570916d0, pattern=0x555555d20dd9 "%name% (", varid=0) at lib/token.cpp:663
3 0x0000555555c62101 in getLifetimeVariable (tok=0x5555570921a0, errorPath=empty std::__debug::list) at lib/valueflow.cpp:2651
4 0x0000555555c62194 in getLifetimeVariable (tok=0x5555570921a0, errorPath=empty std::__debug::list) at lib/valueflow.cpp:2660
5 0x0000555555c62194 in getLifetimeVariable (tok=0x5555570921a0, errorPath=empty std::__debug::list) at lib/valueflow.cpp:2660
orbitcowboy
left a comment
There was a problem hiding this comment.
Many thanks! Could you please add a regression test?
|
@orbitcowboy: don't have time to this but you may read some details about the bug here: Also, I hesitated between "return nullptr;" and "return var;" |
|
I think int& f() { return f(); }Which this PR does fix. Although, it will still crash on: int& g(int& i) { return i; }
int& f() { return g(f()); }I can try to fix that case. |
|
Thank you Paul for your feedback. |
prevent infinite recursion, eg from LibreOffice
0 0x0000555555bdc9dd in multiComparePercent (tok=0x5555570916d0, haystack=@0x7fffff7ff0a0: 0x555555d20dd9 "%name% (",
varid=<error reading variable: Cannot access memory at address 0x7fffff7feffc>) at lib/token.cpp:354
1 0x0000555555bdd113 in Token::multiCompare (tok=0x5555570916d0, haystack=0x555555d20dd9 "%name% (", varid=0) at lib/token.cpp:499
2 0x0000555555bdd6c9 in Token::Match (tok=0x5555570916d0, pattern=0x555555d20dd9 "%name% (", varid=0) at lib/token.cpp:663
3 0x0000555555c62101 in getLifetimeVariable (tok=0x5555570921a0, errorPath=empty std::__debug::list) at lib/valueflow.cpp:2651
4 0x0000555555c62194 in getLifetimeVariable (tok=0x5555570921a0, errorPath=empty std::__debug::list) at lib/valueflow.cpp:2660
5 0x0000555555c62194 in getLifetimeVariable (tok=0x5555570921a0, errorPath=empty std::__debug::list) at lib/valueflow.cpp:2660
|
Argh, I badly understood, thought nullptr was better. |
prevent infinite recursion, eg from LibreOffice
0 0x0000555555bdc9dd in multiComparePercent (tok=0x5555570916d0, haystack=@0x7fffff7ff0a0: 0x555555d20dd9 "%name% (",
varid=<error reading variable: Cannot access memory at address 0x7fffff7feffc>) at lib/token.cpp:354
1 0x0000555555bdd113 in Token::multiCompare (tok=0x5555570916d0, haystack=0x555555d20dd9 "%name% (", varid=0) at lib/token.cpp:499
2 0x0000555555bdd6c9 in Token::Match (tok=0x5555570916d0, pattern=0x555555d20dd9 "%name% (", varid=0) at lib/token.cpp:663
3 0x0000555555c62101 in getLifetimeVariable (tok=0x5555570921a0, errorPath=empty std::__debug::list) at lib/valueflow.cpp:2651
4 0x0000555555c62194 in getLifetimeVariable (tok=0x5555570921a0, errorPath=empty std::__debug::list) at lib/valueflow.cpp:2660
5 0x0000555555c62194 in getLifetimeVariable (tok=0x5555570921a0, errorPath=empty std::__debug::list) at lib/valueflow.cpp:2660