summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorC. Davis <cd.rattan@gmail.com>2012-07-27 18:39:54 -0700
committerMichael Adam <obnox@samba.org>2013-04-29 13:05:58 +0200
commit5e0f4be8e2123ccf9f6beece95b187cd2676ff24 (patch)
tree55f8e7b41b2ee46432365c9c720eaf3c25a8cf01 /source3
parent6155abcf82f0bb03e62f7fc4b1df3f7260337bc3 (diff)
downloadsamba-5e0f4be8e2123ccf9f6beece95b187cd2676ff24.tar.gz
samba-5e0f4be8e2123ccf9f6beece95b187cd2676ff24.tar.bz2
samba-5e0f4be8e2123ccf9f6beece95b187cd2676ff24.zip
regedit: Improve calculation for centering dialogs.
Add some sanity checks to avoid crashing. Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'source3')
-rw-r--r--source3/utils/regedit_dialog.c42
1 files changed, 32 insertions, 10 deletions
diff --git a/source3/utils/regedit_dialog.c b/source3/utils/regedit_dialog.c
index 419c4081e0..b5e41ee901 100644
--- a/source3/utils/regedit_dialog.c
+++ b/source3/utils/regedit_dialog.c
@@ -86,15 +86,40 @@ fail:
}
-struct dialog *dialog_center_new(TALLOC_CTX *ctx, const char *title, int nlines,
- int ncols, WINDOW *below)
+static void center_dialog_above_window(WINDOW *below, int *nlines, int *ncols,
+ int *y, int *x)
{
- int y, x, maxy, maxx;
+ int maxy, maxx;
+ int centery, centerx;
getmaxyx(below, maxy, maxx);
- y = maxy / 2 - nlines;
- x = maxx / 2 - ncols;
+ centery = maxy / 2;
+ centerx = maxx / 2;
+ *y = 0;
+ *x = 0;
+
+ if (*nlines > maxy) {
+ *nlines = maxy;
+ }
+ if (*ncols > maxx) {
+ *ncols = maxx;
+ }
+
+ if (*nlines < centery) {
+ *y = centery - *nlines;
+ }
+ if (*ncols < centerx) {
+ *x = centerx - *ncols;
+ }
+}
+
+struct dialog *dialog_center_new(TALLOC_CTX *ctx, const char *title, int nlines,
+ int ncols, WINDOW *below)
+{
+ int y, x;
+
+ center_dialog_above_window(below, &nlines, &ncols, &y, &x);
return dialog_new(ctx, title, nlines, ncols, y, x);
}
@@ -161,12 +186,9 @@ struct dialog *dialog_choice_center_new(TALLOC_CTX *ctx, const char *title,
const char **choices, int nlines,
int ncols, WINDOW *below)
{
- int y, x, maxy, maxx;
-
- getmaxyx(below, maxy, maxx);
+ int y, x;
- y = maxy / 2 - nlines;
- x = maxx / 2 - ncols;
+ center_dialog_above_window(below, &nlines, &ncols, &y, &x);
return dialog_choice_new(ctx, title, choices, nlines, ncols, y, x);
}