1. 程式人生 > >程式質量管理(二)——關於靜態程式碼掃描

程式質量管理(二)——關於靜態程式碼掃描

騰訊開源了一款靜態程式碼掃描工具:

http://code.tencent.com/tscancode.html

這個工具可以掃描發現程式碼中潛在的漏洞隱患,比如解引用為空,客戶端不同步問題等。

牆裂推薦在開發過程中作為日常掃描,可以幫助發現很多潛在的Bug。

TScanCode提供了命令列工具,可以很方便地和持續整合工具(例如Jenkins、Hudson)進行整合,作為一個例行的定時掃描任務:


圖一 檢查掃描結果中是否存在錯誤的批處理


圖二 過濾掉誤報,重建TScanCode能夠識別的XML結果檔案的批處理


圖三 過濾誤報的批處理


圖四 過濾誤報的批處理


圖五 TScanCode的命令列掃描批處理


圖六 例行掃描的結果,發現了兩個問題


由於我這個專案只需要掃描CSharp指令碼,所以只做了CSharp的掃描批處理,如果需要掃描其它語言,可使用如下指令碼:

 @echo off
rem TscanCode web account

rem set your src file path
set srcpath="F:/test"
set cppresult=./log/cppresult.xml
set csharpresult=./log/csharpresult.xml
set luaresult=./log/luaresult.xml

./TscanCode --xml --enable=all --lua ./log %srcpath% 2>%cppresult%
./TscSharp --xml --lua ./log %srcpath% 2>%csharpresult%
./tsclua --xml --csharp ./log -fr ./log/csharp.lua.exp -fr ./log/cpp.lua.exp %srcpath% 2>%luaresult%