[education/rkward] /: Fix crash on spontaneous R output
Thomas Friedrichsmeier
null at kde.org
Mon Jul 29 13:53:07 BST 2024
Git commit 341e7b539161a7c1c674ffa9b31011af33a86dac by Thomas Friedrichsmeier.
Committed on 29/07/2024 at 12:52.
Pushed by tfry into branch 'master'.
Fix crash on spontaneous R output
M +1 -0 ChangeLog
M +3 -11 rkward/rkconsole.cpp
https://invent.kde.org/education/rkward/-/commit/341e7b539161a7c1c674ffa9b31011af33a86dac
diff --git a/ChangeLog b/ChangeLog
index 68c58d552..464697740 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,5 @@
--- Version 0.8.1 - UNRELEASED
+- Fixed: Potential crash on "spontaneous" R output (originating from event handlers such as tcl)
- Fixed: commandArgs() would show incorrect options
- Internal: Various code cleanups
- Added: Configuration pages for loaded kate plugins are integrated into the settings dialog
diff --git a/rkward/rkconsole.cpp b/rkward/rkconsole.cpp
index 46b2a9ffc..58f44f3d9 100644
--- a/rkward/rkconsole.cpp
+++ b/rkward/rkconsole.cpp
@@ -536,16 +536,12 @@ void RKConsole::rawWriteLine(const QString& line, QChar line_end) {
void RKConsole::newOutput (RCommand *command, const ROutput *output) {
RK_TRACE (APP);
- int first_line = doc->lines () -1;
- QString popped_line;
- // TODO: rewrite utilizing output_cursor;
if (!command) {
// spontanteous R output, to be inserted _above_ the current command
- // as a shortcut, we pop the last line, and reinsert in, later
- popped_line = doc->line(doc->lines() - 1);
- doc->removeLine(doc->lines() - 1);
+ output_cursor = KTextEditor::Cursor(doc->lines()-2, doc->lineLength(doc->lines()-2));
}
+ int first_line = output_cursor.line();;
// split by and handle carriage returns (important for progress bars)
const QString out = output->output;
int string_pos = -1;
@@ -560,7 +556,7 @@ void RKConsole::newOutput (RCommand *command, const ROutput *output) {
}
if (start_pos < end_pos) rawWriteLine(out.mid(start_pos, string_pos - start_pos + 1), ' ');
- int end_line = doc->lines () -1;
+ int end_line = output_cursor.line();
if (output->type != ROutput::Output || (!command)) {
for (int line = first_line; line < end_line; ++line) {
doc->addMark (line, command ? KTextEditor::Document::BreakpointActive : KTextEditor::Document::BreakpointDisabled);
@@ -579,10 +575,6 @@ void RKConsole::newOutput (RCommand *command, const ROutput *output) {
}
}
- if (!command) {
- doc->insertLine(doc->lines(), popped_line);
- }
-
cursorAtTheEnd ();
}
More information about the rkward-tracker
mailing list