1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:07:45 +00:00

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.
This commit is contained in:
Victor Song 2022-12-26 18:15:28 -05:00 committed by Sam Atkins
parent 41e0e4cdd7
commit 9724797da7

View file

@ -207,12 +207,12 @@ static int print_escaped(StringView name)
return utf8_name.length(); return utf8_name.length();
} }
for (int i = 0; name[i] != '\0'; i++) { for (auto c : name) {
if (isprint(name[i])) { if (isprint(c)) {
putchar(name[i]); putchar(c);
printed++; printed++;
} else { } else {
printed += printf("\\%03d", name[i]); printed += printf("\\%03d", c);
} }
} }