]> www.infradead.org Git - users/hch/misc.git/commitdiff
kconfig: nconf: Format and print 'line' without a temporary copy
authorThorsten Blum <thorsten.blum@linux.dev>
Mon, 11 Aug 2025 16:16:48 +0000 (18:16 +0200)
committerNathan Chancellor <nathan@kernel.org>
Mon, 18 Aug 2025 17:46:19 +0000 (10:46 -0700)
Use "%.*s" as the format specifier and supply the 'line' length 'len' to
mvwprintw() to format and print each line without making a temporary
copy. Remove the temporary buffer.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: Nicolas Schier <nsc@kernel.org>
Link: https://lore.kernel.org/r/20250811161650.37428-2-thorsten.blum@linux.dev
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
scripts/kconfig/nconf.gui.c

index 7206437e784a0a85408b45bc84d7566f4d8917a4..2d097bc7ef1a9d674dbbdc8c470f3e72c1f96d30 100644 (file)
@@ -173,12 +173,10 @@ void fill_window(WINDOW *win, const char *text)
        /* do not go over end of line */
        total_lines = min(total_lines, y);
        for (i = 0; i < total_lines; i++) {
-               char tmp[x+10];
                const char *line = get_line(text, i);
-               int len = get_line_length(line);
-               strncpy(tmp, line, min(len, x));
-               tmp[len] = '\0';
-               mvwprintw(win, i, 0, "%s", tmp);
+               int len = min(get_line_length(line), x);
+
+               mvwprintw(win, i, 0, "%.*s", len, line);
        }
 }