commit 5d71514f211c5b44a61870252c0df71373891657
parent e92a7bcb78d6d81c06af68cd42397ea5bf6b409e
Author: Chris Allegretta <chrisa@asty.org>
Date: Wed, 29 Jan 2003 04:18:37 +0000
- 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)
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1406 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Diffstat:
3 files changed, 22 insertions(+), 4 deletions(-)
diff --git 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
@@ -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
@@ -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;