Commit a5cf36fe authored by Milian Wolff's avatar Milian Wolff

Don't crash when signatures don't match in AdaptSignatureAssistant

When the old positions overflow the new list of available declarations,
do not crash. This could happen due to parse errors or any other
discrepancy in counts. Should fixes the following assert I just
encountered:

```
[KCrash Handler]
#6  0x00007fc6324a3f25 in raise () from /usr/lib/libc.so.6
#7  0x00007fc63248d897 in abort () from /usr/lib/libc.so.6
#8  0x00007fc632a0996c in QMessageLogger::fatal(char const*, ...) const () from /usr/lib/libQt5Core.so.5
#9  0x00007fc632a08d52 in qt_assert_x(char const*, char const*, char const*, int) () from /usr/lib/libQt5Core.so.5
#10 0x00007fc5f508be69 in QVector<KDevelop::Declaration*>::operator[] (this=0x7ffc9cfb01a0, i=1) at /usr/include/qt/QtCore/qvector.h:463
#11 0x00007fc5f508a4a6 in AdaptSignatureAssistant::getRenameActions (this=0x5621d5cd80e0, newSignature=..., oldPositions=...) at /home/milian/projects/kf5/src/extragear/kdevelop/kdevelop/plugins/clang/codegen/adaptsignatureassistant.cpp:246
```
parent ab8dd731
......@@ -239,11 +239,14 @@ QList<RenameAction*> AdaptSignatureAssistant::getRenameActions(const Signature &
if (!m_otherSideContext) {
return renameActions;
}
const auto oldDeclarations = m_otherSideContext->localDeclarations();
for (int i = newSignature.parameters.size() - 1; i >= 0; --i) {
if (oldPositions[i] == -1) {
continue; //new parameter
}
Declaration *renamedDecl = m_otherSideContext->localDeclarations()[oldPositions[i]];
Declaration *renamedDecl = oldDeclarations.value(oldPositions[i]);
if (!renamedDecl)
continue;
if (newSignature.parameters[i].second != m_oldSignature.parameters[oldPositions[i]].second) {
const auto uses = renamedDecl->uses();
if (!uses.isEmpty()) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment