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.
This commit is contained in:
13
src/utf8.cpp
13
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 utf8_width (const std::string& str)
|
||||||
{
|
{
|
||||||
unsigned int length = 0;
|
unsigned int length = 0;
|
||||||
|
int l;
|
||||||
std::string::size_type i = 0;
|
std::string::size_type i = 0;
|
||||||
unsigned int c;
|
unsigned int c;
|
||||||
while ((c = utf8_next_char (str, i)))
|
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;
|
return length;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user