Prevent overflow beyond the end of string in wtf_strwidth()

Bug-Debian: https://github.com/tats/w3m/issues/57
This commit is contained in:
Tatsuya Kinoshita
2016-12-07 20:41:29 +09:00
parent 900553de6d
commit d345c0950d

View File

@@ -120,10 +120,14 @@ int
wtf_strwidth(wc_uchar *p)
{
int w = 0;
size_t len;
while (*p) {
w += wtf_width(p);
p += WTF_LEN_MAP[*p];
len = WTF_LEN_MAP[*p];
if (len > strlen(p))
len = strlen(p);
p += len;
}
return w;
}