aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorCheng Renquan <crquan@gmail.com>2011-09-01 13:52:20 -0400
committerMichal Marek <mmarek@suse.cz>2011-09-09 08:40:08 -0400
commit5ea9f64ffc073bf2882f6aa83b0dad3609b1e67a (patch)
tree3915aa9950e2b9e6404acb48a945c00662964954 /scripts
parentcd58a90fa6ff2ec86bcc9e399acfd6dcc97268b3 (diff)
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')
-rw-r--r--scripts/kconfig/nconf.c21
-rw-r--r--scripts/kconfig/nconf.gui.c20
-rw-r--r--scripts/kconfig/nconf.h2
3 files changed, 26 insertions, 17 deletions
diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c
index b113c50209e3..73070cb0b6de 100644
--- a/scripts/kconfig/nconf.c
+++ b/scripts/kconfig/nconf.c
@@ -278,6 +278,9 @@ static int global_exit;
278/* the currently selected button */ 278/* the currently selected button */
279const char *current_instructions = menu_instructions; 279const char *current_instructions = menu_instructions;
280 280
281static char *dialog_input_result;
282static int dialog_input_result_len;
283
281static void conf(struct menu *menu); 284static void conf(struct menu *menu);
282static void conf_choice(struct menu *menu); 285static void conf_choice(struct menu *menu);
283static void conf_string(struct menu *menu); 286static void conf_string(struct menu *menu);
@@ -693,7 +696,6 @@ static void search_conf(void)
693{ 696{
694 struct symbol **sym_arr; 697 struct symbol **sym_arr;
695 struct gstr res; 698 struct gstr res;
696 char dialog_input_result[100];
697 char *dialog_input; 699 char *dialog_input;
698 int dres; 700 int dres;
699again: 701again:
@@ -701,7 +703,7 @@ again:
701 _("Search Configuration Parameter"), 703 _("Search Configuration Parameter"),
702 _("Enter " CONFIG_ " (sub)string to search for " 704 _("Enter " CONFIG_ " (sub)string to search for "
703 "(with or without \"" CONFIG_ "\")"), 705 "(with or without \"" CONFIG_ "\")"),
704 "", dialog_input_result, 99); 706 "", &dialog_input_result, &dialog_input_result_len);
705 switch (dres) { 707 switch (dres) {
706 case 0: 708 case 0:
707 break; 709 break;
@@ -1346,7 +1348,6 @@ static void conf_choice(struct menu *menu)
1346static void conf_string(struct menu *menu) 1348static void conf_string(struct menu *menu)
1347{ 1349{
1348 const char *prompt = menu_get_prompt(menu); 1350 const char *prompt = menu_get_prompt(menu);
1349 char dialog_input_result[256];
1350 1351
1351 while (1) { 1352 while (1) {
1352 int res; 1353 int res;
@@ -1369,8 +1370,8 @@ static void conf_string(struct menu *menu)
1369 prompt ? _(prompt) : _("Main Menu"), 1370 prompt ? _(prompt) : _("Main Menu"),
1370 heading, 1371 heading,
1371 sym_get_string_value(menu->sym), 1372 sym_get_string_value(menu->sym),
1372 dialog_input_result, 1373 &dialog_input_result,
1373 sizeof(dialog_input_result)); 1374 &dialog_input_result_len);
1374 switch (res) { 1375 switch (res) {
1375 case 0: 1376 case 0:
1376 if (sym_set_string_value(menu->sym, 1377 if (sym_set_string_value(menu->sym,
@@ -1390,14 +1391,13 @@ static void conf_string(struct menu *menu)
1390 1391
1391static void conf_load(void) 1392static void conf_load(void)
1392{ 1393{
1393 char dialog_input_result[256];
1394 while (1) { 1394 while (1) {
1395 int res; 1395 int res;
1396 res = dialog_inputbox(main_window, 1396 res = dialog_inputbox(main_window,
1397 NULL, load_config_text, 1397 NULL, load_config_text,
1398 filename, 1398 filename,
1399 dialog_input_result, 1399 &dialog_input_result,
1400 sizeof(dialog_input_result)); 1400 &dialog_input_result_len);
1401 switch (res) { 1401 switch (res) {
1402 case 0: 1402 case 0:
1403 if (!dialog_input_result[0]) 1403 if (!dialog_input_result[0])
@@ -1422,14 +1422,13 @@ static void conf_load(void)
1422 1422
1423static void conf_save(void) 1423static void conf_save(void)
1424{ 1424{
1425 char dialog_input_result[256];
1426 while (1) { 1425 while (1) {
1427 int res; 1426 int res;
1428 res = dialog_inputbox(main_window, 1427 res = dialog_inputbox(main_window,
1429 NULL, save_config_text, 1428 NULL, save_config_text,
1430 filename, 1429 filename,
1431 dialog_input_result, 1430 &dialog_input_result,
1432 sizeof(dialog_input_result)); 1431 &dialog_input_result_len);
1433 switch (res) { 1432 switch (res) {
1434 case 0: 1433 case 0:
1435 if (!dialog_input_result[0]) 1434 if (!dialog_input_result[0])
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, ...)
356 356
357int dialog_inputbox(WINDOW *main_window, 357int dialog_inputbox(WINDOW *main_window,
358 const char *title, const char *prompt, 358 const char *title, const char *prompt,
359 const char *init, char *result, int result_len) 359 const char *init, char **resultp, int *result_len)
360{ 360{
361 int prompt_lines = 0; 361 int prompt_lines = 0;
362 int prompt_width = 0; 362 int prompt_width = 0;
@@ -367,7 +367,12 @@ int dialog_inputbox(WINDOW *main_window,
367 int i, x, y; 367 int i, x, y;
368 int res = -1; 368 int res = -1;
369 int cursor_position = strlen(init); 369 int cursor_position = strlen(init);
370 char *result = *resultp;
370 371
372 if (strlen(init)+1 > *result_len) {
373 *result_len = strlen(init)+1;
374 *resultp = result = realloc(result, *result_len);
375 }
371 376
372 /* find the widest line of msg: */ 377 /* find the widest line of msg: */
373 prompt_lines = get_line_no(prompt); 378 prompt_lines = get_line_no(prompt);
@@ -384,7 +389,7 @@ int dialog_inputbox(WINDOW *main_window,
384 y = (LINES-(prompt_lines+4))/2; 389 y = (LINES-(prompt_lines+4))/2;
385 x = (COLS-(prompt_width+4))/2; 390 x = (COLS-(prompt_width+4))/2;
386 391
387 strncpy(result, init, result_len); 392 strncpy(result, init, *result_len);
388 393
389 /* create the windows */ 394 /* create the windows */
390 win = newwin(prompt_lines+6, prompt_width+7, y, x); 395 win = newwin(prompt_lines+6, prompt_width+7, y, x);
@@ -443,7 +448,7 @@ int dialog_inputbox(WINDOW *main_window,
443 case KEY_UP: 448 case KEY_UP:
444 case KEY_RIGHT: 449 case KEY_RIGHT:
445 if (cursor_position < len && 450 if (cursor_position < len &&
446 cursor_position < min(result_len, prompt_width)) 451 cursor_position < min(*result_len, prompt_width))
447 cursor_position++; 452 cursor_position++;
448 break; 453 break;
449 case KEY_DOWN: 454 case KEY_DOWN:
@@ -452,8 +457,13 @@ int dialog_inputbox(WINDOW *main_window,
452 cursor_position--; 457 cursor_position--;
453 break; 458 break;
454 default: 459 default:
455 if ((isgraph(res) || isspace(res)) && 460 if ((isgraph(res) || isspace(res))) {
456 len-2 < result_len) { 461 /* one for new char, one for '\0' */
462 if (len+2 > *result_len) {
463 *result_len = len+2;
464 *resultp = result = realloc(result,
465 *result_len);
466 }
457 /* insert the char at the proper position */ 467 /* insert the char at the proper position */
458 memmove(&result[cursor_position+1], 468 memmove(&result[cursor_position+1],
459 &result[cursor_position], 469 &result[cursor_position],
diff --git a/scripts/kconfig/nconf.h b/scripts/kconfig/nconf.h
index 58fbda8fc0dc..0d5261705ef5 100644
--- a/scripts/kconfig/nconf.h
+++ b/scripts/kconfig/nconf.h
@@ -89,7 +89,7 @@ void fill_window(WINDOW *win, const char *text);
89int btn_dialog(WINDOW *main_window, const char *msg, int btn_num, ...); 89int btn_dialog(WINDOW *main_window, const char *msg, int btn_num, ...);
90int dialog_inputbox(WINDOW *main_window, 90int dialog_inputbox(WINDOW *main_window,
91 const char *title, const char *prompt, 91 const char *title, const char *prompt,
92 const char *init, char *result, int result_len); 92 const char *init, char **resultp, int *result_len);
93void refresh_all_windows(WINDOW *main_window); 93void refresh_all_windows(WINDOW *main_window);
94void show_scroll_win(WINDOW *main_window, 94void show_scroll_win(WINDOW *main_window,
95 const char *title, 95 const char *title,