写代码之际突然想起了pc-lint这个"古董级"的代码静态分析工具;  
下午机房的服务器歇菜了,没法调试游戏,刚好抽出时间来研究一下pc-lint集成在SourceInsight中;
当然百度上也有许多集成的方法,但是经常有某些错误,导致进程无法lint的正常执行;
分3块部分来讲,先说第一块:

一:安装pclint和SourceInsight

安装pclint: 上http://download.csdn.net/detail/u012329294/8280039   或者直接百度
安装SourceInsight: http://rj.baidu.com/soft/detail/10258.html?ald    或者直接百度
配置SourceInsight可以参考我去年写的一篇SourceInsight安装配置指南;

pclint主要配置是 std.lnt  ---主入口 
其中要配置一些其他的.lnt文件,如果在之后的运行过程中提示找不到lnt文件但是实际文件存在的情况,可以手动拷贝到std.lnt文件中;  在最后加上引用lib文件的路径作为头文件引用路径:
我这里已经写好了,大家直接拷贝就行了;
std.lnt文件我待会儿也会发在附件中;

二:将pclint集成到SourceInsight

1.打开Options中的Custom Commonds
2.随意起个名字比如pclint;,再点击Add
3.Run中填: C:\lint\lint-nt  -u  C:\lint\std.lnt  C:\lint\env-vc6.lnt %f  
4.勾选Iconic Window; Capture Output; Parse Links in OutPut; File,then Line; 4个选项
5.Close
6.打开MenuAssignments界面;输入自己刚刚取的名字
7.在MenuAssignments界面选择Menu ,选择Help,选择<end of menu>
8.点击insert;

9.你可以看看在Help界面,有没有出现刚刚你自己定义的名字
大功告成;

三.开始运行pclint了;
1.在SourceInsight中打开你想要检查的cpp文件,
2.Help->pclint;开始执行了
3.执行完毕后会弹出link的分析界面
那就说明lint完毕了;

四.简单分析下,拿自己代码做例子吧;
1.上图

我圈了4个红色的地方;
然后再来看看我写的代码:(提示:::点击左边的小红箭头可以直接跳转到指定代码位置!!)
红圈1:

能看出来后面的return FALSE; 是肯定走不到的分支;

红圈4:

这个比较严重,我发现我的stActiveSingle变量居然没有用过....

红圈2: 
代码是指针的直接偏移指定字节数得到结构体指针;还是很可能野指针的,但是这个毕竟按照消息头规则来的,那应该是没问题;

红圈3: 2
error 641: (Warning -- Converting enum 'TCBY_ENUM_ACTIVETYPE' to int)
不能直接把enum转成int;

五.分析完毕

附:lint文件内容:

//  Microsoft C and Visual C++ 6.x, -si4 -sp4, lib-w32.lnt
//  Standard lint options
//    co-msc60.lnt
//    Compiler Options for Microsoft C Version 12.x
//         (32 bit version)

-cmsc
-si4    // integers are 4 bytes
-sp4    // pointers are 4 bytes too.
-A(C++1997)     // The C++ standard used was 1997,
                // i.e., not the 2003 upgrade

//    This file contains options to allow PC-lint to process source
//    files for your compiler.  It is used as follows:
//
//    lint  co-msc60.lnt  source-file(s)
//
-d_M_IX86=300   // assume Intel 80386 architecture -- modify to suit

// We now support __declspec directly so that the following
        // option is now commented out.  If trouble ensues you can
        // once again disable __declspec through this option.
        // -d__declspec()= // ignore this construct
-d_declspec=__declspec  // the single '_' version is occasionally used

// while processing compiler (library) header files ...
-wlib(1)    // sets the warning level within library headers to 1
        // (no warnings, just syntax errors).  Comment out if you
        // are actually linting library headers.  This
        // option makes obsolete options of the form -elib(axxx) where
        // xxx >= 400 which may be retained for historical reasons.
-elib(19)   // useless declarations (lone semicolons)
-elib(123)  // function-like macro name used as non macro
-elib(652)  // suppress message about #define of earlier declared symbols
-elib(762)  // suppress message about multiple identical declarations and
-elib(760)  // suppress message about multiple identical macro defs
-elib(514)  // allow #if <boolean> | <boolean>
-elib(553)  // undefined preprocessor variables assumed 0
-elib(1081) // suspicious object argument to an object parameter
-elib(726)  // extraneous comma in enum definition

