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

From: <git_AT_suckless.org>
Date: Wed, 18 Feb 2015 17:49:13 +0100 (CET)

commit 5962271616471f85657d6cd8464f58ee78d4e7b8
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 Wed Feb 18 2015 - 17:49:13 CET

This archive was generated by hypermail 2.3.0 : Wed Feb 18 2015 - 18:00:18 CET