mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
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:
parent
c830b4b669
commit
5b01abc27f
1 changed files with 12 additions and 1 deletions
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue