summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGreg Ercolano <erco@seriss.com>2023-12-04 09:30:26 -0800
committerGreg Ercolano <erco@seriss.com>2023-12-04 09:30:54 -0800
commitc3849b0a97913add0fae4b3ba3e4bff2a706738d (patch)
treee6ef3be665c8fb657ee51bd3ec96e2153c70d394 /src
parented910b7368aa8a43dd72262119f14a488e8e7648 (diff)
Fix issue 854 - append_ansi() len fix
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Simple_Terminal.cxx10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/Fl_Simple_Terminal.cxx b/src/Fl_Simple_Terminal.cxx
index 1f6933326..c7718dbf8 100644
--- a/src/Fl_Simple_Terminal.cxx
+++ b/src/Fl_Simple_Terminal.cxx
@@ -792,6 +792,8 @@ void Fl_Simple_Terminal::unknown_escape() {
/**
Handle appending string with ANSI escape sequences, and other 'special'
character processing (such as backspaces).
+ - \p s -- the string containing ANSI codes to be appended
+ - \p len -- the length of the string to be appended, or -1 for a NULL terminated string.
*/
void Fl_Simple_Terminal::append_ansi(const char *s, int len) {
int nstyles = stable_size_ / STE_SIZE;
@@ -803,7 +805,7 @@ void Fl_Simple_Terminal::append_ansi(const char *s, int len) {
nsp_ = nsm_; // new style ptr
// Walk user's string looking for codes, modify new text/style text as needed
const char *sp = s;
- while ( *sp ) {
+ while ( *sp && --len >= 0 ) { // walk string until NULL or len reached
if (*sp == 0x1b ) { // start of ESC sequence?
escseq.parse(*sp++); // start parsing..
continue;
@@ -891,7 +893,7 @@ void Fl_Simple_Terminal::append_ansi(const char *s, int len) {
}
/**
- Appends new string 's' to terminal.
+ Appends new string 's' of length 'len' to terminal.
The string can contain UTF-8, crlf's.
And if ansi(bool) is set to 'true', ANSI 'ESC' sequences (such as ESC[1m)
@@ -900,7 +902,8 @@ void Fl_Simple_Terminal::append_ansi(const char *s, int len) {
\param s string to append.
\param len optional length of string can be specified if known
- to save the internals from having to call strlen()
+ to save the internals from having to call strlen().
+ If -1 is specified for len, strlen(s) is used to find the length.
\see printf(), vprintf(), text(), clear()
*/
@@ -929,6 +932,7 @@ void Fl_Simple_Terminal::append(const char *s, int len) {
\param len optional length of string can be specified if known
to save the internals from having to call strlen()
+ If -1 is specified for len, strlen(s) is used to find the length.
\see append(), printf(), vprintf(), clear()