mirror of git://git.sv.gnu.org/nano.git
- 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
This commit is contained in:
parent
e92a7bcb78
commit
5d71514f21
|
@ -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
|
||||
|
|
2
proto.h
2
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);
|
||||
|
|
20
search.c
20
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;
|
||||
|
|
Loading…
Reference in New Issue