From 89454508a2024da5fde5db309ede45a0af9cdeb3 Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Fri, 19 May 2023 18:57:18 +0200 Subject: Fix Fl_Simple_Terminal::append(str, len) assumes a null terminated string (#728) --- src/Fl_Simple_Terminal.cxx | 2 +- src/Fl_Text_Buffer.cxx | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Fl_Simple_Terminal.cxx b/src/Fl_Simple_Terminal.cxx index b8f1f403d..1f6933326 100644 --- a/src/Fl_Simple_Terminal.cxx +++ b/src/Fl_Simple_Terminal.cxx @@ -910,7 +910,7 @@ void Fl_Simple_Terminal::append(const char *s, int len) { append_ansi(s, len); } else { // raw append - buf->append(s); + buf->append(s, len); lines_ += ::strcnt(s, '\n'); // count total line feeds in string added } enforce_history_lines(); diff --git a/src/Fl_Text_Buffer.cxx b/src/Fl_Text_Buffer.cxx index 1cfcd1b9b..b606af9de 100644 --- a/src/Fl_Text_Buffer.cxx +++ b/src/Fl_Text_Buffer.cxx @@ -380,7 +380,7 @@ char Fl_Text_Buffer::byte_at(int pos) const { Insert some text at the given index. Pos must be at a character boundary. */ -void Fl_Text_Buffer::insert(int pos, const char *text) +void Fl_Text_Buffer::insert(int pos, const char *text, int insertedLength) { IS_UTF8_ALIGNED2(this, (pos)) IS_UTF8_ALIGNED(text) @@ -399,7 +399,7 @@ void Fl_Text_Buffer::insert(int pos, const char *text) call_predelete_callbacks(pos, 0); /* insert and redisplay */ - int nInserted = insert_(pos, text); + int nInserted = insert_(pos, text, insertedLength); mCursorPosHint = pos + nInserted; IS_UTF8_ALIGNED2(this, (mCursorPosHint)) call_modify_callbacks(pos, 0, nInserted, 0, NULL); @@ -454,7 +454,7 @@ void Fl_Text_Buffer::printf(const char *fmt, ...) { Replace a range of text with new text. Start and end must be at a character boundary. */ -void Fl_Text_Buffer::replace(int start, int end, const char *text) +void Fl_Text_Buffer::replace(int start, int end, const char *text, int insertedLength) { // Range check... if (!text) @@ -471,7 +471,7 @@ void Fl_Text_Buffer::replace(int start, int end, const char *text) call_predelete_callbacks(start, end - start); const char *deletedText = text_range(start, end); remove_(start, end); - int nInserted = insert_(start, text); + int nInserted = insert_(start, text, insertedLength); mCursorPosHint = start + nInserted; call_modify_callbacks(start, end - start, nInserted, 0, deletedText); free((void *) deletedText); @@ -1355,12 +1355,12 @@ int Fl_Text_Buffer::search_backward(int startPos, const char *searchString, Insert a string into the buffer. Pos must be at a character boundary. Text must be a correct UTF-8 string. */ -int Fl_Text_Buffer::insert_(int pos, const char *text) +int Fl_Text_Buffer::insert_(int pos, const char *text, int insertedLength) { if (!text || !*text) return 0; - int insertedLength = (int) strlen(text); + if (insertedLength == -1) insertedLength = (int) strlen(text); /* Prepare the buffer to receive the new text. If the new text fits in the current buffer, just move the gap (if necessary) to where -- cgit v1.2.3