Linux 下代码检查工具
一、sonarlint 进行代码审计
JAVA_HOME=/usr/lib/jvm/jdk-18
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH
保存文件以后,在source /etc/profile 使得生效
代码检查
- 需要配置Makefile tool ,设置相关参数 生成 compile_commands.json
- No compilation databases were found in the workspace
How to generate compile commands
vs code 文件->首选项->MakeFile
{
"makefile.configurations": [
{
"name": "selinux_permission_manager",
"makeArgs": ["TARGET=permission_manager_dbus_daemon" ,
"TOOLS_SRC=$(wildcard src/tools/*.c)" ,
"TOOLS=$(patsubst %.c,%,$(TOOLS_SRC))" ,
"CC = gcc" ,
"INC = -I src/include" ,
"LIBS = $(shell pkg-config --cflags --libs libsystemd)" ,
"LIBS += -lpthread -lRoseLprAPI -lsemanage -lselinux -lmount" ,
"CFLAGS += -g" ,
"DAEMON_SRC=$(wildcard src/dbus_daemon/*.c src/policy_control/*.c)" ,
"OBJS=$(patsubst %.c,%.o,$(DAEMON_SRC))"]
}
],
"sonarlint.pathToCompileCommands": "${workspaceFolder}/.vscode/compile_commands.json"
}
二、splint的安装。
在安装splint的时候遇到了不少问题(注:在ubuntu下),这里我把安装工程描述一边:
1.下载splint:http://www.splint.org/downloads/splint-3.1.2.src.tgz 这是最新的。不过我使用的是3.1.1版http://www.splint.org/downloads/binaries/splint-3.1.1.Linux.tgz 。
2.解压包 安装:
tar -xzf splint-3.1.1.linux.tgz
mkdir /usr/local/splint
cd splint-3.1.1
./configure --prefix=/usr/local/splint
make install
3.配置
#vi ~/.bashrc
加入:export LARCH_PATH= /usr/local/splint/share/splint/lib
export LCLIMPORTDIR = /usr/local/splint/share/splint/import
#source ~/.bashrc
exprot PATH=/usr/local/splint/bin: P A T H ( 这里注意,有的说明上这样写 e x p o r t P A T H = / u s r / l o c a l / s p l i n t / b i n / s p l i n t : PATH (这里注意,有的说明上这样写export PATH=/usr/local/splint/bin/splint: PATH(这里注意,有的说明上这样写exportPATH=/usr/local/splint/bin/splint:PATH。我使用是发现不能有问题 )
或者将~/.bashrc重新打开,将上面一句加入文件中,注销重启。完成环境变量的设置
4.可以使用# splint abc.c
https://blog.csdn.net/xiaowang1379214245/article/details/82688802
https://www.cnblogs.com/LiuYanYGZ/p/11729938.html
http://senlinzhan.github.io/2017/12/31/valgrind/