diff options
author | Victor Song <vms2@rice.edu> | 2022-12-26 18:15:28 -0500 |
---|---|---|
committer | Sam Atkins <atkinssj@gmail.com> | 2023-01-01 11:03:29 +0000 |
commit | 9724797da7816525e71f89e464752aeaa72f48be (patch) | |
tree | dfd7f7adb82ab4939570e8a4af0a65e3f1010320 /Userland/Utilities | |
parent | 41e0e4cdd7377fb2df71903a0a0466a26a288eca (diff) | |
download | serenity-9724797da7816525e71f89e464752aeaa72f48be.zip |
Utilities: Print arbitrary bytes in `ls`
Currently, `ls` crashes when printing certain byte sequences.
This is likely due to an out-of-bounds error when iterating
through the `StringView` representing the file name to be printed.
We switch to using an index-based for loop to a range-based
for loop. This fixes #16678.
Diffstat (limited to 'Userland/Utilities')
-rw-r--r-- | Userland/Utilities/ls.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/Userland/Utilities/ls.cpp b/Userland/Utilities/ls.cpp index 065466e433..1779e4c4f5 100644 --- a/Userland/Utilities/ls.cpp +++ b/Userland/Utilities/ls.cpp @@ -207,12 +207,12 @@ static int print_escaped(StringView name) return utf8_name.length(); } - for (int i = 0; name[i] != '\0'; i++) { - if (isprint(name[i])) { - putchar(name[i]); + for (auto c : name) { + if (isprint(c)) { + putchar(c); printed++; } else { - printed += printf("\\%03d", name[i]); + printed += printf("\\%03d", c); } } |