//  SREGS, WORDREGS, BYTEREGS are defined in both bios.h and dos.h
//  and accordingly you MAY get type differences based on 'origin'.
//  If so, use the following options:
//      -etd(origin)
//      -elib(770)

-format=%(%f(%l)\s:\s%)%t\s%n:\s%m
        // error format similar to MSC
        // Note that %c can also be used to specify column
-e46    // allows bit-fields to be other than int or unsigned
+fan    // allow anonymous unions
+fdi    // Use directory of the including file
+fbo    // enable the bool type
+fwm    // wprintf format codes are not standard
-fdh    // do not append a .h to header names
-ffb    // do not establish a separate scope for declares within for clauses
-esym(123,min,max)  // allows users to use min, max as variables
-d_MSC_VER=1200 // compiler version (in decimal)
+rw(__inline)   // activate the __inline keyword
+ppw(import)    // activate #import
-d_inline=__inline  // _inline is the same as __inline
-sld10          // sizeof(long double) is 10.
-function(exit,_exit)   // _exit() is like exit()
-function(exit,_assert)   // _assert() is like exit()
-emacro(506,assert) // don't warn about constant value Boolean
-emacro(734,putc)   // don't complain about items being too large.
-emacro(415,_FP_SEG)  // access of out-of-bounds pointer
-emacro(740,FP_SEG,FP_OFF)  // unusual casts
-emacro((???),va_arg)   // the va_arg() macro can yield 415, 416, 661, 662
            // 796 and 797 (out-of-bounds errors).
-emacro(413,offsetof)  // use of NULL pointer creates a stir
-emacro(545,offsetof)  // addressing an array member is OK
-emacro(845,RGB)       // a common use of RGB uses a operator that produces a 0
-e793           // inhibit 'ANSI limit reached' --
        // limits are impractically low with MSVC headers
-esym(628,eof)  // failure to provide argument information for eof()
-esym(773,L_tmpnam)     // defined with an unparenthesized '+'
-esym(438,_acp)         // USES_CONVERSION assigns to _acp.

//  The following functions exhibit variable return modes.
//  That is, they may equally-usefully be called for a value
//  as called just for their effects.  Accordingly we inhibit
//  Warning 534 for these functions.
//  Feel free to add to or subtract from this list.

-esym(534,close,creat,fclose,fflush,_flsbuf,fprintf,fputc)
-esym(534,fputs,fscanf,fseek,fwrite,lseek,memcpy,memmove,memset)
-esym(534,printf,puts,scanf,sprintf,sscanf,strcat,strcpy)
-esym(534,strncat,strncpy,unlink,write)

//  These are the wide char variants of printf-scanf family

-wprintf( 1, wprintf )
-wprintf( 2, fwprintf, swprintf )
-wscanf( 1, wscanf )
-wscanf( 2, fwscanf, swscanf )

// The following options are used to adjust our function mimicry to
// the actual library as provided by MS.

-function( wcstombs(1) )  // remove the check for a NULL first arg to wcstombs()

// The following options are required by most compilers to
// noiselessly process iostream.h

-elib(1717) //empty prototypes
-elib(522) //function return value ignored
-elib(1053) //prototypes cannot be distinguished
-elib(1721) //unusual operator =() declaration
-elib(1720) //assignment op has non-const parameter
-elib(655)  // bitwise operator combining compatible enum's
-elib(641)  // converting enum's to int
-elib(537)  // repeated include file (ios.h)
-elib(1511) // member (rdbuf) hides nonvirtual member
-elib(1712) // default constructor not defined for class
-elib(1736) // redundant access specifier
-esym(1702,operator<<,operator>>)  // both a member and an ordinary function

// These functions return things that are frequently ignored.

-esym(534,*operator<<,*operator>>)

// The following additional options seem to be needed.

