]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
terminal-util: use LESS_BY() where appropriate
authorLennart Poettering <lennart@amutable.com>
Thu, 25 Jun 2026 09:07:15 +0000 (11:07 +0200)
committerLennart Poettering <lennart@amutable.com>
Thu, 2 Jul 2026 06:18:36 +0000 (08:18 +0200)
src/basic/terminal-util.c

index e756fcd45ab12c6af4f88be9a467e5138d811f63..436daa731195ac9baa4eebe30d98ca1710dbb489 100644 (file)
@@ -531,6 +531,7 @@ int show_menu(char **x,
 
         assert(x);
         assert(n_columns > 0);
+        assert(column_width > 0);
 
         if (n_columns == SIZE_MAX)
                 n_columns = 3;
@@ -542,16 +543,16 @@ int show_menu(char **x,
                 size_t column_max = (columns()-1) / n_columns;
 
                 /* Subtract room for numbers */
-                if (with_numbers && column_max > 6)
-                        column_max -= 6;
+                if (with_numbers)
+                        column_max = LESS_BY(column_max, 6U);
 
                 /* If columns would get too tight let's make this a linear list instead. */
                 if (column_max < 10 && widest > 10) {
                         n_columns = 1;
                         column_max = columns()-1;
 
-                        if (with_numbers && column_max > 6)
-                                column_max -= 6;
+                        if (with_numbers)
+                                column_max = LESS_BY(column_max, 6U);
                 }
 
                 column_width = CLAMP(widest+1, 10U, column_max);