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:
Wilhelm Schuermann 2015-04-03 22:22:44 +02:00
parent c830b4b669
commit 5b01abc27f

View file

@ -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;
} }