splint的安装与使用
来源:互联网 发布:淘宝加盟骗局公安查吗 编辑:程序博客网 时间:2024/05/18 01:24
简介
splint是一个GNU免费授权的 Lint程序,是一个动态检查C语言程序安全弱点和编写错误的程序。Splint会进行多种常规检查,包括未使用的变量,类型不一致,使用未定义变量,无法执行的代码,忽略返回值,执行路径未返回,无限循环等错误。
安装
下载源代码,按照安装步骤安装splint。
make的时候出现下列错误:
/home/pngynghay/splint/src/cscanner.c:2483: undefined reference to `yywrap'
cscanner.o: In function `yylex':
/home/pngynghay/splint/src/cscanner.c:2133: undefined reference to `yywrap'
collect2: ld returned 1 exit status
make[2]: *** [splint] Error 1
修改文件cscanner.c,在其中添加函数实现
{
return 1;
}
配置
export LARCH_PATH=/usr/local/share/splint/lib/
export LCLIMPORTDIR=/usr/local/share/splint/imports/
实践
#include <stdio.h>#include <stdlib.h>int main(){ unsigned char ch = 128; signed char sch = ch; int *p = (int*)malloc(1000*sizeof(int)); printf("%d", sch);}
[root@localhost test]# splint test.c
Splint 3.1.2 --- 15 Jan 2014
test.c: (in function main)
test.c:6:21: Variable ch initialized to type int, expects unsigned char: 128
To make char and int types equivalent, use +charint.
test.c:7:20: Variable sch initialized to type unsigned char, expects char: ch
To ignore signs in type comparisons use +ignoresigns
test.c:9:15: Format argument 1 to printf (%d) expects int gets char: sch
test.c:9:11: Corresponding format code
test.c:10:2: Path with no return in function declared to return int
There is a path through a function declared to return a value on which there
is no return statement. This means the execution may fall through without
returning a meaningful result to the caller. (Use -noret to inhibit warning)
test.c:10:2: Fresh storage p not released before return
A memory leak has been detected. Storage allocated locally is not released
before the last reference to it is lost. (Use -mustfreefresh to inhibit
warning)
test.c:8:42: Fresh storage p created
test.c:8:7: Variable p declared but not used
A variable is declared but never used. Use /*@unused@*/ in front of
declaration to suppress message. (Use -varuse to inhibit warning)
Finished checking --- 6 code warnings
从输出信息可以看出:变量类型转换、内存泄露、返回值等相关问题都被检测了出来。在代码编译之前,对代码使用splint进行检查,可以避免很多不必要的错误。
在Linux下,通过man splint可以查看更多的splint选项
splint库函数问题
如果代码中涉及到库函数,需要添加库函数支持,才能让splint支持库函数的解析。
splint test.c +posixlib 支持POSIX库
splint test.c +unixlib 支持Unix库
- splint的安装与使用
- splint的学习与使用
- unbuntu下splint的使用与配置
- splint的使用
- 代码静态分析工具 - splint的学习与使用
- splint使用
- splint使用
- splint使用
- splint在linux的简单使用
- Ubuntu中C代码静态检查工具Splint的安装配置和使用
- 代码静态分析工具——splint的学习与使用
- 代码静态分析工具——splint的学习与使用
- 代码静态分析工具——splint的学习与使用
- 代码静态分析工具——splint的学习与使用(转)
- 代码静态分析工具——splint的学习与使用
- 代码静态分析工具——splint的学习与使用
- splint 编译安装
- Ubuntu 下安装splint
- R语言与机器学习学习笔记(分类算法)(4)支持向量机
- GetMessage and PeekMessage Internals
- Ext Direct Spring Tree Load Method
- IOS之创建一个静态库
- 防止ViewPager中的Fragment被销毁的方法
- splint的安装与使用
- ADT 修改project名称
- R语言与机器学习学习笔记(分类算法)(5)神经网络
- oracle 高水位线详解
- 由UIColor 生成 UIImage
- -[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object' 解决方法
- Last_IO_Error: error connecting to master Last_IO_Errno: 2003解决方法
- 自定义标签注入
- 差强人意的iBeacons定位精度