-elib(506) // constant value Boolean
-elib(620) // el or one? (some constants end in 'l' not 'L')
-elib(648) // overflow in computing constant (3<<16)
-elib(659) // nothing follows '}' on some line
-elib(723) // suspicious use of '='
-elib(747) //significant prototype coercion
-elib(740) //unusual pointer casts
-elib(1007) // virtual functions within extern "C" block
-elib(1029) //default argument repeated -- can't dist. char, signed char
-elib(1055) //call to rdbuf() questioned?
-elib(1504) // apparently useless structs
-elib(1708,1709) // minor C/C++ declaration conflict
-elib(1707) // operator new declared w/o 'static'
-elib(1722) // assignment op does not return reference
-elib(149)  // default argument found in C code.
-elib(578)  // declaration of time hides delaration of global time().
-elib(761)  // two equivalent typedef declarations
-elib(1065)  // same name declared as "C" and not "C"
-elib(1066)  // same name declared as "C" and not "C"
-elib(1704)   // constructor with private access declaration
-elib(1735)   // default parameter within virtual function
-elib(773)  // macros that look like unparenthesized expressions
-elib(806)  // 1-bit bitfields typed int
-elib(1501) // 0-length data members
-elib(1510) // base class has no destructor
-elib(1516) // data member hides inherited member
-elib(1509) // base class destructor is not virtual

// Special Notice:  You may be receiving mysterious 1058 errors
//   when you use "iomanipulator"s.  For example:
//   cout << setw(4) << 4;
//   results in Error 1058 (assigning a const to a ref) because the
//   manipulator setw returns a non-lvalue which is assigned to a reference.
//   This reflects an oversight in the Microsoft header file: iomanip.h
//   Therein you may change the declaration:
//     friend ostream& operator<<(iostream& s, IOMANIP(T) & sm) { ...
//   to:
//     friend ostream& operator<<(iostream& s, const IOMANIP(T) & sm) { ...
//   to reflect the fact that sm is not modified by this function.

-d_M_IX86=300   // define the architecture (one of _M_IX86, _M_ALPHA,
        // _M_PPC, _M_MRX000)
-d_INTEGRAL_MAX_BITS=64  // denotes support for __int64
+fll            // enable long long
-d__STDC__=0    // Starting with 2.0, the tests within Microsoft header
        // files for __STDC__ are of the form #if rather than #ifdef
-dWIN32         // this is necessary because without WIN32 being defined
-d_WIN32        // a very gross syntax error is exposed in the objbase.h
        // ... definition of function operator ==().  Alternatively,
        // ... repair the function definition.
-dDBG=0         // There is a #if test made for this variable.
-d__FUNCTION__=___function___
                        // use Lint's built-in define

/*  The option -d_NEW_ previously appearing in this spot is no longer
    recommended as it nullifies the <new> header and because of this
    prevents definition of 'bad_alloc' among other things.
 */

/*  DLL's  or Multithreads?  Enable the following:

-d_AFXDLL   // making a DLL
    -d_DLL      // ditto
    -d_MT       // multi-thread

*/

/*  At one time we indicated that wchar_t was predefined by using
    the option +fwc but then in order to keep the Microsoft headers
    from redefining it we used the option -d_WCHAR_T_DEFINED.
    But this in turned created a rare problem so now we just leave it
    undefined.
 */

// In the following option we define __uuidof() and suppress
// Errors 50 and 69 and 1924 in exprs. containing same
-d"__uuidof()= /*lint --e(50,69,1924) */ (_GUID)0"

-esym(123,FD_SET)  // defined as macro and as typedef
-esym(1726,endl,ends)   // taking the address of an overloaded function
-esym(18,Data_t::Data_t)  // definition not matching declaration

-elib(10)       // expecting ')' -- comdef.h has a: #if defined( id
-elib(43)       // vacuous array within _MIDL_FORMAT_STRING
-elib(602)      // benign comment within comment
-elib(657)      // declaring "anonymous struct" in union _LARGE_INTEGER
-elib(799)      // long numerical constant for max. __int64
-elib(1502)     // nothrow has no data members
-elib(1505)     // no access specifier in base class specifier
-elib(1515)     // AFX_THREAD_STATE member has no default constructor
-elib(1706)     // Unusual declaration with a scope operator
-elib(1725)     // data member is a reference
-elib(1548)     // conflicting exception specifications
-elib(1737)     // hiding global operator new
-elib(1739)     // binary operator should be non-member function
-elib(1748)     // non-virtual base class included twice
-elib(1759)     // post-fix operator returns a reference

+e1942      // This Elective Note alerts the user to the non-standard
            // way in which MS handles originally-dependent base classes.
            // E.g.  template<class T> class A : T { ... x ... };
            // Should T be searched for "x" during instantiation?
            // the standard says "no", MS does.

