mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-01 05:39:02 +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:
parent
41e0e4cdd7
commit
9724797da7
Notes:
sideshowbarker
2024-07-17 08:37:36 +09:00
Author: https://github.com/Tyrubias
Commit: 9724797da7
Pull-request: https://github.com/SerenityOS/serenity/pull/16679
Issue: https://github.com/SerenityOS/serenity/issues/16678
Reviewed-by: https://github.com/LucasChollet
1 changed files with 4 additions and 4 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue