@@ -717,7 +717,7 @@ static void search_conf(void)
_("Search Configuration Parameter"),
_("Enter " CONFIG_ " (sub)string to search for "
"(with or without \"" CONFIG_ "\")"),
- "", dialog_input_result, &dialog_input_result_len);
+ "", &dialog_input_result, &dialog_input_result_len);
switch (dres) {
case 0:
break;
@@ -1384,7 +1384,7 @@ static void conf_string(struct menu *menu)
prompt ? _(prompt) : _("Main Menu"),
heading,
sym_get_string_value(menu->sym),
- dialog_input_result,
+ &dialog_input_result,
&dialog_input_result_len);
switch (res) {
case 0:
@@ -1410,7 +1410,7 @@ static void conf_load(void)
res = dialog_inputbox(main_window,
NULL, load_config_text,
filename,
- dialog_input_result,
+ &dialog_input_result,
&dialog_input_result_len);
switch (res) {
case 0:
@@ -1441,7 +1441,7 @@ static void conf_save(void)
res = dialog_inputbox(main_window,
NULL, save_config_text,
filename,
- dialog_input_result,
+ &dialog_input_result,
&dialog_input_result_len);
switch (res) {
case 0:
@@ -1508,15 +1508,6 @@ int main(int ac, char **av)
single_menu_mode = 1;
}
- /* initially alloc 2048 bytes for dialog_input_result */
- dialog_input_result_len = 2048;
- dialog_input_result = malloc(dialog_input_result_len);
- if (!dialog_input_result) {
- fprintf(stderr, "Not enough memory for dialog_input_result(%d)\n",
- dialog_input_result_len);
- exit(1);
- }
-
/* Initialize curses */
initscr();
/* set color theme */
@@ -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;
@@ -368,16 +368,16 @@ int dialog_inputbox(WINDOW *main_window,
int res = -1;
int cursor_position = strlen(init);
int cursor_form_win;
+ char *result = *resultp;
- if (strlen(init) > *result_len) {
- do {
- *result_len *= 2;
- } while (strlen(init) > *result_len);
+ if (strlen(init) + 1 > *result_len) {
+ *result_len = strlen(init) + 1;
result = realloc(result, *result_len);
- /* here didn't check result, if it's NULL,
- just let it silently fail (SegFault) */
+ *resultp = result;
}
@@ -480,11 +480,9 @@ int dialog_inputbox(WINDOW *main_window,
if ((isgraph(res) || isspace(res))) {
/* one for new char, one for '\0' */
if (len+2 > *result_len) {
- do {
- *result_len *= 2;
- } while (len+2 > *result_len);
+ *result_len = len+2;
result = realloc(result, *result_len);
- /* silently fail in the same way above */
+ *resultp = result;
}
/* insert the char at the proper position */
memmove(&result[cursor_position+1],
@@ -89,7 +89,7 @@ void fill_window(WINDOW *win, const char *text);
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);
void refresh_all_windows(WINDOW *main_window);
void show_scroll_win(WINDOW *main_window,
const char *title,