Skip to content

Commit 4414f7a

Browse files
authored
Configure Clang static analyzer CI (#575)
1 parent 9134ae9 commit 4414f7a

File tree

9 files changed

+74
-7
lines changed

9 files changed

+74
-7
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
name: Clang Static Analyzer
3+
on: [push, pull_request]
4+
5+
jobs:
6+
Analyze:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v4
11+
with:
12+
submodules: true
13+
14+
- name: Prepare
15+
run: |
16+
sudo apt-get -qq update
17+
sudo apt-get -qq install ninja-build clang-tools
18+
19+
- name: Configure
20+
run: |
21+
mkdir build
22+
cd build
23+
scan-build cmake -G Ninja -DPCRE2_SUPPORT_JIT=ON -DCMAKE_BUILD_TYPE=Debug ..
24+
25+
- name: Build
26+
run: |
27+
# Inefficiently run clang scan twice; once to generate HTML, and secondly
28+
# to generate SARIF files. Ideally we would have some way to scan once and
29+
# generate one of those outputs from the other, but I don't know a good way
30+
# to do that.
31+
cd build
32+
scan-build -o clang-report/ ninja
33+
34+
ninja clean
35+
scan-build -o clang-sarif -sarif ninja
36+
# Work around issue in GitHub's SARIF ingestion - merge all SARIF files into one
37+
npx -y @microsoft/sarif-multitool merge clang-sarif/*/*.sarif --output-file=clang.sarif
38+
39+
# Upload the browsable HTML report as an artifact.
40+
- name: Upload report
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: "Clang Static Analyzer report"
44+
path: './build/clang-report'
45+
46+
# Upload the results to GitHub's code scanning dashboard.
47+
- name: "Upload to code-scanning"
48+
uses: github/codeql-action/upload-sarif@v3
49+
with:
50+
sarif_file: build/clang.sarif
51+
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

@@ -7140,6 +7142,7 @@ for (;; pptr++)
71407142
/* Save start of previous item, in case we have to move it up in order to
71417143
insert something before it, and remember what it was. */
71427144

7145+
PCRE2_ASSERT(previous != NULL);
71437146
tempcode = previous;
71447147
op_previous = *previous;
71457148

@@ -10155,6 +10158,7 @@ PCRE2_ZERO_TERMINATED. Check for an overlong pattern. */
1015510158

1015610159
if ((zero_terminated = (patlen == PCRE2_ZERO_TERMINATED)))
1015710160
patlen = PRIV(strlen)(pattern);
10161+
(void)zero_terminated; /* Silence compiler; only used if Valgrind enabled */
1015810162

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

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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,6 @@ else
329329
Arguments:
330330
f file to write to
331331
code pointer in the compiled code
332-
333-
Returns: end of the character list
334332
*/
335333

336334
static PCRE2_SPTR
@@ -527,14 +525,17 @@ if (printmap)
527525
if (*code == OP_XCLASS)
528526
{
529527
PCRE2_UCHAR ch;
528+
530529
while ((ch = *ccode++) != XCL_END)
531530
{
532531
const char *notch = "";
532+
533533
if (ch >= XCL_LIST)
534534
{
535535
ccode = print_char_list(f, ccode - 1, char_lists_end);
536536
break;
537537
}
538+
538539
switch(ch)
539540
{
540541
case XCL_NOTPROP:
@@ -567,6 +568,7 @@ if (*code == OP_XCLASS)
567568
}
568569
}
569570
break;
571+
570572
default:
571573
ccode += 1 + print_char(f, ccode, utf);
572574
if (ch == XCL_RANGE)
@@ -577,6 +579,8 @@ if (*code == OP_XCLASS)
577579
break;
578580
}
579581
}
582+
583+
PCRE2_ASSERT(ccode == code + GET(code, 1));
580584
}
581585

582586
/* Indicate a non-UTF class which was created by negation */

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)