//  Add elements of ole automation

// BSTR functions (part of OLE Automation)

-sem( SysAllocString, @p == malloc(1p) || @p == 0, 1p )
-sem( SysAllocStringByteLen, @P == malloc(2n+1) || @p == 0 )
-sem( SysAllocStringLen, @p == malloc(2n+1) || @p == 0 )
-sem( SysStringLen, 1p ? @n == 1p - 1 : @n == 0 )
-function( free, SysFreeString )

-d_stdcall=__stdcall    // make _stdcall equivalent to __stdcall

//  lib-w32.lnt
//    PC-lint Library Options File for 32-bit mode windows.h

-d__FLAT__
-d_WIN32
-si4
-sp4
-esym(14,pLocalHeap)   // variable defined in windows.h
-e740   // remove 'suspicious cast' messages because these must be
    // routinely done within Windows.
-elib(46) // windows.h uses a BYTE as base of bit field.
-e793       // windows breaks ANSI limits

//  the following functions have their return value typically ignored.
//  add or subtract from this list as desired.
-esym(534,RegisterClass,ShowWindow,TranslateMessage,DispatchMessage)
-esym(534,DrawText,GetTextMetrics,ReleaseDC,TextOut,SetTextAlign)
-esym(534,SetScrollPos,SelectObject,SetBkMode,SendMessage,MessageBox)
-esym(534,MessageBoxA,MessageBoxW,PostMessageA,PostMessageW)
-esym(534,PatBlt,DeleteDC,SetCapture,SetCursor,StretchBlt)
-esym(534,Rectangle,MoveTo,LineTo,ShowCursor,MoveWindow,SetWindowWord)
-esym(534,SetPixel,FillRect,DeleteObject,KillTimer,GetProfileString)
-esym(534,SetWindowLong,SetFocus,SetBkColor,SetTextColor,SetBrushOrg)
-esym(534,UnrealizeObject,_lclose,Polygon,FrameRect,LoadString)
-esym(534,GetInstanceData,GlobalUnlock,FreeResource,LoadString)
-esym(534,DrawIcon,AppendMenu,GetObject,CheckMenuItem,SetClassWord)
-esym(534,EnableMenuItem,SetMenu,DestroyMenu,TrackPopupMenu)
-esym(534,AnsiUpper,Arc,BeginPaint,BitBlt,ChangeClipboardChain,Chord)
-esym(534,CloseClipboard,CombineRgn,DdeClientTransaction,DdeDisconnect)
-esym(534,DdeFreeStringHandle,DdeGetData,DdeNameService,DdePostAdvise)
-esym(534,DdeQueryString,DdeUninitialize,DeleteMenu,DeleteMetaFile)
-esym(534,DestroyWindow,DialogBox,DPtoLP,Ellipse,EmptyClipboard,EnableWindow)
-esym(534,EnumChildWindows,EnumWindows,Escape,GetClassName,GetDlgItemText)
-esym(534,GetFileTitle,GetMenuString,GetStrings,GetSystemMenu,GetTextFace)
-esym(534,GetWindowText,GlobalDeleteAtom,GlobalFree,GlobalGetAtomName)
-esym(534,LocalFree,LocalUnlock,LockResource,lstrcpy,OpenClipboard)
-esym(534,Pie,PlayMetaFile,PopFindNextText,PostDataMessage,PostMessage)
-esym(534,RestoreDC,SaveDC,SelectClipRgn,SendDlgItemMessage,SetClipboardData)
-esym(534,SetDIBitsToDevice,SetMapMode,SetMapperFlags,SetROP2,SetStretchBltMode)
-esym(534,SetTextJustification,SetTimer,SetViewportExt,SetViewportOrg)
-esym(534,SetWindowExt,SetWindowOrg,StretchDIBits,WinExec)

//  Ignored parameters
-esym(715,lpszCmdParam,lpszCmdLine)

-emacro(648,PSN_*)      // ignore unsigned overflow (0-200U)

