summaryrefslogtreecommitdiffstats
path: root/scripts/kconfig/nconf.gui.c
diff options
context:
space:
mode:
authorCheng Renquan <crquan@gmail.com>2011-09-01 10:52:20 -0700
committerMichal Marek <mmarek@suse.cz>2011-09-09 14:40:08 +0200
commit5ea9f64ffc073bf2882f6aa83b0dad3609b1e67a (patch)
tree3915aa9950e2b9e6404acb48a945c00662964954 /scripts/kconfig/nconf.gui.c
parentcd58a90fa6ff2ec86bcc9e399acfd6dcc97268b3 (diff)
downloadlinux-5ea9f64ffc073bf2882f6aa83b0dad3609b1e67a.tar.bz2
scripts/kconfig/nconf: dynamically alloc dialog_input_result
To support unlimited length string config items; No check for realloc return value keeps code simple, and to be consistent with other existing unchecked malloc in kconfig. Signed-off-by: Cheng Renquan <crquan@gmail.com> Signed-off-by: Arnaud Lacombe <lacombar@gmail.com>
Diffstat (limited to 'scripts/kconfig/nconf.gui.c')
-rw-r--r--scripts/kconfig/nconf.gui.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c
index 3ce2a7c0bda6..d64bc1c24c20 100644
--- a/scripts/kconfig/nconf.gui.c
+++ b/scripts/kconfig/nconf.gui.c
@@ -356,7 +356,7 @@ int btn_dialog(WINDOW *main_window, const char *msg, int btn_num, ...)
int dialog_inputbox(WINDOW *main_window,
const char *title, const char *prompt,
- const char *init, char *result, int result_len)
+ const char *init, char **resultp, int *result_len)
{
int prompt_lines = 0;
int prompt_width = 0;
@@ -367,7 +367,12 @@ int dialog_inputbox(WINDOW *main_window,
int i, x, y;
int res = -1;
int cursor_position = strlen(init);
+ char *result = *resultp;
+ if (strlen(init)+1 > *result_len) {
+ *result_len = strlen(init)+1;
+ *resultp = result = realloc(result, *result_len);
+ }
/* find the widest line of msg: */
prompt_lines = get_line_no(prompt);
@@ -384,7 +389,7 @@ int dialog_inputbox(WINDOW *main_window,
y = (LINES-(prompt_lines+4))/2;
x = (COLS-(prompt_width+4))/2;
- strncpy(result, init, result_len);
+ strncpy(result, init, *result_len);
/* create the windows */
win = newwin(prompt_lines+6, prompt_width+7, y, x);
@@ -443,7 +448,7 @@ int dialog_inputbox(WINDOW *main_window,
case KEY_UP:
case KEY_RIGHT:
if (cursor_position < len &&
- cursor_position < min(result_len, prompt_width))
+ cursor_position < min(*result_len, prompt_width))
cursor_position++;
break;
case KEY_DOWN:
@@ -452,8 +457,13 @@ int dialog_inputbox(WINDOW *main_window,
cursor_position--;
break;
default:
- if ((isgraph(res) || isspace(res)) &&
- len-2 < result_len) {
+ if ((isgraph(res) || isspace(res))) {
+ /* one for new char, one for '\0' */
+ if (len+2 > *result_len) {
+ *result_len = len+2;
+ *resultp = result = realloc(result,
+ *result_len);
+ }
/* insert the char at the proper position */
memmove(&result[cursor_position+1],
&result[cursor_position],