summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2014-10-25 23:06:18 +0100
committerVincent Sanders <vince@kyllikki.org>2014-10-25 23:07:00 +0100
commite39606c411bad57de5891965628f6ac278df42ee (patch)
tree697c5404c0a9bbe616bada833db7bb52df9bd778 /utils
parentdf89f689f7ddcb082b4616c6e32cabbb859b3a11 (diff)
downloadnetsurf-e39606c411bad57de5891965628f6ac278df42ee.tar.gz
netsurf-e39606c411bad57de5891965628f6ac278df42ee.tar.bz2
make regex wrapper return errors instead of just aborting
Diffstat (limited to 'utils')
-rw-r--r--utils/url.c12
-rw-r--r--utils/url.h2
-rw-r--r--utils/utils.c9
-rw-r--r--utils/utils.h2
4 files changed, 17 insertions, 8 deletions
diff --git a/utils/url.c b/utils/url.c
index 37fa93967..949478efb 100644
--- a/utils/url.c
+++ b/utils/url.c
@@ -44,10 +44,12 @@ struct url_components_internal {
regex_t url_re, url_up_re;
/* exported interface documented in utils/url.h */
-void url_init(void)
+nserror url_init(void)
{
+ nserror ret;
+
/* regex from RFC 2396 */
- regcomp_wrapper(&url_re, "^[[:space:]]*"
+ ret = regcomp_wrapper(&url_re, "^[[:space:]]*"
#define URL_RE_SCHEME 2
"(([a-zA-Z][-a-zA-Z0-9+.]*):)?"
#define URL_RE_AUTHORITY 4
@@ -59,7 +61,11 @@ void url_init(void)
#define URL_RE_FRAGMENT 9
"(#([^[:space:]]*))?"
"[[:space:]]*$", REG_EXTENDED);
- regcomp_wrapper(&url_up_re,
+ if (ret != NSERROR_OK) {
+ return ret;
+ }
+
+ return regcomp_wrapper(&url_up_re,
"/([^/]?|[.][^./]|[^./][.]|[^./][^./]|[^/][^/][^/]+)"
"/[.][.](/|$)",
REG_EXTENDED);
diff --git a/utils/url.h b/utils/url.h
index f1aff0e93..aac4e57e4 100644
--- a/utils/url.h
+++ b/utils/url.h
@@ -49,7 +49,7 @@ struct url_components {
*
* Compiles regular expressions required by the url_ functions.
*/
-void url_init(void);
+nserror url_init(void);
/**
diff --git a/utils/utils.c b/utils/utils.c
index 6199a8451..6730c9fa1 100644
--- a/utils/utils.c
+++ b/utils/utils.c
@@ -33,6 +33,7 @@
#include <time.h>
#include "utils/config.h"
+#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utf8.h"
#include "utils/time.h"
@@ -207,18 +208,20 @@ nserror snstrjoin(char **str, size_t *size, char sep, size_t nelm, ...)
/* exported interface documented in utils/utils.h */
-void regcomp_wrapper(regex_t *preg, const char *regex, int cflags)
+nserror regcomp_wrapper(regex_t *preg, const char *regex, int cflags)
{
int r;
r = regcomp(preg, regex, cflags);
if (r) {
char errbuf[200];
regerror(r, preg, errbuf, sizeof errbuf);
- fprintf(stderr, "Failed to compile regexp '%s'\n", regex);
- die(errbuf);
+ LOG(("Failed to compile regexp '%s': %s\n", regex, errbuf));
+ return NSERROR_INIT_FAILED;
}
+ return NSERROR_OK;
}
+
/**
* The size of buffers within human_friendly_bytesize.
*
diff --git a/utils/utils.h b/utils/utils.h
index 80298a4a7..9be859e59 100644
--- a/utils/utils.h
+++ b/utils/utils.h
@@ -163,7 +163,7 @@ bool is_dir(const char *path);
*
* Parameters as for regcomp(), see man regex.
*/
-void regcomp_wrapper(regex_t *preg, const char *regex, int cflags);
+nserror regcomp_wrapper(regex_t *preg, const char *regex, int cflags);
/**
* Create a human redable representation of a size in bytes.