• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /usr/bin/env bash
2#                          __  __            _
3#                       ___\ \/ /_ __   __ _| |_
4#                      / _ \\  /| '_ \ / _` | __|
5#                     |  __//  \| |_) | (_| | |_
6#                      \___/_/\_\ .__/ \__,_|\__|
7#                               |_| XML parser
8#
9# Copyright (c) 2024 Sebastian Pipping <sebastian@pipping.org>
10# Licensed under the MIT license:
11#
12# Permission is  hereby granted,  free of charge,  to any  person obtaining
13# a  copy  of  this  software   and  associated  documentation  files  (the
14# "Software"),  to  deal in  the  Software  without restriction,  including
15# without  limitation the  rights  to use,  copy,  modify, merge,  publish,
16# distribute, sublicense, and/or sell copies of the Software, and to permit
17# persons  to whom  the Software  is  furnished to  do so,  subject to  the
18# following conditions:
19#
20# The above copyright  notice and this permission notice  shall be included
21# in all copies or substantial portions of the Software.
22#
23# THE  SOFTWARE  IS  PROVIDED  "AS  IS",  WITHOUT  WARRANTY  OF  ANY  KIND,
24# EXPRESS  OR IMPLIED,  INCLUDING  BUT  NOT LIMITED  TO  THE WARRANTIES  OF
25# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
26# NO EVENT SHALL THE AUTHORS OR  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
27# DAMAGES OR  OTHER LIABILITY, WHETHER  IN AN  ACTION OF CONTRACT,  TORT OR
28# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
29# USE OR OTHER DEALINGS IN THE SOFTWARE.
30
31set -e -u -o pipefail
32
33cd "$(dirname "$(type -P "$0")")"
34
35checks_to_enable=(
36    readability-avoid-const-params-in-decls
37    readability-named-parameter
38)
39checks_to_enable_flat="${checks_to_enable[*]}"  # i.e. flat string separated by spaces
40
41checks_to_disable=(
42    # Would need a closer look before any adjustments
43    clang-analyzer-optin.performance.Padding
44
45    # Used only in xmlwf, manually checked to be good enough for now
46    clang-analyzer-security.insecureAPI.strcpy
47
48    # Disabling because buggy, see https://github.com/llvm/llvm-project/issues/40656
49    clang-analyzer-valist.Uninitialized
50)
51checks_to_disable_flat="${checks_to_disable[*]}"  # i.e. flat string separated by spaces
52
53checks="${checks_to_enable_flat// /,},-${checks_to_disable_flat// /,-}"
54
55args=(
56    --checks="${checks}"
57    --header-filter='.*'  # .. to display errors from all non-system headers
58    --warnings-as-errors=\*
59)
60
61flags=(
62    -std=c99
63
64    -Ilib/
65
66    -DENCODING_FOR_FUZZING=UTF-8
67    -DXML_ATTR_INFO
68    -DXML_DTD
69    -DXML_GE
70    -DXML_NS
71    -DXML_TESTING
72)
73
74if [[ $# -gt 0 ]]; then
75    files=( "$@" )
76else
77    # For the list of excluded files please note:
78    # https://github.com/libexpat/libexpat/issues/119
79    files=( $(
80        git ls-files -- \*.c | grep -v \
81        -e '^xmlwf/ct\.c$' \
82        -e '^xmlwf/xmlmime\.c$' \
83        -e '^xmlwf/win32filemap\.c$' \
84    ) )
85fi
86
87set -x
88
89type -P clang-tidy
90
91clang-tidy --version
92
93clang-tidy --checks="${checks}" --verify-config
94
95clang-tidy --checks="${checks}" --list-checks
96
97# These are the checks clang-tidy has *more* that so far we are missing out on,
98# for good and for bad
99clang-tidy --checks=\* --list-checks \
100    | grep -v -f <(clang-tidy --checks="${checks}" --list-checks | xargs -n1) \
101    | sed 's,\(\s*\)\([^-]\+\)-[^ ]\+,\1\2-*,' \
102    | sort -u \
103    | sed 's/^$/Disabled checks (simplified):/'
104
105pwd
106
107exec clang-tidy "${args[@]}" "${files[@]}" -- "${flags[@]}"
108