Skip to content

Commit 9cbd605

Browse files
committed
Configure Clang static analyzer CI
1 parent 833ab6d commit 9cbd605

File tree

9 files changed

+64
-6
lines changed

9 files changed

+64
-6
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
name: Clang Static Analyzer
3+
on: [push, pull_request]
4+
5+
jobs:
6+
linux:
7+
name: Linux
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v4
12+
with:
13+
submodules: true
14+
15+
- name: Prepare
16+
run: |
17+
sudo apt-get -qq update
18+
sudo apt-get -qq install ninja-build clang-tools
19+
20+
- name: Configure
21+
run: |
22+
mkdir build
23+
cd build
24+
scan-build cmake -G Ninja -DPCRE2_SUPPORT_JIT=ON -DCMAKE_BUILD_TYPE=Debug ..
25+
26+
- name: Build
27+
run: |
28+
cd build
29+
scan-build -o clang-report/ ninja
30+
31+
ninja clean
32+
scan-build -o clang.sarif -sarif ninja
33+
34+
# Upload the browsable HTML report as an artifact.
35+
- name: Upload report
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: "Clang Static Analyzer report"
39+
path: './build/clang-report'
40+
41+
# Upload the results to GitHub's code scanning dashboard.
42+
- name: "Upload to code-scanning"
43+
uses: github/codeql-action/upload-sarif@v3
44+
with:
45+
sarif_file: build/clang.sarif
46+
category: clang-analyzer

.github/workflows/scorecards.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151

5252
# Upload the results to GitHub's code scanning dashboard.
5353
- name: "Upload to code-scanning"
54-
uses: github/codeql-action/upload-sarif@5f532563584d71fdef14ee64d17bafb34f751ce5 # v1.0.26
54+
uses: github/codeql-action/upload-sarif@v3
5555
with:
5656
sarif_file: results.sarif
57+
category: ossf-scorecard

src/pcre2_compile.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,6 +2964,8 @@ ptrdiff_t parsed_pattern_extra_check = 0;
29642964
PCRE2_SPTR ptr_check;
29652965
#endif
29662966

2967+
PCRE2_ASSERT(parsed_pattern != NULL);
2968+
29672969
/* Insert leading items for word and line matching (features provided for the
29682970
benefit of pcre2grep). */
29692971

@@ -7131,6 +7133,7 @@ for (;; pptr++)
71317133
/* Save start of previous item, in case we have to move it up in order to
71327134
insert something before it, and remember what it was. */
71337135

7136+
PCRE2_ASSERT(previous != NULL);
71347137
tempcode = previous;
71357138
op_previous = *previous;
71367139

@@ -10154,6 +10157,7 @@ PCRE2_ZERO_TERMINATED. Check for an overlong pattern. */
1015410157

1015510158
if ((zero_terminated = (patlen == PCRE2_ZERO_TERMINATED)))
1015610159
patlen = PRIV(strlen)(pattern);
10160+
(void)zero_terminated; /* Silence compiler; only used if Valgrind enabled */
1015710161

1015810162
if (patlen > ccontext->max_pattern_length)
1015910163
{

src/pcre2_compile_class.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ while (TRUE)
11031103
int posix_class;
11041104
int taboffset, tabopt;
11051105
uint8_t pbits[32];
1106-
uint32_t escape, c, d;
1106+
uint32_t escape, c;
11071107

11081108
/* Handle POSIX classes such as [:alpha:] etc. */
11091109
switch (META_CODE(meta))
@@ -1408,7 +1408,7 @@ while (TRUE)
14081408
characters are equal, and for hyphens that cannot indicate a range. At
14091409
this point, therefore, no checking is needed. */
14101410

1411-
c = d = meta;
1411+
c = meta;
14121412

14131413
/* Remember if \r or \n were explicitly used */
14141414

@@ -1418,6 +1418,8 @@ while (TRUE)
14181418

14191419
if (*pptr == META_RANGE_LITERAL || *pptr == META_RANGE_ESCAPED)
14201420
{
1421+
uint32_t d;
1422+
14211423
#ifdef EBCDIC
14221424
BOOL range_is_literal = (*pptr == META_RANGE_LITERAL);
14231425
#endif

src/pcre2_match.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5792,6 +5792,8 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
57925792

57935793
/* Disable compiler warning. */
57945794
offset = 0;
5795+
(void)offset;
5796+
57955797
for (;;)
57965798
{
57975799
if (*ecode == OP_CREF)

src/pcre2_printint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,6 @@ if (*code == OP_XCLASS)
533533
if (ch >= XCL_LIST)
534534
{
535535
ccode = print_char_list(f, ccode - 1, char_lists_end);
536-
break;
537536
}
538537
switch(ch)
539538
{
@@ -567,6 +566,7 @@ if (*code == OP_XCLASS)
567566
}
568567
}
569568
break;
569+
570570
default:
571571
ccode += 1 + print_char(f, ccode, utf);
572572
if (ch == XCL_RANGE)

src/pcre2_substitute.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,7 @@ do
766766
}
767767

768768
next = 0; /* not used or updated after this point */
769+
(void)next;
769770

770771
/* In extended mode we recognize ${name:+set text:unset text} and
771772
${name:-default text}. */

src/pcre2grep.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,12 +1539,13 @@ switch(endlinetype)
15391539
for (;;)
15401540
{
15411541
while (p < endptr && *p != '\r') p++;
1542-
if (++p >= endptr)
1542+
if (p == endptr)
15431543
{
15441544
*lenptr = 0;
15451545
return endptr;
15461546
}
1547-
if (*p == '\n')
1547+
p++;
1548+
if (p < endptr && *p == '\n')
15481549
{
15491550
*lenptr = 2;
15501551
return p + 1;

src/pcre2test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8056,6 +8056,7 @@ for (gmatched = 0;; gmatched++)
80568056
if ((dat_datctl.control & (CTL_FINDLIMITS|CTL_FINDLIMITS_NOHEAP)) != 0)
80578057
{
80588058
capcount = 0; /* This stops compiler warnings */
8059+
(void)capcount;
80598060

80608061
if ((dat_datctl.control & CTL_FINDLIMITS_NOHEAP) == 0 &&
80618062
(FLD(compiled_code, executable_jit) == NULL ||

0 commit comments

Comments
 (0)