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
/* 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);
/* 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)
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;