diff --git a/ChangeLog b/ChangeLog index 7c3afa0a00a9e239436b225091d8d6cd3767d9a1..916f7f71d2e9869cd2cf82cda6a69992a30e6026 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,10 @@ CVS Code - Affects files.c:load_open_file(), nano.c:main(), search.c:findnextstr(), winio.c:statusbar() and do_cursorpos() (David Benbennick). + - 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!) - cut.c: do_cut_text() - Fix incorrect cursor location when cutting long lines diff --git a/proto.h b/proto.h index 645e822604ec0940b912909772bd82814e9731cc..8f202b56c2a7bf7b34dde38774012a91aca2cef0 100644 --- a/proto.h +++ b/proto.h @@ -334,7 +334,7 @@ void do_rcfile(void); /* Public functions in search.c */ #ifdef HAVE_REGEX_H -void regexp_init(const char *regexp); +int regexp_init(const char *regexp); void regexp_cleanup(void); #endif void not_found_msg(const char *str); diff --git a/search.c b/search.c index 2966594c1d6a6fe560a2e21dc21ffd5247545f77..5a625985c84589bb3b6e3be53c846387e4929a73 100644 --- a/search.c +++ b/search.c @@ -34,10 +34,15 @@ /* Regular expression helper functions */ #ifdef HAVE_REGEX_H -void regexp_init(const char *regexp) +int regexp_init(const char *regexp) { - regcomp(&search_regexp, regexp, (ISSET(CASE_SENSITIVE) ? 0 : REG_ICASE) | REG_EXTENDED); + /* Hmm, perhaps we should check for whether regcomp returns successfully */ + if (regcomp(&search_regexp, regexp, (ISSET(CASE_SENSITIVE) ? 0 : REG_ICASE) + | REG_EXTENDED) != 0) + return 0; + SET(REGEXP_COMPILED); + return 1; } void regexp_cleanup(void) @@ -165,7 +170,16 @@ int search_init(int replacing) case 0: /* They entered something new */ #ifdef HAVE_REGEX_H if (ISSET(USE_REGEXP)) - regexp_init(answer); + if (regexp_init(answer) == 0) { + statusbar(_("Invalid regex!")); + reset_cursor(); + free(backupstring); + backupstring = NULL; +#ifndef NANO_SMALL + search_history.current = search_history.next; +#endif + return -3; + } #endif free(backupstring); backupstring = NULL;