From 128c50360c7fb9be5ccd613264b20b72f17ec875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= Date: Fri, 29 Oct 2021 08:07:53 -0700 Subject: [PATCH] fix building on ancient compilers (#32) * jit: allow building with ancient MSVC versions Visual Studio older than 2013, fails to build with JIT enabled, because it is unable to parse non C89 compatible syntax, with mixed declarations and code. While most recent compilers wouldn't even report this as a warning since it is valid C99, it could be also made visible by adding to gcc/clang the -Wdeclaration-after-statement flag at build time. Move the code below the affected definitions. * pcre2grep: avoid mixing declarations with code Since d5a61ee8 (Patch to detect (and ignore) symlink loops in pcre2grep., 2021-08-28), code will fail to build in a strict C89 compiler. Reformat slightly to make it C89 compatible again. --- src/pcre2_jit_compile.c | 14 +++++++++----- src/pcre2grep.c | 11 ++++++++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/pcre2_jit_compile.c b/src/pcre2_jit_compile.c index 2c61406..db2ce65 100644 --- a/src/pcre2_jit_compile.c +++ b/src/pcre2_jit_compile.c @@ -4202,9 +4202,6 @@ TMP2 is not used. Otherwise TMP2 must contain the start of the subject buffer, and it is destroyed. Does not modify STR_PTR for invalid character sequences. */ DEFINE_COMPILER; -SLJIT_UNUSED_ARG(backtracks); -SLJIT_UNUSED_ARG(must_be_valid); - #if defined SUPPORT_UNICODE && PCRE2_CODE_UNIT_WIDTH != 32 struct sljit_jump *jump; #endif @@ -4278,6 +4275,10 @@ if (common->invalid_utf && !must_be_valid) } #endif /* PCRE2_CODE_UNIT_WIDTH == [8|16|32] */ #endif /* SUPPORT_UNICODE */ + +SLJIT_UNUSED_ARG(backtracks); +SLJIT_UNUSED_ARG(must_be_valid); + OP2(SLJIT_SUB, STR_PTR, 0, STR_PTR, 0, SLJIT_IMM, IN_UCHARS(1)); } @@ -14131,6 +14132,10 @@ PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION pcre2_jit_compile(pcre2_code *code, uint32_t options) { pcre2_real_code *re = (pcre2_real_code *)code; +#ifdef SUPPORT_JIT +executable_functions *functions; +static int executable_allocator_is_working = 0; +#endif if (code == NULL) return PCRE2_ERROR_NULL; @@ -14165,8 +14170,7 @@ actions are needed: */ #ifdef SUPPORT_JIT -executable_functions *functions = (executable_functions *)re->executable_jit; -static int executable_allocator_is_working = 0; +functions = (executable_functions *)re->executable_jit; #endif if ((options & PCRE2_JIT_INVALID_UTF) != 0) diff --git a/src/pcre2grep.c b/src/pcre2grep.c index feafce0..aa84ea7 100644 --- a/src/pcre2grep.c +++ b/src/pcre2grep.c @@ -3361,18 +3361,23 @@ if (isdirectory(pathname)) because that affects the output from pcre2grep. */ #ifdef HAVE_REALPATH + { char resolvedpath[PATH_MAX]; + BOOL isSame; + size_t rlen; if (realpath(childpath, resolvedpath) == NULL) continue; /* This path is invalid - we can skip processing this */ - BOOL isSame = strcmp(pathname, resolvedpath) == 0; + isSame = strcmp(pathname, resolvedpath) == 0; if (isSame) continue; /* We have a recursion */ - size_t rlen = strlen(resolvedpath); + rlen = strlen(resolvedpath); if (rlen++ < sizeof(resolvedpath) - 3) { + BOOL contained; strcat(resolvedpath, "/"); - BOOL contained = strncmp(pathname, resolvedpath, rlen) == 0; + contained = strncmp(pathname, resolvedpath, rlen) == 0; if (contained) continue; /* We have a recursion */ } + } #endif /* HAVE_REALPATH */ frc = grep_or_recurse(childpath, dir_recurse, FALSE);