aboutsummaryrefslogtreecommitdiff
path: root/test-static
blob: 4b74e2435bf3496b1bee1fa7cdf993c211d996a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh
# We don't use printf's percent notation with our custom logging mechanism,
# so the compiler cannot check it for us like it usually does.
#
# In clang-query terms, the string we're interested in can be found through:
#   set traversal IgnoreUnlessSpelledInSource
#   set output dump
#   match callExpr(callee(functionDecl(
#     hasName("log_full"))),
#     hasArgument(5, stringLiteral().bind("format")))
# However, the tool is too restricted to be useful in a shell script.
perl -n0777 - "$(dirname "$0")"/xC.c <<-'END'
	while (/\blog_[^ ]+\s*\([^"()]*"[^"]*%\w[^"]*"/gm) {
		my ($p, $m) = ($`, $&);
		printf "$ARGV:%d: suspicious log format string: %s...\n",
			(1 + $p =~ tr/\n//), ($m =~ s/\s+/ /rg);
		$status = 1;
	}
	END {
		exit $status;
	}
END