summaryrefslogtreecommitdiff
path: root/pcreposix.c
diff options
context:
space:
mode:
authorph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>2010-03-03 20:09:39 +0000
committerph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>2010-03-03 20:09:39 +0000
commit83b2b44d38f1afd36c4b19e1afceea68e6216fbd (patch)
tree591d90b315e50d3c1ee7a3ae6d22b3b6d8e14543 /pcreposix.c
parent7887b1dc1c1c7276d3f95aa3920e1c5997ea3480 (diff)
downloadpcre-83b2b44d38f1afd36c4b19e1afceea68e6216fbd.tar.gz
Add some checks for the eint vector size and the list of compile-time error
texts. git-svn-id: svn://vcs.exim.org/pcre/code/trunk@499 2f5784b3-3f2a-0410-8824-cb99058d5e15
Diffstat (limited to 'pcreposix.c')
-rw-r--r--pcreposix.c43
1 files changed, 28 insertions, 15 deletions
diff --git a/pcreposix.c b/pcreposix.c
index b30378c..44c3ff9 100644
--- a/pcreposix.c
+++ b/pcreposix.c
@@ -344,6 +344,8 @@ rc = pcre_exec((const pcre *)preg->re_pcre, NULL, string + so, (eo - so),
if (rc == 0) rc = nmatch; /* All captured slots were filled in */
+/* Successful match */
+
if (rc >= 0)
{
size_t i;
@@ -360,22 +362,33 @@ if (rc >= 0)
return 0;
}
-else
+/* Unsuccessful match */
+
+if (allocated_ovector) free(ovector);
+switch(rc)
{
- if (allocated_ovector) free(ovector);
- switch(rc)
- {
- case PCRE_ERROR_NOMATCH: return REG_NOMATCH;
- case PCRE_ERROR_NULL: return REG_INVARG;
- case PCRE_ERROR_BADOPTION: return REG_INVARG;
- case PCRE_ERROR_BADMAGIC: return REG_INVARG;
- case PCRE_ERROR_UNKNOWN_NODE: return REG_ASSERT;
- case PCRE_ERROR_NOMEMORY: return REG_ESPACE;
- case PCRE_ERROR_MATCHLIMIT: return REG_ESPACE;
- case PCRE_ERROR_BADUTF8: return REG_INVARG;
- case PCRE_ERROR_BADUTF8_OFFSET: return REG_INVARG;
- default: return REG_ASSERT;
- }
+/* ========================================================================== */
+ /* These cases are never obeyed. This is a fudge that causes a compile-time
+ error if the vector eint, which is indexed by compile-time error number, is
+ not the correct length. It seems to be the only way to do such a check at
+ compile time, as the sizeof() operator does not work in the C preprocessor.
+ As all the PCRE_ERROR_xxx values are negative, we can use 0 and 1. */
+
+ case 0:
+ case (sizeof(eint)/sizeof(int) == ERRCOUNT):
+ return REG_ASSERT;
+/* ========================================================================== */
+
+ case PCRE_ERROR_NOMATCH: return REG_NOMATCH;
+ case PCRE_ERROR_NULL: return REG_INVARG;
+ case PCRE_ERROR_BADOPTION: return REG_INVARG;
+ case PCRE_ERROR_BADMAGIC: return REG_INVARG;
+ case PCRE_ERROR_UNKNOWN_NODE: return REG_ASSERT;
+ case PCRE_ERROR_NOMEMORY: return REG_ESPACE;
+ case PCRE_ERROR_MATCHLIMIT: return REG_ESPACE;
+ case PCRE_ERROR_BADUTF8: return REG_INVARG;
+ case PCRE_ERROR_BADUTF8_OFFSET: return REG_INVARG;
+ default: return REG_ASSERT;
}
}