[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [ktexteditor] /: The original patch (691c0315868511edff8048081e6e8b85c6653816) from Francis Herne go
From: Simon St James <kdedevel () etotheipiplusone ! com>
Date: 2016-06-17 8:18:10
Message-ID: E1bDoyg-0002ZN-TD () scm ! kde ! org
[Download RAW message or body]
Git commit 6571af1abf9da2cce4bdc8b20fdd4436d840d107 by Simon St James.
Committed on 17/06/2016 at 08:14.
Pushed by sstjames into branch 'master'.
The original patch (691c0315868511edff8048081e6e8b85c6653816) from Francis Herne got \
lost in the merge of the emulated command bar refactoring: I'm re-instating it here, \
this time with a test. Original commit message:
vimode: Don't crash when given a range for a nonexistent command.
Patch by Francis Herne.
When entering a range for a nonexistent command ,p is dereferenced before the null \
check. Move that check to before p is used.
BUG: 360418
Differential Revision: D1684
M +3 -0 autotests/src/vimode/emulatedcommandbar.cpp
M +14 -15 src/vimode/emulatedcommandbar/commandmode.cpp
http://commits.kde.org/ktexteditor/6571af1abf9da2cce4bdc8b20fdd4436d840d107
diff --git a/autotests/src/vimode/emulatedcommandbar.cpp \
b/autotests/src/vimode/emulatedcommandbar.cpp index 0240440..7a99c9c 100644
--- a/autotests/src/vimode/emulatedcommandbar.cpp
+++ b/autotests/src/vimode/emulatedcommandbar.cpp
@@ -1488,6 +1488,9 @@ void EmulatedCommandBarTest::EmulatedCommandBarTests()
// Execute the command on Enter.
DoTest("d\nb\na\nc", "Vjjj:sort\\enter", "a\nb\nc\nd");
+ // Don't crash if we call a non-existent command with a range.
+ DoTest("123", ":42nonexistentcommand\\enter", "123");
+
// Bar background should always be normal for command bar.
BeginTest("foo");
TestPressKey("/foo\\enter:");
diff --git a/src/vimode/emulatedcommandbar/commandmode.cpp \
b/src/vimode/emulatedcommandbar/commandmode.cpp index 67e9f62..0c5f053 100644
--- a/src/vimode/emulatedcommandbar/commandmode.cpp
+++ b/src/vimode/emulatedcommandbar/commandmode.cpp
@@ -168,21 +168,20 @@ QString CommandMode::executeCommand ( const QString& \
commandToExecute )
if (cmd.length() > 0) {
KTextEditor::Command *p = queryCommand(cmd);
- KateViCommandInterface *ci = dynamic_cast<KateViCommandInterface*>(p);
-
- if (ci) {
- ci->setViInputModeManager(viInputModeManager());
- ci->setViGlobal(viInputModeManager()->globalState());
- }
+ if (p) {
+ KateViCommandInterface *ci = dynamic_cast<KateViCommandInterface*>(p);
+ if (ci) {
+ ci->setViInputModeManager(viInputModeManager());
+ ci->setViGlobal(viInputModeManager()->globalState());
+ }
- // The following commands changes the focus themselves, so bar should be \
hidden before execution. + // The following commands changes the focus \
themselves, so bar should be hidden before execution.
- // We got a range and a valid command, but the command does not inherit the \
RangeCommand
- // extension. Bail out.
- if (range.isValid() && !p->supportsRange(cmd)) {
- commandResponseMessage = i18n("Error: No range allowed for command \
\"%1\".", cmd);
- } else {
- if (p) {
+ // We got a range and a valid command, but the command does not inherit \
the RangeCommand + // extension. Bail out.
+ if (range.isValid() && !p->supportsRange(cmd)) {
+ commandResponseMessage = i18n("Error: No range allowed for command \
\"%1\".", cmd); + } else {
if (p->exec(view(), cmd, commandResponseMessage, range)) {
if (commandResponseMessage.length() > 0) {
@@ -198,9 +197,9 @@ QString CommandMode::executeCommand ( const QString& \
commandToExecute )
commandResponseMessage = i18n("Command \"%1\" failed.", \
cmd); }
}
- } else {
- commandResponseMessage = i18n("No such command: \"%1\"", cmd);
}
+ } else {
+ commandResponseMessage = i18n("No such command: \"%1\"", cmd);
}
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic