仓酷云

标题: 来谈谈:Ubuntu体系下C言语代码反省东西-- Splint [打印本页]

作者: 蒙在股里    时间: 2015-1-16 13:42
标题: 来谈谈:Ubuntu体系下C言语代码反省工具-- Splint
系统做了些什么,这需要时间去掌握,(背命令不是一件好的学习方法,相信我你一定会在你背完之前全部忘光),尽量掌握常用命令;
看一下上面的代码(固然包含毛病,以查验splint的功效):
#include
intmain(intargc,char*argv[]){
inta=100;/*没有利用的变量*/
intb[8];
printf("Helloc
");
b[9]=100;/*分明数组越界*/
/*用到了两个为声明的变量c和d/
c=100;
d=10;
return0;
}

如今能够用splint来反省一下,为了查验是不是能够检测到数组越界,利用+bounds选项。
splinthi.c+bounds
输入了局:
hi.c:(infunctionmain)
hi.c:9:2:Unrecognizedidentifier:c
Identifierusedincodehasnotbeendeclared.(Use-unrecogtoinhibit
warning)
hi.c:10:2:Unrecognizedidentifier:d
hi.c:4:6:Variableadeclaredbutnotused
Avariableisdeclaredbutneverused.Use/*@unused@*/infrontof
declarationtosuppressmessage.(Use-varusetoinhibitwarning)
hi.c:7:2:Likelyout-of-boundsstore:
b[9]
Unabletoresolveconstraint:
requires7>=9
neededtosatisfyprecondition:
requiresmaxSet(b@hi.c:7:2)>=9
Amemorywritemaywritetoanaddressbeyondtheallocatedbuffer.(Use
-likely-boundswritetoinhibitwarning)
hi.c:3:14:Parameterargcnotused
Afunctionparameterisnotusedinthebodyofthefunction.Iftheargument
isneededfortypecompatibilityorfutureplans,use/*@unused@*/inthe
argumentdeclaration.(Use-paramusetoinhibitwarning)
hi.c:3:25:Parameterargvnotused
Finishedchecking---6codewarnings

如今具体看一下了局:
反省了局1:
hi.c:9:2:Unrecognizedidentifier:c
Identifierusedincodehasnotbeendeclared.(Use-unrecogtoinhibit
warning)
hi.c:10:2:Unrecognizedidentifier:d
hi.c:4:6:Variableadeclaredbutnotused
Avariableisdeclaredbutneverused.Use/*@unused@*/infrontof
declarationtosuppressmessage.(Use-varusetoinhibitwarning)

这些应当是splint检测到变量c和d没有声明。
反省了局2:
hi.c:7:2:Likelyout-of-boundsstore:
b[9]
Unabletoresolveconstraint:
requires7>=9
neededtosatisfyprecondition:
requiresmaxSet(b@hi.c:7:2)>=9
Amemorywritemaywritetoanaddressbeyondtheallocatedbuffer.(Use
-likely-boundswritetoinhibitwarning)

这些是反省存在数组越界,由于吧b[8]的最年夜数组序号应当是7,而不是9,以是呈现requires7>=9;
反省了局3:
hi.c:3:14:Parameterargcnotused
Afunctionparameterisnotusedinthebodyofthefunction.Iftheargument
isneededfortypecompatibilityorfutureplans,use/*@unused@*/inthe
argumentdeclaration.(Use-paramusetoinhibitwarning)
hi.c:3:25:Parameterargvnotused

这些标明argc和argv变量声了然,可是没有利用。这个不是甚么成绩。
假如当心利用splint,应当关于c言语的程序编写有十分年夜的帮助感化!

</p>
使用gcc或g++进行编译,使用gdb进行调试;
作者: 谁可相欹    时间: 2015-1-17 16:56
发问的时候一定要注意到某些礼节。因为Linux社区是一个松散的组织、也不承担回复每个帖子的义务。它不是技术支持。
作者: 小妖女    时间: 2015-1-21 06:46
在学习linux的工程中,linux学习方法有很多种,这里是小编的学习心得,给大家拿出来分享一下。
作者: 活着的死人    时间: 2015-1-30 10:10
学习Linux半年了~个人认为不会的多在网上找资料网上有很多资料可以搜索到,LS那位说放手去搞。
作者: 金色的骷髅    时间: 2015-2-6 10:04
随着IT从业人员越来越多,理论上会有更多的人使用Linux,可以肯定,Linux在以后这多时间不会消失。
作者: 简单生活    时间: 2015-2-15 22:49
让我树立了很大的信心学好这门课程,也学到了不少专业知识和技能。?
作者: 兰色精灵    时间: 2015-3-4 17:36
对我们学习操作系统有很大的帮助,加深我们对OS的理解。?
作者: 老尸    时间: 2015-3-11 20:36
甚至目前许多应用软件都是基于它的。可是没有哪一个系统是十分完美的。
作者: 再见西城    时间: 2015-3-19 12:45
不同于Windows?系统需要花钱购买,因为Linux的核心是免费的,自由使用的,核心源代码是开放的。
作者: 愤怒的大鸟    时间: 2015-3-28 08:56
工具书对于学习者而言是相当重要的。一本错误观念的工具书却会让新手整个误入歧途。目前国内关于Linux的书籍有很多不过精品的不多。




欢迎光临 仓酷云 (http://www.ckuyun.com/) Powered by Discuz! X3.2