]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
terminal-util: calculate array index only once
authorLennart Poettering <lennart@amutable.com>
Thu, 25 Jun 2026 09:06:22 +0000 (11:06 +0200)
committerLennart Poettering <lennart@amutable.com>
Thu, 2 Jul 2026 06:18:36 +0000 (08:18 +0200)
src/basic/terminal-util.c

index cde9f1ec8c09186809257ba8d05e51a70b04fc5e..e756fcd45ab12c6af4f88be9a467e5138d811f63 100644 (file)
@@ -564,8 +564,7 @@ int show_menu(char **x,
         if (break_lines > 2)
                 break_lines--;
 
-        /* The first page gets two extra lines, since we want to show
-         * a title */
+        /* The first page gets two extra lines, since we want to show a title */
         size_t break_modulo = break_lines;
         if (break_modulo > 3)
                 break_modulo -= 3;
@@ -575,17 +574,18 @@ int show_menu(char **x,
                 for (size_t j = 0; j < n_columns; j++) {
                         _cleanup_free_ char *e = NULL;
 
-                        if (j * per_column + i >= n)
+                        size_t p = j * per_column + i;
+                        if (p >= n)
                                 break;
 
-                        e = ellipsize(x[j * per_column + i], column_width, ellipsize_percentage);
+                        e = ellipsize(x[p], column_width, ellipsize_percentage);
                         if (!e)
                                 return -ENOMEM;
 
                         if (with_numbers)
                                 printf("%s%4zu)%s ",
                                        ansi_grey(),
-                                       j * per_column + i + 1,
+                                       p + 1,
                                        ansi_normal());
 
                         if (grey_prefix && startswith(e, grey_prefix)) {