Fix ls -q UTF-8 parsing

Thanks FRIGN for the input.
This commit is contained in:
sin 2015-02-18 16:43:18 +00:00
parent 2a3f82a5cd
commit d40333e702
1 changed files with 4 additions and 3 deletions

7
ls.c
View File

@ -209,11 +209,11 @@ lsdir(const char *path)
output(&ent);
} else {
ents = erealloc(ents, ++n * sizeof(*ents));
name = p = estrdup(d->d_name);
name = p = emalloc(strlen(d->d_name) + 1);
if (qflag) {
q = d->d_name;
while (*p) {
len = chartorune(&r, p);
while (*q) {
len = chartorune(&r, q);
if (isprintrune(r)) {
memcpy(p, q, len);
p += len, q += len;
@ -222,6 +222,7 @@ lsdir(const char *path)
q += len;
}
}
*p = '\0';
}
mkent(&ents[n - 1], name, tflag || Fflag || lflag || iflag, Lflag);
}