diff options
author | Cheng Renquan <crquan@gmail.com> | 2011-09-01 13:52:20 -0400 |
---|---|---|
committer | Michal Marek <mmarek@suse.cz> | 2011-09-09 08:40:08 -0400 |
commit | 5ea9f64ffc073bf2882f6aa83b0dad3609b1e67a (patch) | |
tree | 3915aa9950e2b9e6404acb48a945c00662964954 /scripts/kconfig/nconf.gui.c | |
parent | cd58a90fa6ff2ec86bcc9e399acfd6dcc97268b3 (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/kconfig/nconf.gui.c')
-rw-r--r-- | scripts/kconfig/nconf.gui.c | 20 |
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, ...) | |||
356 | 356 | ||
357 | int dialog_inputbox(WINDOW *main_window, | 357 | int 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], |