Open zhenjing opened 3 months ago
find ../ -type f ( -name ".c" -o -name ".cpp" ) | xargs infer run -- clang -c only issues of lsanSuppressed.c have found.
Write a python script for CMake project to find out all issues:
import json
import sys
import re
import os
num_args = len(sys.argv) - 1
# check argv
if len(sys.argv) < 2:
print("Usage: python script.py <path_to_json_file>")
sys.exit(1)
json_file_path = sys.argv[1]
module_name = 'DecisionCenter'
if (num_args > 2):
module_name = sys.argv[2]
print("json file: ", json_file_path, " module name: ", module_name)
with open(json_file_path, 'r') as file:
data = json.load(file)
for item in data:
if 'command' in item and module_name in item['command']:
print()
command = item['command']
#print("orig command: ", command)
command = re.sub(r'^/opt/rh/devtoolset-9/root/usr/bin/cc', 'infer run -- clang', command)
command = re.sub(r'^/opt/rh/devtoolset-9/root/usr/bin/c\+\+', 'infer run -- clang', command)
command = re.sub(r'-o .*? -c', '-c', command)
print(command)
os.system(command)
ENV: Infer version v1.2.0 contos 7.4
I have a Cmake project. (addressSanitizer.zip). run infer in the way:
only issues of lsanSuppressed.c have found:
If infer single file, more issues will be found. infer run -- clang -c ../classMemberHeapOverflow.cpp
infer run -- clang -c ../useAfterFree.cpp
How to use infer find out all issues in Cmake project?