diff --git a/ChangeLog b/ChangeLog index 43c037aa10f29a7c38f286f3b5eec76c245bcb1f..19ea27e56285d9b310225401db2b02a69880de54 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,8 @@ it will also work for do_fileresearch(). * src/text.c (do_int_spell_fix): Save and restore the global flags in the same short and quick way as above. + * src/nano.c (main): Initialize the search and replace strings in + a central place, to get rid of a bunch of ifs. 2015-04-20 Benno Schulenberg <bensberg@justemail.net> * src/winio.c (need_horizontal_update, need_vertical_update): Fuse diff --git a/src/browser.c b/src/browser.c index 39eedf6c1d28e5d1c1c9f00f45b163845af0fde8..47bac75b15c8ea17a3d7265c875b04089d1c73fa 100644 --- a/src/browser.c +++ b/src/browser.c @@ -706,9 +706,6 @@ int filesearch_init(void) int input; char *buf; - if (last_search == NULL) - last_search = mallocstrcpy(NULL, ""); - if (last_search[0] != '\0') { char *disp = display_string(last_search, 0, COLS / 3, FALSE); @@ -844,9 +841,6 @@ void do_filesearch(void) /* Search for the last given filename again without prompting. */ void do_fileresearch(void) { - if (last_search == NULL) - last_search = mallocstrcpy(NULL, ""); - if (last_search[0] == '\0') statusbar(_("No current search pattern")); else diff --git a/src/global.c b/src/global.c index 2d22e462b13bbcd029bb24de0c29c46de144b8a7..c93b78c4ea849ea886265ffd93ea075a4315571c 100644 --- a/src/global.c +++ b/src/global.c @@ -1602,10 +1602,8 @@ void thanks_for_all_the_fish(void) if (full_operating_dir != NULL) free(full_operating_dir); #endif - if (last_search != NULL) - free(last_search); - if (last_replace != NULL) - free(last_replace); + free(last_search); + free(last_replace); #ifndef DISABLE_SPELLER if (alt_speller != NULL) free(alt_speller); diff --git a/src/nano.c b/src/nano.c index c2cc3d5f0f38a6ee6d75644ef490b1fa5c974d63..8291cf3d0261252622de372a6d7e05f0ee135fd6 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2648,6 +2648,10 @@ int main(int argc, char **argv) #endif /* !DISABLE_NANORC */ #endif /* !NANO_TINY */ + /* Initialize the search and replace strings. */ + last_search = mallocstrcpy(NULL, ""); + last_replace = mallocstrcpy(NULL, ""); + /* If tabsize wasn't specified, set its default value. */ if (tabsize == -1) tabsize = WIDTH_OF_TAB; diff --git a/src/search.c b/src/search.c index c1d8c5b7ef795c546400805d3513df0aab66da80..923206aecce5f264ff6dea353ffa50c4ab226a00 100644 --- a/src/search.c +++ b/src/search.c @@ -120,10 +120,6 @@ void search_replace_abort(void) void search_init_globals(void) { focusing = TRUE; - if (last_search == NULL) - last_search = mallocstrcpy(NULL, ""); - if (last_replace == NULL) - last_replace = mallocstrcpy(NULL, ""); } /* Set up the system variables for a search or replace. If use_answer