让Visual Studio的代码分析工具提高你的代码质量
2012-11-07 19:07
549 查看
静态代码分析工具,第三方的有很多。其实visual studio有的版本里面也有的哦,通过Q—A的引子希望本文可以起到抛砖引玉的作用。
Q:为什么我的Visual Studio中没有代码分析功能([分析]菜单中[仅对...运行代码分析])。
A:你的vs版本是下面其中之一吗?
Microsoft Visual Studio 2005 Team Edition for Software Developers
Visual Studio Team System Development Edition 或 Visual Studio Team Suite
Visual Studio 2010 Premium 或 Visual Studio 2010 Team Suite
Visual Studio 2012 Premium 或 Visual Studio 2012 Ultimate
Q:代码分析得出的都是些什么样的结果?
A:[项目]菜单--》[属性]--》[配置属性]--》[代码分析]--》[托管代码分析规则]里有详细的规则,下面是几个例子。
warning C6326: Potential comparison of a constant with another constant
warning C6202: Buffer overrun for '...', which is possibly stack allocated, in call to 'memset': length 'xxx' exceeds buffer size 'yyy'
warning C6386: Buffer overrun: accessing 'argument 1', the writable size is 'xxxx' bytes, but 'yyy' bytes might be written: Lines: ... ... ...
warning C6385: Invalid data: accessing 'argument 2', the readable size is 'xxx' bytes, but 'yyy' bytes might be read: Lines: ... ... ...
Q:分析得出的这些警告后,我们要做什么?
A:一句话,找到根本原因,修改使之更安全;更进一步,努力写出不被代码分析工具警告的代码。
之所以重要,是因为这些警告很可能会导致Release版本出类似buffer overrun之类难搞的问题,而且这些问题多数在debug下并不再现。
Q:msdn官方链接
A:http://msdn.microsoft.com/zh-cn/library/4dtdybt8(v=vs.90).aspx
链接的标题即为“编写高质量的代码”,有下面这样一段话。
{从一开始就确保质量。质量不是您可以在以后容易地增添的元素。过于复杂、过于隐蔽或在产品生命周期中发现过迟的问题通常得不到修复。}
{Ensure quality from the start. Quality is not something that can be easily added later. Problems that are too complex, too obscure, or are discovered too late in the product cycle are usually not fixed.}
Q:为什么我的Visual Studio中没有代码分析功能([分析]菜单中[仅对...运行代码分析])。
A:你的vs版本是下面其中之一吗?
Microsoft Visual Studio 2005 Team Edition for Software Developers
Visual Studio Team System Development Edition 或 Visual Studio Team Suite
Visual Studio 2010 Premium 或 Visual Studio 2010 Team Suite
Visual Studio 2012 Premium 或 Visual Studio 2012 Ultimate
Q:代码分析得出的都是些什么样的结果?
A:[项目]菜单--》[属性]--》[配置属性]--》[代码分析]--》[托管代码分析规则]里有详细的规则,下面是几个例子。
warning C6326: Potential comparison of a constant with another constant
warning C6202: Buffer overrun for '...', which is possibly stack allocated, in call to 'memset': length 'xxx' exceeds buffer size 'yyy'
warning C6386: Buffer overrun: accessing 'argument 1', the writable size is 'xxxx' bytes, but 'yyy' bytes might be written: Lines: ... ... ...
warning C6385: Invalid data: accessing 'argument 2', the readable size is 'xxx' bytes, but 'yyy' bytes might be read: Lines: ... ... ...
Q:分析得出的这些警告后,我们要做什么?
A:一句话,找到根本原因,修改使之更安全;更进一步,努力写出不被代码分析工具警告的代码。
之所以重要,是因为这些警告很可能会导致Release版本出类似buffer overrun之类难搞的问题,而且这些问题多数在debug下并不再现。
Q:msdn官方链接
A:http://msdn.microsoft.com/zh-cn/library/4dtdybt8(v=vs.90).aspx
链接的标题即为“编写高质量的代码”,有下面这样一段话。
{从一开始就确保质量。质量不是您可以在以后容易地增添的元素。过于复杂、过于隐蔽或在产品生命周期中发现过迟的问题通常得不到修复。}
{Ensure quality from the start. Quality is not something that can be easily added later. Problems that are too complex, too obscure, or are discovered too late in the product cycle are usually not fixed.}
相关文章推荐
- 安装sonar代码质量分析工具,以及java8和java7的安装处理
- Javascript模块化开发,使用模块化脚本加载工具RequireJS,提高你代码的速度和质量。
- 提高代码质量-工具篇
- 提高 Android 代码质量的4个工具
- 提高 Android 代码质量的4个工具
- idea,配置checkstyle 【提高代码质量,检查代码规范的工具 】Checkstyle,FindBugs,PMD,Jtest
- .NET Visual Studio 代码性能分析工具
- 11 个 Visual Studio 代码性能分析工具
- 随想录(提高代码质量的几个工具)
- .NET 11 个 Visual Studio 代码性能分析工具
- 提高 Android 代码质量的4个工具
- 使用代码分析工具分析应用程序质量【鸡蛋】
- 随想录(提高代码质量的几个工具)
- 随想录(提高代码质量的几个工具)
- 11 个 Visual Studio 代码性能分析工具
- 11个Visual Studio代码性能分析工具
- 提高代码质量 - 工具篇
- Android提高代码质量-工具篇
- idea,配置checkstyle 【提高代码质量,检查代码规范的工具 】Checkstyle,FindBugs,PMD,Jtest
- gometalinter代码质量检查分析工具(golang)