diff options
author | Chris Davis <cd.rattan@gmail.com> | 2014-06-16 17:36:16 -0700 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2014-10-01 14:32:08 +0200 |
commit | 55662513e14c026eb4cfa044ed772b31be5d6ab9 (patch) | |
tree | 2615f4b05deef0495a1f1d8260257d3a953149f7 | |
parent | c85cc6b8360284c64d60ff4d09ca8d5e03188f7b (diff) | |
download | samba-55662513e14c026eb4cfa044ed772b31be5d6ab9.tar.gz samba-55662513e14c026eb4cfa044ed772b31be5d6ab9.tar.xz samba-55662513e14c026eb4cfa044ed772b31be5d6ab9.zip |
regedit: handle awkward window sizes better
This fixes some assertion failures and an infinte loop that occurs
when the terminal window is shrunk down far enough to the point
regedit can't fit everything on screen.
Signed-off-by: Chris Davis <cd.rattan@gmail.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
-rw-r--r-- | source3/utils/regedit_list.c | 23 | ||||
-rw-r--r-- | source3/utils/regedit_treeview.c | 7 | ||||
-rw-r--r-- | source3/utils/regedit_valuelist.c | 7 |
3 files changed, 25 insertions, 12 deletions
diff --git a/source3/utils/regedit_list.c b/source3/utils/regedit_list.c index 417dea8abc..ac4e24091c 100644 --- a/source3/utils/regedit_list.c +++ b/source3/utils/regedit_list.c @@ -271,6 +271,7 @@ static WERROR put_data(struct multilist *list) return WERR_OK; } +#define MIN_WIDTH 3 static struct multilist_column *find_widest_column(struct multilist *list) { unsigned col; @@ -285,6 +286,10 @@ static struct multilist_column *find_widest_column(struct multilist *list) } } + if (colp->width < MIN_WIDTH) { + return NULL; + } + return colp; } @@ -295,6 +300,7 @@ static WERROR calc_column_widths(struct multilist *list) size_t len; const char *item; size_t width, total_width, overflow; + struct multilist_column *colp; /* calculate the maximum widths for each column */ for (col = 0; col < list->ncols; ++col) { @@ -335,19 +341,12 @@ static WERROR calc_column_widths(struct multilist *list) } overflow = total_width - list->window_width; - /* the window is so narrow that no amount of trimming will - help fit the data. just give up. */ - if (overflow > width) { - return WERR_OK; - } - /* keep trimming from the widest column until the row fits */ - while (overflow) { - struct multilist_column *colp = find_widest_column(list); - size_t max_trim = colp->width / 3; - size_t trim = MIN(overflow, max_trim); - colp->width -= trim; - overflow -= trim; + /* attempt to trim as much as possible to fit all the columns to + the window */ + while (overflow && (colp = find_widest_column(list))) { + colp->width--; + overflow--; } return WERR_OK; diff --git a/source3/utils/regedit_treeview.c b/source3/utils/regedit_treeview.c index 47765c16de..9962ad99fb 100644 --- a/source3/utils/regedit_treeview.c +++ b/source3/utils/regedit_treeview.c @@ -445,7 +445,14 @@ void tree_view_resize(struct tree_view *view, int nlines, int ncols, WINDOW *nwin, *nsub; nwin = newwin(nlines, ncols, begin_y, begin_x); + if (nwin == NULL) { + return; + } nsub = subwin(nwin, nlines - 2, ncols - 2, begin_y + 1, begin_x + 1); + if (nsub == NULL) { + delwin(nwin); + return; + } replace_panel(view->panel, nwin); delwin(view->sub); delwin(view->window); diff --git a/source3/utils/regedit_valuelist.c b/source3/utils/regedit_valuelist.c index 1c80c0911b..9557c8ca6a 100644 --- a/source3/utils/regedit_valuelist.c +++ b/source3/utils/regedit_valuelist.c @@ -183,7 +183,14 @@ void value_list_resize(struct value_list *vl, int nlines, int ncols, WINDOW *nwin, *nsub; nwin = newwin(nlines, ncols, begin_y, begin_x); + if (nwin == NULL) { + return; + } nsub = subwin(nwin, nlines - 2, ncols - 2, begin_y + 1, begin_x + 1); + if (nsub == NULL) { + delwin(nwin); + return; + } replace_panel(vl->panel, nwin); delwin(vl->sub); delwin(vl->window); |