[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[augeas-devel] [PATCH] * src/fa.h (fa_compile): pass in size of regexp



---
 src/fa.c       |   29 ++++++++++++++++++++---------
 src/fa.h       |   10 +++++-----
 src/lens.c     |    2 +-
 src/regexp.c   |    4 ++--
 tests/fatest.c |    8 ++++----
 5 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/src/fa.c b/src/fa.c
index 2b9ce4f..e5f8ea7 100644
--- a/src/fa.c
+++ b/src/fa.c
@@ -2292,12 +2292,20 @@ char *fa_ambig_example(struct fa *fa1, struct fa *fa2, char **pv, char **v) {
 
 #define Xs "\001"
 #define Ys "\002"
+#define MPs Ys Xs "(" Xs "(.|\n))+"
+#define MSs Ys Xs "(" Xs "(.|\n))*"
+#define SPs "(" Xs "(.|\n))+" Ys Xs
+#define SSs "(" Xs "(.|\n))*" Ys Xs
     /* These could become static constants */
     struct fa *mp, *ms, *sp, *ss;
-    fa_compile( Ys Xs "(" Xs "(.|\n))+", &mp);
-    fa_compile( Ys Xs "(" Xs "(.|\n))*", &ms);
-    fa_compile( "(" Xs "(.|\n))+" Ys Xs, &sp);
-    fa_compile("(" Xs "(.|\n))*" Ys Xs, &ss);
+    fa_compile( MPs, strlen(MPs), &mp);
+    fa_compile( MSs, strlen(MSs), &ms);
+    fa_compile( SPs, strlen(SPs), &sp);
+    fa_compile( SSs, strlen(SSs), &ss);
+#undef SSs
+#undef SPs
+#undef MSs
+#undef MPs
 #undef Xs
 #undef Ys
 
@@ -2417,16 +2425,19 @@ static void free_re(struct re *re) {
     free(re);
 }
 
-int fa_compile(const char *regexp, struct fa **fa) {
+int fa_compile(const char *regexp, size_t size, struct fa **fa) {
     int ret = REG_NOERROR;
-    struct re *re = parse_regexp(&regexp, &ret);
+    struct re *re = NULL;
     *fa = NULL;
+
+    /* We don't handle embedded nul's yet */
+    if (strlen(regexp) != size)
+        return REG_ESIZE;
+
+    re = parse_regexp(&regexp, &ret);
     if (re == NULL)
         return ret;
 
-    //print_re(re);
-    //printf("\n");
-
     *fa = fa_from_re(re);
     re_unref(re);
 
diff --git a/src/fa.h b/src/fa.h
index dbfd52a..e28e3b2 100644
--- a/src/fa.h
+++ b/src/fa.h
@@ -59,16 +59,16 @@ extern int fa_minimization_algorithm;
  */
 
 /*
- * Compile the regular expression RE into an automaton. The return value is
- * the same as the return value for the POSIX function regcomp. The syntax
- * for regular expressions is extended POSIX syntax, with the difference
- * that '.' does not match newlines.
+ * Compile the regular expression RE of length SIZE into an automaton. The
+ * return value is the same as the return value for the POSIX function
+ * regcomp. The syntax for regular expressions is extended POSIX syntax,
+ * with the difference that '.' does not match newlines.
  *
  * On success, FA points to the newly allocated automaton constructed for
  * RE, and the function returns REG_NOERROR. Otherwise, FA is NULL, and the
  * return value indicates the error.
  */
-int fa_compile(const char *re, struct fa **fa);
+int fa_compile(const char *re, size_t size, struct fa **fa);
 
 /* Make a new automaton that accepts one of the basic languages defined in
  * the enum FA_BASIC.
diff --git a/src/lens.c b/src/lens.c
index d8e3eb2..7d905e8 100644
--- a/src/lens.c
+++ b/src/lens.c
@@ -53,7 +53,7 @@ static struct value *str_to_fa(struct info *info, const char *pattern,
     size_t re_err_len;
     char *re_str, *re_err;
 
-    error = fa_compile(pattern, fa);
+    error = fa_compile(pattern, strlen(pattern), fa);
     if (error == REG_NOERROR)
         return NULL;
 
diff --git a/src/regexp.c b/src/regexp.c
index 5b6471d..5d02bcb 100644
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -191,11 +191,11 @@ regexp_minus(struct info *info, struct regexp *r1, struct regexp *r2) {
     int r;
     char *s = NULL;
 
-    r = fa_compile(p1, &fa1);
+    r = fa_compile(p1, strlen(p1), &fa1);
     if (r != REG_NOERROR)
         goto error;
 
-    r = fa_compile(p2, &fa2);
+    r = fa_compile(p2, strlen(p2), &fa2);
     if (r != REG_NOERROR)
         goto error;
 
diff --git a/tests/fatest.c b/tests/fatest.c
index 88c38ed..d153da4 100644
--- a/tests/fatest.c
+++ b/tests/fatest.c
@@ -84,7 +84,7 @@ static void assertAsRegexp(CuTest *tc, struct fa *fa) {
     r = fa_as_regexp(fa1, &re);
     CuAssertIntEquals(tc, 0, r);
 
-    r = fa_compile(re, &fa2);
+    r = fa_compile(re, strlen(re), &fa2);
     CuAssertIntEquals(tc, REG_NOERROR, r);
 
     CuAssertTrue(tc, fa_equals(fa, fa2));
@@ -97,7 +97,7 @@ static struct fa *make_fa(CuTest *tc, const char *regexp, int exp_err) {
     struct fa *fa;
     int r;
 
-    r = fa_compile(regexp, &fa);
+    r = fa_compile(regexp, strlen(regexp), &fa);
     if (exp_err == REG_NOERROR) {
         if (r != REG_NOERROR)
             print_regerror(r, regexp);
@@ -384,7 +384,7 @@ static void assertFaAsRegexp(CuTest *tc, const char *regexp) {
     r = fa_as_regexp(fa1, &re);
     CuAssertIntEquals(tc, 0, r);
 
-    r = fa_compile(re, &fa2);
+    r = fa_compile(re, strlen(re), &fa2);
     CuAssertIntEquals(tc, REG_NOERROR, r);
 
     CuAssert(tc, regexp, fa_equals(fa1, fa2));
@@ -453,7 +453,7 @@ int main(int argc, char **argv) {
     for (int i=1; i<argc; i++) {
         struct fa *fa;
         int r;
-        if ((r = fa_compile(argv[i], &fa)) != REG_NOERROR) {
+        if ((r = fa_compile(argv[i], strlen(argv[i]), &fa)) != REG_NOERROR) {
             print_regerror(r, argv[i]);
         } else {
             dot(fa);
-- 
1.6.0.6



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]