API: Bugfix: Use 0-terminated string in vim_strwidth

While the mb_string2cells function accepts a length parameter, it only seems to
work properly with 0-terminated strings, since valgrind reports a conditional
jump that depends on uninitialized values(means it reads after the string
boundaries which could result in overflows or wrong results)
This commit is contained in:
Thiago de Arruda 2014-05-23 15:49:19 -03:00
parent c6483aa2fa
commit 677d30d796

View File

@ -73,7 +73,10 @@ Integer vim_strwidth(String str, Error *err)
return 0;
}
return mb_string2cells((char_u *)str.data, (int)str.size);
char *buf = xstrndup(str.data, str.size);
Integer rv = mb_string2cells((char_u *)buf, -1);
free(buf);
return rv;
}
StringArray vim_list_runtime_paths(void)