summaryrefslogtreecommitdiff
path: root/ext/pcre/pcrelib/pcreposix.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/pcre/pcrelib/pcreposix.c')
-rw-r--r--ext/pcre/pcrelib/pcreposix.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/ext/pcre/pcrelib/pcreposix.c b/ext/pcre/pcrelib/pcreposix.c
index 4cb5e12a1b..d552abcd1e 100644
--- a/ext/pcre/pcrelib/pcreposix.c
+++ b/ext/pcre/pcrelib/pcreposix.c
@@ -124,7 +124,8 @@ static const int eint[] = {
REG_BADPAT, /* (?+ or (?- must be followed by a non-zero number */
REG_BADPAT, /* number is too big */
REG_BADPAT, /* subpattern name expected */
- REG_BADPAT /* digit expected after (?+ */
+ REG_BADPAT, /* digit expected after (?+ */
+ REG_BADPAT /* ] is an invalid data character in JavaScript compatibility mode */
};
/* Table of texts corresponding to POSIX error codes */
@@ -157,7 +158,7 @@ static const char *const pstring[] = {
* Translate error code to string *
*************************************************/
-PCREPOSIX_EXP_DEFN size_t
+PCREPOSIX_EXP_DEFN size_t PCRE_CALL_CONVENTION
regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
{
const char *message, *addmessage;
@@ -192,7 +193,7 @@ return length + addlength;
* Free store held by a regex *
*************************************************/
-PCREPOSIX_EXP_DEFN void
+PCREPOSIX_EXP_DEFN void PCRE_CALL_CONVENTION
regfree(regex_t *preg)
{
(pcre_free)(preg->re_pcre);
@@ -215,7 +216,7 @@ Returns: 0 on success
various non-zero codes on failure
*/
-PCREPOSIX_EXP_DEFN int
+PCREPOSIX_EXP_DEFN int PCRE_CALL_CONVENTION
regcomp(regex_t *preg, const char *pattern, int cflags)
{
const char *errorptr;
@@ -257,11 +258,11 @@ If REG_NOSUB was specified at compile time, the PCRE_NO_AUTO_CAPTURE flag will
be set. When this is the case, the nmatch and pmatch arguments are ignored, and
the only result is yes/no/error. */
-PCREPOSIX_EXP_DEFN int
+PCREPOSIX_EXP_DEFN int PCRE_CALL_CONVENTION
regexec(const regex_t *preg, const char *string, size_t nmatch,
regmatch_t pmatch[], int eflags)
{
-int rc;
+int rc, so, eo;
int options = 0;
int *ovector = NULL;
int small_ovector[POSIX_MALLOC_THRESHOLD * 3];
@@ -294,7 +295,23 @@ else if (nmatch > 0)
}
}
-rc = pcre_exec((const pcre *)preg->re_pcre, NULL, string, (int)strlen(string),
+/* REG_STARTEND is a BSD extension, to allow for non-NUL-terminated strings.
+The man page from OS X says "REG_STARTEND affects only the location of the
+string, not how it is matched". That is why the "so" value is used to bump the
+start location rather than being passed as a PCRE "starting offset". */
+
+if ((eflags & REG_STARTEND) != 0)
+ {
+ so = pmatch[0].rm_so;
+ eo = pmatch[0].rm_eo;
+ }
+else
+ {
+ so = 0;
+ eo = strlen(string);
+ }
+
+rc = pcre_exec((const pcre *)preg->re_pcre, NULL, string + so, (eo - so),
0, options, ovector, nmatch * 3);
if (rc == 0) rc = nmatch; /* All captured slots were filled in */