仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 849|回复: 9
打印 上一主题 下一主题

[其他Linux] 来谈谈:Ubuntu体系下C言语代码反省东西-- Splint

[复制链接]
蒙在股里 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 13:42:25 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
系统做了些什么,这需要时间去掌握,(背命令不是一件好的学习方法,相信我你一定会在你背完之前全部忘光),尽量掌握常用命令;
看一下上面的代码(固然包含毛病,以查验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:00 | 只看该作者
发问的时候一定要注意到某些礼节。因为Linux社区是一个松散的组织、也不承担回复每个帖子的义务。它不是技术支持。
小妖女 该用户已被删除
板凳
发表于 2015-1-21 06:46:24 | 只看该作者
在学习linux的工程中,linux学习方法有很多种,这里是小编的学习心得,给大家拿出来分享一下。
活着的死人 该用户已被删除
地板
发表于 2015-1-30 10:10:11 | 只看该作者
学习Linux半年了~个人认为不会的多在网上找资料网上有很多资料可以搜索到,LS那位说放手去搞。
金色的骷髅 该用户已被删除
5#
发表于 2015-2-6 10:04:23 | 只看该作者
随着IT从业人员越来越多,理论上会有更多的人使用Linux,可以肯定,Linux在以后这多时间不会消失。
简单生活 该用户已被删除
6#
发表于 2015-2-15 22:49:15 | 只看该作者
让我树立了很大的信心学好这门课程,也学到了不少专业知识和技能。?
兰色精灵 该用户已被删除
7#
发表于 2015-3-4 17:36:44 | 只看该作者
对我们学习操作系统有很大的帮助,加深我们对OS的理解。?
老尸 该用户已被删除
8#
发表于 2015-3-11 20:36:44 | 只看该作者
甚至目前许多应用软件都是基于它的。可是没有哪一个系统是十分完美的。
再见西城 该用户已被删除
9#
发表于 2015-3-19 12:45:11 | 只看该作者
不同于Windows?系统需要花钱购买,因为Linux的核心是免费的,自由使用的,核心源代码是开放的。
愤怒的大鸟 该用户已被删除
10#
发表于 2015-3-28 08:56:38 | 只看该作者
工具书对于学习者而言是相当重要的。一本错误观念的工具书却会让新手整个误入歧途。目前国内关于Linux的书籍有很多不过精品的不多。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-4-28 05:22

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表