PC-lint集成于SourceInsight 范例以及简单分析;提高代码的健壮性;的更多相关文章

  1. 【原创】在pc端集成地图功能(一)

    在pc端做人员调度功能,用到地图.看了一点高德地图API,由于手机端用的是百度地图,现在需要改用百度地图.下面把看的高德地图一点点成果记录下来: 1.在高德地图开放平台(http://lbs.amap ...

  2. 利用WxJava实现PC网站集成微信登录功能

    原文地址:https://mp.weixin.qq.com/s/rT0xL9uAdHdZck_F8nyncg 来源:微信公众号:java碎碎念 1. 微信开放平台操作步骤 微信开放平台地址:https ...

  3. FFmpeg的HEVC解码器源码简单分析:解析器(Parser)部分

    ===================================================== HEVC源码分析文章列表: [解码 -libavcodec HEVC 解码器] FFmpeg ...

  4. FFmpeg的HEVC解码器源代码简单分析:解析器(Parser)部分

    ===================================================== HEVC源代码分析文章列表: [解码 -libavcodec HEVC 解码器] FFmpe ...

  5. x264源代码简单分析:x264命令行工具(x264.exe)

    ===================================================== H.264源代码分析文章列表: [编码 - x264] x264源代码简单分析:概述 x26 ...

  6. FFmpeg的H.264解码器源代码简单分析:解析器(Parser)部分

    ===================================================== H.264源代码分析文章列表: [编码 - x264] x264源代码简单分析:概述 x26 ...

  7. FFmpeg源代码简单分析:configure

    ===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...

  8. FFmpeg源代码简单分析:makefile

    ===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...

  9. nginx和Tomcat集成后发生的重定向问题分析和解决

    nginx和Tomcat集成后发生的重定向问题分析和解决 Tomcat前端配置一个HTTP服务器应该是大部分应用的标配了,基本思路就是所有动态请求都反向代理给后端的Tomcat,HTTP服务器来处 理 ...

随机推荐

  1. canvas——路径搜索

    在前一篇博客中随机生成迷宫,现在就以随机生成的迷宫为地图,开始寻找路径. 迷宫寻路也可以使用DFS,BFS,但常见的是A*算法,它是启发式搜索算法的一种,效率相比前两者也更高.接下来以A*算法为例,迷 ...

  2. (原创)Python 自动化测试框架详解

    自己折腾了一个python的自动化测试框架,梳理了一下流程,简单分享一下. 项目背景 B/S架构,进行用户界面的自动化测试 工具选择 python开发的自动化测试框架,足够灵活,可以随时根据需求进行变 ...

  3. a标签点击之后有个虚线边框,怎么去掉

    1.行内处理方式1 <a hidefocus="true" href="#"></a> 2.行内处理方式2,让a标签获得焦点就失去焦点, ...

  4. a标签实现文件下载

    如果想通过纯前端技术实现文件下载,直接把a标签的href属性设置为文件路径即可,如下: <a href="https://cdn.shopify.com/s/files/1/1545/ ...

  5. angular表单验证实例----可用的代码

    前段时间,公司做一个单页面,就是一个表单验证,早开始在菜鸟教程上关注了angular,所以下派上用场了 angular里面对于表单验证,设置了很多指令. 也就是说不用自己写一些逻辑,直接绑定指令就行. ...

  6. asp.net core中负载均衡场景下http重定向https的问题

    上周欣喜地发现,微软官方终于针对 asp.net core 在使用负载均衡的情况下从 http 强制重定向至 https 的问题提供了解决方法. app.UseForwardedHeaders(new ...

  7. 关于 asp.net 点击确定按钮 获取不到新值问题

    点击事件内,可以使用request.form[" kk"] 获取到值,但是this.txt.Text 确实旧值, 尼玛,居然没加isPostBack重新加载了数据 ,request ...

  8. 如何在BCGControlBar界面库的CBCGPFormView子视图里面添加工具栏

    最近有一个项目需求,需要在子视图里面添加一个新工具栏用来处理当前视图对应模块的操作.之前在对话框模式下做过添加工具栏的实现,在CBCGPFormView中添加工具栏还是头一次.在这里记录一下,给自己留 ...

  9. javascript中apply,call,bind区别,bind兼容等问题总结

    1 三者的相似之处: (1).都是用来改变函数的this对象的指向的 (2).都是用第一个参数来做this对象的指向 (3).都可以传参数进去 那么,具体到它们有什么区别呢?请看下面的例子: 两个对象 ...

  10. angularJS directive详解(自定义指令)

    Angularjs指令定义的API AngularJs的指令定义大致如下 其中return返回的对象包含很多参数,下面一一说明 1.restrict (字符串)可选参数,指明指令在DOM里面以什么形式 ...