Skip to content

Commit

Permalink
Fix up GCC compiler detection in ManyConfigTests
Browse files Browse the repository at this point in the history
  • Loading branch information
NWilson committed Jan 13, 2025
1 parent 2ec34b9 commit 22a7aae
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,7 @@ jobs:
env:
# Disallowing shadowing would be very spammy for unity builds, because the
# same variable name can be used in multiple files.
# We disable format truncation/overflow because the heuristics used for
# these warnings are not very good, and are apparently affected by the
# inliner, which is used much less aggressively in unity builds.
CFLAGS_UNITY: "-Wno-shadow -Wno-format-truncation -Wno-format-overflow"
CFLAGS_UNITY: "-Wno-shadow"
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
Expand Down Expand Up @@ -321,7 +318,7 @@ jobs:

- name: Configure
shell: msys2 {0}
run: cmake -G Ninja -DPCRE2_BUILD_PCRE2_16=ON -DPCRE2_BUILD_PCRE2_32=ON -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DPCRE2_DEBUG=ON -DCMAKE_C_FLAGS="$CFLAGS_GCC_STYLE -Wno-format-truncation -Wno-format-overflow" -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DCMAKE_BUILD_TYPE=Release -B build
run: cmake -G Ninja -DPCRE2_BUILD_PCRE2_16=ON -DPCRE2_BUILD_PCRE2_32=ON -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DPCRE2_DEBUG=ON -DCMAKE_C_FLAGS="$CFLAGS_GCC_STYLE" -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DCMAKE_BUILD_TYPE=Release -B build

- name: Build
shell: msys2 {0}
Expand Down Expand Up @@ -392,7 +389,7 @@ jobs:
run: |
set -e
# TODO: Set -DCMAKE_COMPILE_WARNING_AS_ERROR=ON (there's currently a build failure on S390x)
cmake -G Ninja -DPCRE2_SUPPORT_JIT=ON -DPCRE2_BUILD_PCRE2_16=ON -DPCRE2_BUILD_PCRE2_32=ON -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DPCRE2_DEBUG=ON -DCMAKE_C_FLAGS="$CFLAGS_GCC_STYLE -Wno-format-truncation -Wno-format-overflow" -DCMAKE_COMPILE_WARNING_AS_ERROR=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo -B build
cmake -G Ninja -DPCRE2_SUPPORT_JIT=ON -DPCRE2_BUILD_PCRE2_16=ON -DPCRE2_BUILD_PCRE2_32=ON -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DPCRE2_DEBUG=ON -DCMAKE_C_FLAGS="$CFLAGS_GCC_STYLE" -DCMAKE_COMPILE_WARNING_AS_ERROR=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo -B build
ninja -C build
(cd build && ctest -j3 --output-on-failure)
Expand Down
11 changes: 6 additions & 5 deletions maint/ManyConfigTests
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,14 @@ tmp=/tmp/pcre2testing

CFLAGS="-g"
OFLAGS="-O0"
CC="${CC:=cc}"
ISGCC=0

# If the compiler is gcc, add a lot of warning switches.

cc --version >/tmp/pcre2ccversion 2>/dev/null
if [ $? -eq 0 ] && grep GCC /tmp/pcre2ccversion >/dev/null; then
CC_VER_OUTPUT=`printf '#ifdef __GNUC__\nGCC=yes\n#endif\n' | $CC -E -`
if [ $? -eq 0 ] && (echo "$CC_VER_OUTPUT" | grep GCC=yes) >/dev/null; then
echo "Treating $CC as GCC"
ISGCC=1
CFLAGS="$CFLAGS -Wall"
CFLAGS="$CFLAGS -Wextra"
Expand All @@ -137,10 +139,9 @@ if [ $? -eq 0 ] && grep GCC /tmp/pcre2ccversion >/dev/null; then
CFLAGS="$CFLAGS -Wstrict-prototypes"
CFLAGS="$CFLAGS -Warray-bounds"
CFLAGS="$CFLAGS -Wformat-overflow=2"
CFLAGS="$CFLAGS -Wformat-truncation=2"
CFLAGS="$CFLAGS -Wformat-truncation=1"
CFLAGS="$CFLAGS -Wdeclaration-after-statement"
fi
rm -f /tmp/pcre2ccversion

# This function runs a single test with the set of configuration options that
# are in $opts. The source directory must be set in srcdir. The function must
Expand All @@ -161,7 +162,7 @@ runtest()

if [ $dummy -eq 1 ]; then return; fi

CFLAGS="$CFLAGS" \
CC="$CC" CFLAGS="$CFLAGS" \
$srcdir/configure $opts >/dev/null 2>teststderrM
if [ $? -ne 0 ]; then
echo " "
Expand Down
20 changes: 13 additions & 7 deletions src/pcre2grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -3440,16 +3440,18 @@ if (isdirectory(pathname))
while ((nextfile = readdirectory(dir)) != NULL)
{
int frc;
size_t fnlength = strlen(pathname) + strlen(nextfile) + 2;
if (fnlength > FNBUFSIZ)
int prc;
if (strlen(pathname) + strlen(nextfile) + 2 > sizeof(childpath) ||
(prc = snprintf(childpath, sizeof(childpath), "%s%c%s", pathname,
FILESEP, nextfile)) < 0 ||
prc >= (int)sizeof(childpath))
{
/* LCOV_EXCL_START - this is a "never" event */
fprintf(stderr, "pcre2grep: recursive filename is too long\n");
rc = 2;
break;
/* LCOV_EXCL_STOP */
}
snprintf(childpath, sizeof(childpath), "%s%c%s", pathname, FILESEP, nextfile);

/* If the realpath() function is available, we can try to prevent endless
recursion caused by a symlink pointing to a parent directory (GitHub
Expand Down Expand Up @@ -3509,15 +3511,19 @@ if (iswild(pathname))
while ((nextfile = readdirectory(dir)) != NULL)
{
int frc;
if (strlen(pathname) + strlen(nextfile) + 1 > sizeof(buffer))
int prc;
if (strlen(pathname) + strlen(nextfile) + 1 > sizeof(buffer) ||
(prc = snprintf(buffer, sizeof(buffer), "%s%s", pathname,
nextfile)) < 0 ||
prc >= (int)sizeof(buffer))
{
/* LCOV_EXCL_START - this is a "never" event */
fprintf(stderr, "pcre2grep: wildcard filename is too long\n");
rc = 2;
break;
/* LCOV_EXCL_STOP */
}
snprintf(buffer, sizeof(buffer), "%s%s", pathname, nextfile);

frc = grep_or_recurse(buffer, dir_recurse, FALSE);
if (frc > 1) rc = frc;
else if (frc == 0 && rc == 1) rc = 0;
Expand Down Expand Up @@ -4064,10 +4070,10 @@ for (i = 1; i < argc; i++)
(int)strlen(arg) : (int)(argequals - arg);

if ((ret = snprintf(buff1, sizeof(buff1), "%.*s", baselen, op->long_name),
ret < 0 || ret > (int)sizeof(buff1)) ||
ret < 0 || ret >= (int)sizeof(buff1)) ||
(ret = snprintf(buff2, sizeof(buff2), "%s%.*s", buff1,
fulllen - baselen - 2, opbra + 1),
ret < 0 || ret > (int)sizeof(buff2)))
ret < 0 || ret >= (int)sizeof(buff2)))
{
/* LCOV_EXCL_START - this is a "never" event */
fprintf(stderr, "pcre2grep: Buffer overflow when parsing %s option\n",
Expand Down

0 comments on commit 22a7aae

Please sign in to comment.