[hackers] [sbase] Fix ls -q UTF-8 parsing || sin

From: <git_AT_suckless.org>
Date: Tue, 24 Mar 2015 23:53:53 +0100 (CET)

commit d40333e702c5f116cbc0650b5dd5512abb17c5e4
Author: sin <sin_AT_2f30.org>
Date: Wed Feb 18 16:43:18 2015 +0000

    Fix ls -q UTF-8 parsing
    
    Thanks FRIGN for the input.

diff --git a/ls.c b/ls.c
index bb249ed..900d5f6 100644
--- a/ls.c
+++ b/ls.c
_AT_@ -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;
_AT_@ -222,6 +222,7 @@ lsdir(const char *path)
                                                 q += len;
                                         }
                                 }
+ *p = '\0';
                         }
                         mkent(&ents[n - 1], name, tflag || Fflag || lflag || iflag, Lflag);
                 }
Received on Tue Mar 24 2015 - 23:53:53 CET

This archive was generated by hypermail 2.3.0 : Wed Mar 25 2015 - 00:10:33 CET