diff --git a/compat/regex/regcomp.c b/compat/regex/regcomp.c index 29a71d31e444cb..53325f6468e9a6 100644 --- a/compat/regex/regcomp.c +++ b/compat/regex/regcomp.c @@ -2675,6 +2675,7 @@ build_range_exp (bitset_t sbcset, re_charset_t *mbcset, Idx *range_alloc, && strlen ((char *) end_elem->opr.name) > 1))) return REG_ECOLLATE; + { unsigned int start_ch = ((start_elem->type == SB_CHAR) ? start_elem->opr.ch : ((start_elem->type == COLL_SYM) ? start_elem->opr.name[0] @@ -2740,6 +2741,7 @@ build_range_exp (bitset_t sbcset, re_charset_t *mbcset, Idx *range_alloc, if (start_wc <= wc && wc <= end_wc) bitset_set (sbcset, wc); } + } return REG_NOERROR; } diff --git a/compat/regex/regex.c b/compat/regex/regex.c index 1182dae6640426..191797fc43ea06 100644 --- a/compat/regex/regex.c +++ b/compat/regex/regex.c @@ -19,15 +19,33 @@ #define __STDC_WANT_IEC_60559_BFP_EXT__ -#ifndef _LIBC -# include +#include +#include -# if __GNUC_PREREQ (4, 6) -# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure" -# pragma GCC diagnostic ignored "-Wvla" -# endif +#define __USE_GNU +#define __STRICT_ANSI__ +#define assume(x) +#define __glibc_unlikely(x) (x) +#define __glibc_likely(x) (x) +#define libc_hidden_def(name) +#define weak_alias(name, aliasname) +#define __always_inline inline +#define nl_langinfo(x) "UTF8" +#define FALLTHROUGH /* fallthru */ +#define uint_fast32_t uint32_t + +/* This imitates the `RESULT_MUST_BE_USED` macro in `git-compat-util.h` */ +/* The sentinel attribute is valid from gcc version 4.0 */ +#if defined(__GNUC__) && (__GNUC__ >= 4) +/* warn_unused_result exists as of gcc 3.4.0, but be lazy and check 4.0 */ +#define __attribute_warn_unused_result__ __attribute__ ((warn_unused_result)) +#else +#define __attribute_warn_unused_result__ #endif +/* True if the real type T is signed. */ +#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) + /* Make sure no one compiles this code with a C++ compiler. */ #if defined __cplusplus && defined _LIBC # error "This is C code, use a C compiler" diff --git a/compat/regex/regex_internal.h b/compat/regex/regex_internal.h index 345e895ced0543..9544183637eb05 100644 --- a/compat/regex/regex_internal.h +++ b/compat/regex/regex_internal.h @@ -24,19 +24,9 @@ #include #include -#include #include #include #include -#include -#include - -#ifndef _LIBC -# include -#endif - -#include -#include #if defined DEBUG && DEBUG != 0 # include @@ -818,14 +808,4 @@ re_string_elem_size_at (const re_string_t *pstr, Idx idx) return 1; } -#ifdef _LIBC -# if __glibc_has_attribute (__fallthrough__) -# define FALLTHROUGH __attribute__ ((__fallthrough__)) -# else -# define FALLTHROUGH ((void) 0) -# endif -#else -# include "attribute.h" -#endif - #endif /* _REGEX_INTERNAL_H */ diff --git a/compat/regex/regexec.c b/compat/regex/regexec.c index 38ec76ebb60c35..0e461b6f226fe0 100644 --- a/compat/regex/regexec.c +++ b/compat/regex/regexec.c @@ -185,7 +185,7 @@ static reg_errcode_t extend_buffers (re_match_context_t *mctx, int min_len); int regexec (const regex_t *__restrict preg, const char *__restrict string, - size_t nmatch, regmatch_t pmatch[_REGEX_NELTS (nmatch)], int eflags) + size_t nmatch, regmatch_t *pmatch, int eflags) { reg_errcode_t err; Idx start, length; @@ -1214,6 +1214,7 @@ proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs, return -2; } + { /* Pick a valid destination, or return -1 if none is found. */ Idx dest_node = -1; for (Idx i = 0; i < edests->nelem; i++) @@ -1242,6 +1243,7 @@ proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs, } } return dest_node; + } } else { @@ -1338,6 +1340,7 @@ pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, Idx nregs, { if (fs == NULL || fs->num == 0) return -1; + { Idx num = --fs->num; *pidx = fs->stack[num].idx; memcpy (regs, fs->stack[num].regs, sizeof (regmatch_t) * nregs); @@ -1347,13 +1350,13 @@ pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, Idx nregs, *eps_via_nodes = fs->stack[num].eps_via_nodes; DEBUG_ASSERT (0 <= fs->stack[num].node); return fs->stack[num].node; + } } #define DYNARRAY_STRUCT regmatch_list #define DYNARRAY_ELEMENT regmatch_t #define DYNARRAY_PREFIX regmatch_list_ -#include /* Set the positions where the subexpressions are starts/ends to registers PMATCH.