]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Move regex_flag_parse to fr_slen_t
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 4 Sep 2022 04:34:02 +0000 (00:34 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 4 Sep 2022 20:49:46 +0000 (16:49 -0400)
src/lib/util/regex.c
src/tests/unit/condition/regex.txt
src/tests/unit/xlat/cond_regex.txt

index ec6f66113210b8743960892bd9b12d3032c0bbe8..a85cc639c939d2b446bd4e3258144bb477fbc86b 100644 (file)
@@ -1270,8 +1270,8 @@ fr_regmatch_t *regex_match_data_alloc(TALLOC_CTX *ctx, uint32_t count)
  *      - > 0 on success.  The number of flag bytes parsed.
  *     - <= 0 on failure.  Negative offset of first unrecognised flag.
  */
-ssize_t regex_flags_parse(int *err, fr_regex_flags_t *out, fr_sbuff_t *in,
-                         fr_sbuff_term_t const *terminals, bool err_on_dup)
+fr_slen_t regex_flags_parse(int *err, fr_regex_flags_t *out, fr_sbuff_t *in,
+                           fr_sbuff_term_t const *terminals, bool err_on_dup)
 {
        fr_sbuff_t      our_in = FR_SBUFF(in);
 
@@ -1284,7 +1284,7 @@ ssize_t regex_flags_parse(int *err, fr_regex_flags_t *out, fr_sbuff_t *in,
                        if (err_on_dup && out->_f) { \
                                fr_strerror_printf("Duplicate regex flag '%c'", *our_in.p); \
                                if (err) *err = -2; \
-                               return -fr_sbuff_used(&our_in); \
+                               return fr_sbuff_error(&our_in); \
                        } \
                        out->_f = 1; \
                        break
@@ -1302,7 +1302,7 @@ ssize_t regex_flags_parse(int *err, fr_regex_flags_t *out, fr_sbuff_t *in,
 
                        fr_strerror_printf("Unsupported regex flag '%c'", *our_in.p);
                        if (err) *err = -1;
-                       return -(fr_sbuff_used_total(&our_in));
+                       return fr_sbuff_error(&our_in);
                }
                fr_sbuff_advance(&our_in, 1);
        }
index aadc5ed0b17037a481d073aa43ee1d6f363cb589..fdc048458441286e3a5f8166541a61b5b0af348d 100644 (file)
@@ -37,13 +37,13 @@ condition foo =~ /bar/im
 match 'foo' =~ /bar/im
 
 condition foo =~ /bar/ima
-match ERROR offset 14: Unsupported regex flag 'a'
+match ERROR offset 15: Unsupported regex flag 'a'
 
 condition foo =~ /bar/ii
-match ERROR offset 13: Duplicate regex flag 'i'
+match ERROR offset 14: Duplicate regex flag 'i'
 
 condition foo =~ /bar/iia
-match ERROR offset 13: Duplicate regex flag 'i'
+match ERROR offset 14: Duplicate regex flag 'i'
 
 #
 #  Escape the backslashes correctly
index 064146e54e89ef7486939fc815445fc9cfca8484..d24ae43cfb439ec5a9e08361e27cef15813cebe1 100644 (file)
@@ -32,13 +32,13 @@ xlat_purify &User-Name =~ /bar/im
 match (&User-Name =~ /bar/im)
 
 xlat_purify &User-Name =~ /bar/ima
-match ERROR offset 21: Unsupported regex flag 'a'
+match ERROR offset 22: Unsupported regex flag 'a'
 
 xlat_purify &User-Name =~ /bar/ii
-match ERROR offset 20: Duplicate regex flag 'i'
+match ERROR offset 21: Duplicate regex flag 'i'
 
 xlat_purify &User-Name =~ /bar/iia
-match ERROR offset 20: Duplicate regex flag 'i'
+match ERROR offset 21: Duplicate regex flag 'i'
 
 #
 #  Escape the backslashes correctly