Skip to content

Commit

Permalink
Userland: ls division by zero.
Browse files Browse the repository at this point in the history
When the terminal app window became smaller than the longest filename,
a division by zero occured while calculating the offset.
  • Loading branch information
marprok authored and awesomekling committed Aug 20, 2019
1 parent c106ec4 commit d4b7b92
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Userland/ls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ int do_file_system_object_short(const char* path)

if (!print_filesystem_object_short(pathbuf, name.characters(), &nprinted))
return 2;
int offset = columns % longest_name / (columns / longest_name);
int offset = 0;
if (columns > longest_name)
offset = columns % longest_name / (columns / longest_name);
/* The offset must be at least 2 because:
* - With each file an aditional char is printed e.g. '@','*'.
* - Each filename must be separated by a space.
Expand Down

0 comments on commit d4b7b92

Please sign in to comment.