Module Name:    src
Committed By:   martin
Date:           Thu Jun  2 15:36:08 UTC 2022

Modified Files:
        src/usr.sbin/sysinst: disks.c

Log Message:
If we get the disk description via device properties, the strings may
have arbitrary length - make sure the "available disks" menu fits
on the current screen.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/usr.sbin/sysinst/disks.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/sysinst/disks.c
diff -u src/usr.sbin/sysinst/disks.c:1.80 src/usr.sbin/sysinst/disks.c:1.81
--- src/usr.sbin/sysinst/disks.c:1.80	Mon May 16 18:44:38 2022
+++ src/usr.sbin/sysinst/disks.c	Thu Jun  2 15:36:08 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: disks.c,v 1.80 2022/05/16 18:44:38 martin Exp $ */
+/*	$NetBSD: disks.c,v 1.81 2022/06/02 15:36:08 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -881,6 +881,7 @@ find_disks(const char *doingwhat, bool a
 	int i = 0, dno, wno, skipped = 0;
 	int already_found, numdisks, selected_disk = -1;
 	int menu_no, w_menu_no;
+	size_t max_desc_len;
 	struct pm_devs *pm_i, *pm_last = NULL;
 	bool any_wedges = false;
 
@@ -895,6 +896,13 @@ find_disks(const char *doingwhat, bool a
 	refresh();
 	/* Kill typeahead, it won't be what the user had in mind */
 	fpurge(stdin);
+	/*
+	 * we need space for the menu box and the row label,
+	 * this sums up to 7 characters.
+	 */
+	max_desc_len = getmaxx(stdscr) - 8;
+	if (max_desc_len >= __arraycount(disks[0].dd_descr))
+		max_desc_len = __arraycount(disks[0].dd_descr) - 1;
 
 	/*
 	 * partman_go: <0 - we want to see menu with extended partitioning
@@ -923,6 +931,7 @@ find_disks(const char *doingwhat, bool a
 					any_wedges = true;
 					wedge_menu[wno].opt_name =
 					    disks[i].dd_descr;
+					disks[i].dd_descr[max_desc_len] = 0;
 					wedge_menu[wno].opt_flags = OPT_EXIT;
 					wedge_menu[wno].opt_action =
 					    set_menu_select;
@@ -931,6 +940,7 @@ find_disks(const char *doingwhat, bool a
 				} else {
 					dsk_menu[dno].opt_name =
 					    disks[i].dd_descr;
+					disks[i].dd_descr[max_desc_len] = 0;
 					dsk_menu[dno].opt_flags = OPT_EXIT;
 					dsk_menu[dno].opt_action =
 					    set_menu_select;

Reply via email to