[dev] [sbase] [PATCH 1--2] ls: fix -S and -q

From: Alexandre Niveau <alexandre.niveau_AT_gmail.com>
Date: Fri, 15 May 2015 00:29:48 +0200


I found some bugs in ls.

1. option -S does not work on its own:

$ echo "aa" >a; echo "b" >b; echo "ccc">c
$ ls -S

First attached patch fixes this.

2. When filenames contain control chars, it only works fine when no
option among -tSFilpR is specified:

$ touch "$(printf "toto\ntiti")"
$ ls -tq
ls: lstat toto?titi: No such file or directory

Second attached patch fixes this. Basically the problem was that
ent->name was modified “in place”. With the patch, the non-printable
chars are “sanitized” only when printed out. This also makes -q work
with -U (ent->name was not modified in this code path).

For the sanitizing function, I choose not to return a modified string in
order to avoid strdup-ing and free-ing, given that the sanitized name is
never used more than once. It causes some one-line printf's to be
exploded into several puts, though.

Not sure about all my choices; criticism is welcome.


-- AN

Received on Fri May 15 2015 - 00:29:48 CEST

This archive was generated by hypermail 2.3.0 : Fri May 15 2015 - 00:36:07 CEST