diff --git a/src/helpers.cpp b/src/helpers.cpp index 6899ad97..dc33f7af 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -368,22 +368,16 @@ std::basic_string Scroller(const std::basic_string &str, s std::basic_string::const_iterator b = s.begin(), e = s.end(); for (std::basic_string::const_iterator it = b+pos; it < e && len < width; ++it) { -# ifdef _UTF8 - len += wcwidth(*it); -# else - len++; -# endif + if ((len += wcwidth(*it)) > width) + break; result += *it; } if (++pos >= s.length()) pos = 0; for (; len < width; ++b) { -# ifdef _UTF8 - len += wcwidth(*b); -# else - len++; -# endif + if ((len += wcwidth(*b)) > width) + break; result += *b; } } diff --git a/src/strbuffer.h b/src/strbuffer.h index 8f6568d2..34ae9858 100644 --- a/src/strbuffer.h +++ b/src/strbuffer.h @@ -169,7 +169,8 @@ template void NCurses::basic_buffer::Write(Window &w, size_t &po LoadAttribute(w, lb->Value); ++lb; } - len += wcwidth(s[i]); + if ((len += wcwidth(s[i])) > width) + break; w << s[i]; } if (++pos >= s.length()) @@ -184,7 +185,8 @@ template void NCurses::basic_buffer::Write(Window &w, size_t &po LoadAttribute(w, lb->Value); ++lb; } - len += wcwidth(s[i]); + if ((len += wcwidth(s[i])) > width) + break; w << s[i]; } // load all remained attributes to clean up