From d4b7b924925283e5cf17f1b929d22b3d700ed68b Mon Sep 17 00:00:00 2001 From: marprok Date: Tue, 20 Aug 2019 20:59:55 +0300 Subject: [PATCH] Userland: ls division by zero. When the terminal app window became smaller than the longest filename, a division by zero occured while calculating the offset. --- Userland/ls.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Userland/ls.cpp b/Userland/ls.cpp index 6e94e6de6e..bbd250614e 100644 --- a/Userland/ls.cpp +++ b/Userland/ls.cpp @@ -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.