From: Chris Allegretta Date: Mon, 3 Feb 2003 07:07:40 +0000 (+0000) Subject: Apply the same regexp_init checks to using last|search in search_init() X-Git-Tag: v1.1.99pre2~2 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=d89eb91e77c9a63c2804423bffbfcccba8044497;p=nano.git Apply the same regexp_init checks to using last|search in search_init() git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1418 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 5837472b..99fc60ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,7 +20,8 @@ CVS Code - - Fix nano crashing when searching/replacing an invalid regex (try "^*"). Changed regexp_init() to return 1 or 0 based on regcomp()'s return value and search_init - to exit with an error message (sorry Jordi!) + to exit with an error message (sorry Jordi!). Added + another check when using last_search instead of answer. - Move regcomp into rcfile.c rather than each display refresh of winio.c. New function rcfile.c:nregcomp(). This fixes much of nano's resource hogging behavior diff --git a/search.c b/search.c index 5a625985..5af81656 100644 --- a/search.c +++ b/search.c @@ -102,6 +102,9 @@ int search_init(int replacing) int i = 0; char *buf; static char *backupstring = NULL; +#ifdef HAVE_REGEX_H + const char *regex_error = _("Invalid regex \"%s\""); +#endif /* HAVE_REGEX_H */ search_init_globals(); @@ -164,14 +167,20 @@ int search_init(int replacing) #ifdef HAVE_REGEX_H if (ISSET(USE_REGEXP)) /* If answer is "", use last_search! */ - regexp_init(last_search); + if (regexp_init(last_search) == 0) { + statusbar(regex_error, last_search); + reset_cursor(); + free(backupstring); + backupstring = NULL; + return -3; + } #endif break; case 0: /* They entered something new */ #ifdef HAVE_REGEX_H if (ISSET(USE_REGEXP)) if (regexp_init(answer) == 0) { - statusbar(_("Invalid regex!")); + statusbar(regex_error, answer); reset_cursor(); free(backupstring); backupstring = NULL;