regex handling
Change the regex_error_desc() interface. Have the caller pass in
a pointer to a buffer of at least BUFSZ characters and have
regex_error_desc() populate that. No need for static buffers or
extra dynamic alloction.
Also, change it to never return Null. None of its callers were
checking for that and could have passed Null to config_error_add()
or raw_print(). printf("%s", NULL) produces "null" on OSX but other
systems would probably crash if a Null result ever actually occurred.
The error explanation returned by cppregex included a trailing period.
config_error_add() adds one, so the message ended up with two. Have
regex_error_desc() check for final period and strip it off if found.
(My test case used a menucolor pattern of "[" which triggers an error
about mismatched brackets.)
Reformat cppregex.cpp; treat 'extern "C" {' as if it isn't introducing
a nested block. Fix the '#include <hack.h>' that 'make depend' was
ignoring.
This commit is contained in:
@@ -6916,7 +6916,8 @@ msgtype_add(int typ, char *pattern)
|
||||
/* test_regex_pattern() has already validated this regexp but parsing
|
||||
it again could conceivably run out of memory */
|
||||
if (!regex_compile(pattern, tmp->regex)) {
|
||||
const char *re_error_desc = regex_error_desc(tmp->regex);
|
||||
char errbuf[BUFSZ];
|
||||
char *re_error_desc = regex_error_desc(tmp->regex, errbuf);
|
||||
|
||||
/* free first in case reason for failure was insufficient memory */
|
||||
regex_free(tmp->regex);
|
||||
@@ -7048,7 +7049,7 @@ test_regex_pattern(const char *str, const char *errmsg)
|
||||
{
|
||||
static const char def_errmsg[] = "NHregex error";
|
||||
struct nhregex *match;
|
||||
const char *re_error_desc;
|
||||
char *re_error_desc, errbuf[BUFSZ];
|
||||
boolean retval;
|
||||
|
||||
if (!str)
|
||||
@@ -7066,7 +7067,7 @@ test_regex_pattern(const char *str, const char *errmsg)
|
||||
/* get potential error message before freeing regexp and free regexp
|
||||
before issuing message in case the error is "ran out of memory"
|
||||
since message delivery might need to allocate some memory */
|
||||
re_error_desc = !retval ? regex_error_desc(match) : 0;
|
||||
re_error_desc = !retval ? regex_error_desc(match, errbuf) : 0;
|
||||
/* discard regexp; caller will re-parse it after validating other stuff */
|
||||
regex_free(match);
|
||||
/* if returning failure, tell player */
|
||||
@@ -7089,7 +7090,8 @@ add_menu_coloring_parsed(const char *str, int c, int a)
|
||||
/* test_regex_pattern() has already validated this regexp but parsing
|
||||
it again could conceivably run out of memory */
|
||||
if (!regex_compile(str, tmp->match)) {
|
||||
const char *re_error_desc = regex_error_desc(tmp->match);
|
||||
char errbuf[BUFSZ];
|
||||
char *re_error_desc = regex_error_desc(tmp->match, errbuf);
|
||||
|
||||
/* free first in case reason for regcomp failure was out-of-memory */
|
||||
regex_free(tmp->match);
|
||||
@@ -8242,7 +8244,8 @@ add_autopickup_exception(const char *mapping)
|
||||
ape = (struct autopickup_exception *) alloc(sizeof *ape);
|
||||
ape->regex = regex_init();
|
||||
if (!regex_compile(text, ape->regex)) {
|
||||
const char *re_error_desc = regex_error_desc(ape->regex);
|
||||
char errbuf[BUFSZ];
|
||||
char *re_error_desc = regex_error_desc(ape->regex, errbuf);
|
||||
|
||||
/* free first in case reason for failure was insufficient memory */
|
||||
regex_free(ape->regex);
|
||||
|
||||
@@ -1453,7 +1453,8 @@ add_sound_mapping(const char* mapping)
|
||||
new_map->next = soundmap;
|
||||
|
||||
if (!regex_compile(text, new_map->regex)) {
|
||||
const char *re_error_desc = regex_error_desc(new_map->regex);
|
||||
char errbuf[BUFSZ];
|
||||
char *re_error_desc = regex_error_desc(new_map->regex, errbuf);
|
||||
|
||||
regex_free(new_map->regex);
|
||||
free((genericptr_t) new_map->filename);
|
||||
|
||||
Reference in New Issue
Block a user