Ubuntu检查php,Linux_Ubuntu系统下C语言代码检查工具-- Splint,看一下下面的代码(当然包括 - phpStudy...

Ubuntu系统下C语言代码检查工具-- Splint

看一下下面的代码(当然包括错误,以检验splint的功能):

#include

int main(int argc,char* argv[]){

int a=100; /*没有使用的变量*/

int b[8];

printf("Hello c\n");

b[9]=100; /*明显数组越界 */

/* 用到了两个为声明的变量c和d/

c=100;

d=10;

return 0;

}

现在可以用splint来检查一下,为了检验是否可以检测到数组越界,使用+bounds选项。

splint hi.c +bounds

输出结果:

hi.c: (in function main)

hi.c:9:2: Unrecognized identifier: c

Identifier used in code has not been declared. (Use -unrecog to inhibit

warning)

hi.c:10:2: Unrecognized identifier: d

hi.c:4:6: Variable a 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)

hi.c:7:2: Likely out-of-bounds store:

b[9]

Unable to resolve constraint:

requires 7 >= 9

needed to satisfy precondition:

requires maxSet(b @ hi.c:7:2) >= 9

A memory write may write to an address beyond the allocated buffer. (Use

-likely-boundswrite to inhibit warning)

hi.c:3:14: Parameter argc not used

A function parameter is not used in the body of the function. If the argument

is needed for type compatibility or future plans, use /*@unused@*/ in the

argument declaration. (Use -paramuse to inhibit warning)

hi.c:3:25: Parameter argv not used

Finished checking --- 6 code warnings

现在详细看一下结果:

检查结果1:

hi.c:9:2: Unrecognized identifier: c

Identifier used in code has not been declared. (Use -unrecog to inhibit

warning)

hi.c:10:2: Unrecognized identifier: d

hi.c:4:6: Variable a 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)

这些应该是splint检测到变量c和d没有声明。

检查结果2:

hi.c:7:2: Likely out-of-bounds store:

b[9]

Unable to resolve constraint:

requires 7 >= 9

needed to satisfy precondition:

requires maxSet(b @ hi.c:7:2) >= 9

A memory write may write to an address beyond the allocated buffer. (Use

-likely-boundswrite to inhibit warning)

这些是检查存在数组越界,因为吧b[8]的最大数组序号应该是7,而不是9,所以出现requires 7 >= 9;

检查结果3:

hi.c:3:14: Parameter argc not used

A function parameter is not used in the body of the function. If the argument

is needed for type compatibility or future plans, use /*@unused@*/ in the

argument declaration. (Use -paramuse to inhibit warning)

hi.c:3:25: Parameter argv not used

这些表明argc和argv变量声明了,但是没有使用。这个不是什么问题。

如果小心使用splint,应该对于c语言的程序编写有非常大的辅助作用!相关阅读:

虚拟主机IIS防范入侵常见问答

Oracle性能优化之Rollback Segment优化

asp下如何在Access数据库中立即得到所插入记录的自动编号?

ASP ajax分页教程一

利用JQuery的load函数动态加载其它页面的内容的实现代码

取消Windows XP系统自动提示磁盘空间低

DEBUG 命令详解

截取实际长度字符串,并用空格替换

Ajax in action 英文版配书源码 下载

javascript实例教程(21-7)

WordPress主题在线生成器制作WordPress主题

让IE支持HTML5办法

xhtml和html的概念与区别

php批量删除数据

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值