From 5b01abc27f2e822de3baa3383c742c69476a46fb Mon Sep 17 00:00:00 2001 From: Wilhelm Schuermann Date: Fri, 3 Apr 2015 22:22:44 +0200 Subject: [PATCH] Fix problem with special chars in descriptions Fix 'task add a; task add "\n"; task next' returning "Unknown error." The problem can be reproduced with any report including "description" as a column. For task descriptions that had more special characters than regular ones, "length" in utf8_width() underflowed, leading to problems elsewhere in the code. --- src/utf8.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/utf8.cpp b/src/utf8.cpp index 129232e50..881b77ce0 100644 --- a/src/utf8.cpp +++ b/src/utf8.cpp @@ -188,10 +188,21 @@ unsigned int utf8_length (const std::string& str) unsigned int utf8_width (const std::string& str) { unsigned int length = 0; + int l; std::string::size_type i = 0; unsigned int c; while ((c = utf8_next_char (str, i))) - length += mk_wcwidth (c); + { + l = mk_wcwidth (c); + // Control characters, and more especially newline characters, make + // mk_wcwidth() return -1. Ignore that, thereby "adding zero" to length. + // Since control characters are not displayed in reports, this is a valid + // choice. + if (l != -1) + { + length += l; + } + } return length; }