SlideShare una empresa de Scribd logo
1 de 16
Static Code Analysis
(& AutoLint)
Leander Hasty <leander at 1stplayable.com>

“The more I push code through static analysis, the
more I'm amazed that computers boot at all.”
- Ryan C. Gordon (@icculus)
Static Code Analysis
Essentially, pre-runtime code checking.
Identifies:
syntax errors
likely logic / semantic errors
“code smells” and best practices violations
style violations

•
•
•
•
Benefits - Why should I care?
“The most important thing I have done as a programmer in recent
years is to aggressively pursue static code analysis. Even more
valuable than the hundreds of serious bugs I have prevented with it
is the change in mindset about the way I view software reliability and
code quality.” - John Carmack

•covers language weaknesses
o

often before the language can evolve

o

distilled experience of veteran devs

•offsets human error
•code quality
•metrics (personal & organization)
•canned expertise
Problems and Annoyances

•
•

•

verbosity
erroneous warnings (false positives), due to:
o

o

misconfiguration
 include paths
 defines
 language variants
code style

missed problems (false negatives)

“[...] if you have a large enough codebase, any class of error that is
syntactically legal probably exists there.” - Carmack
Approaches and Solutions
1. Hyperlink to “what is this” and “how to fix”.
o

Helps with learning and burndown.

1. Keep a searchable, unfiltered history.
2. Promote important messages;
hide (but don’t lose) less important ones.
o

If you must suppress, do so at narrowest level.

1. Try different lint tools.
2. Customize configuration:
per project, per platform, and per team.
3. Annotate source as needed;
“cooperate as much as possible” with lint.
A Few Examples
C/C++
Coverity ($$$$$)
Insure++ ($$$$-dyn too)
MS /analyze (free/$$$$)
PVS Studio ($$$$)
Gimpel PC-Lint ($$$)
clang /analyze (free)
Visual Assist ($$-IDE)
C#
Coverity, ReSharper,
FxCop
Obj-C
OCLint

•
•
•
•
•
•
•
•

Bash
shellcheck
Lua
metalua, lualint, luachecker, SWELL*
Perl
Perl::Critic
B::Lint
Python
pychecker, pyflakes, pylint,
pep8
...and many others...

•
•
•
•
•
Aside: Dynamic (Runtime) Checks

•
•
•
•

BoundsChecker
Insure++
IBM Rational
valgrind
o
o

•

o

cachegrind
memcheck
helgrind

MS Application
Verifier

•
•
•
•

electricfence
dmalloc
dlmalloc
glibc debug
o
o

malloc
stl

Also, VMs and
emulators!
AutoLint
AutoLint for rev 2635 of [URL]
committed by [name] at 2012-08-28 17:11:28 -0400 (Tue, 28 Aug 2012)
See [URL] for full lint results.
Overall:
Scanned at least 187 files.
Total 3412 errors. (change: -25)
By type:
37 Errors.
1595 Warnings. (change: -6)
1111 Infos. (change: -4)
669 Notes. (change: -15)
By cluster:
cluster
cluster
cluster

"const correctness": 171 (change: -8)
"missing in initializer list": 57
"uninitialized members": 3
Mailout, continued...
diff of lint-s-rev2609.txt versus lint-s-rev2635.txt
---------------------------------------------------------------------------NEW ENTRIES:
--------------srcstatesSpotlightState.cpp(693): error 534: (Warning -- Ignoring return value of function
'game::ActorModelImpl::switchState(unsigned long)' (compare with line 72, file src3dActorModelImpl.h))
srcstatesSpotlightState.cpp(886): error 534: (Warning -- Ignoring return value of function
'game::ActorModelImpl::switchState(unsigned long)' (compare with line 72, file src3dActorModelImpl.h))
srcstatesSpotlightState.cpp(997): error 732: (Info -- Loss of sign (arg. no. 3) (long to unsigned long))
srcstatesSpotlightState.cpp(640): error 732: (Info -- Loss of sign (assignment) (long to unsigned long))
srcstatesSpotlightState.h(143): error 1762: (Info -- Member function 'game::SpotlightState::isTrinaBumped(void)'
could be made const --- Eff. C++ 3rd Ed. item 3)
srcstatesSpotlightState.cpp(646): error 641: (Warning -- Converting enum 'game::DanceStates' to 'int')
srcstatesSpotlightState.cpp(886): error 641: (Warning -- Converting enum 'game::DanceStates' to 'int')
---------------------------------------------------------------------------OLD ENTRIES:
--------------srcstatesSpotlightState.cpp(733): error 788: (Info -- enum constant
'game::SpotlightState::ActorStates::State::ENDWIN' not used within defaulted switch)
srcstatesSpotlightState.cpp(323): error 534: (Warning -- Ignoring return value of function
'game::ActorModelImpl::switchState(unsigned long)' (compare with line 72, file src3dActorModelImpl.h))
[...]
AutoLint Goals

•
•
•
•
•
•
•

Have a full history for mining.
Filter and hide, don’t suppress.
Push important data.
o
o

Allow pull / query, but don’t wait for it.
Clusters to emphasize important issues.

Lint incrementally:
o
o

decrease time to report, and
provide tailored reports, covering a single commit.

Try to keep maintenance cost low.
Decouple tools - “unix philosophy”.
Very few external dependencies.
Structure
Outputs are stats, diffstats, diff, and full report.
Mail includes the full diff + diffstats header.
Components:
runner
stats
sort and dedupe
diff (scrubbed)
dep generation
ldap lookup

•
•
•
•
•
•

Additional:
Makefile
templates

•
•
External Dependencies

•

Jenkins (CI)

•

GNU make

•

GNU diff

•

o

o

o
o

kick off jobs as needed
why? complexity / code size / maintenance
why? speed and memory
(Algorithm::Diff etc didn’t cut it)

svn, find, cygwin - these are problematic:
o
o
o

parsing “svn” and “svnversion” is error-prone
File::Find is far better in Perl
cygwin increases software stack depth, crashes
Modules - a big part of “Why Perl?”

•

Template toolkit

•

IPC::Run3

o

o
o

so much less code for output generation…
subtools can return a lot of different ways
tools use stdout and stderr

•

Mail::Sendmail

•
•
•

Net::LDAP
XML / XSLT (prior versions)
...and others: Carp, English, Fcntl,
File::Temp, IO::File, Readonly, ...

o

...there’s probably a better choice here eventually...
New Platforms and Problems

• .lnt config “include” / hierarchy helps…
o
o
o

compilers
libs / SDKs
policies (site, platform, project)

•
•
•

local vs global analysis
externals / submodules = pain
“culprits”

•

manual recovery path

o

o

if the lint run hasn’t succeeded in a few revs, who
gets the mailout?
“start again here”
Future of AutoLint

•

HTML/CSS+JS and hyperlinks

•
•
•

database versus flatfile, if needed?
return to global mode
“learning” mode:

•
•
•

o

o
o

search interface, reference pane

watch this build, set yourself up based on the log
perhaps gather deps from file open activity

easier per-file / per-dir / per-lib customization
per-user mailout customization
integrate into local builds, pre-commit
Select References
•
•
•
•
•

“Static Code Analysis”, John
Carmack:http://www.altdevblogaday.com/2011/12/24/static-code-analysis/
various, Bruce Dawson:http://randomascii.wordpress.com/category/codereliability/
“Bugs Considered Harmful with Douglas Crockford”
(Hanselminutes podcast)http://www.hanselminutes.com/396/bugsconsidered-harmful-with-douglas-crockford
Gimpel PC-Lint:http://www.gimpel.com/html/index.htm
Perl::Critic:http://search.cpan.org/dist/Perl-Critic/

Questions?
Code may be available on request (we’ve given it out before, but it is a little
specific to our use-case, and the CEO likes to know about interest).

Más contenido relacionado

La actualidad más candente

The why and how of moving to php 7
The why and how of moving to php 7The why and how of moving to php 7
The why and how of moving to php 7Wim Godden
 
不深不淺,帶你認識 LLVM (Found LLVM in your life)
不深不淺,帶你認識 LLVM (Found LLVM in your life)不深不淺,帶你認識 LLVM (Found LLVM in your life)
不深不淺,帶你認識 LLVM (Found LLVM in your life)Douglas Chen
 
Top five reasons why every DV engineer will love the latest systemverilog 201...
Top five reasons why every DV engineer will love the latest systemverilog 201...Top five reasons why every DV engineer will love the latest systemverilog 201...
Top five reasons why every DV engineer will love the latest systemverilog 201...Srinivasan Venkataramanan
 
08 - Return Oriented Programming, the chosen one
08 - Return Oriented Programming, the chosen one08 - Return Oriented Programming, the chosen one
08 - Return Oriented Programming, the chosen oneAlexandre Moneger
 
[COSCUP 2020] How to use llvm frontend library-libtooling
[COSCUP 2020] How to use llvm frontend library-libtooling[COSCUP 2020] How to use llvm frontend library-libtooling
[COSCUP 2020] How to use llvm frontend library-libtoolingDouglas Chen
 
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...Kamiya Toshihiro
 
Part II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationPart II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationWei-Ren Chen
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.xWim Godden
 
Processor Verification Using Open Source Tools and the GCC Regression Test Suite
Processor Verification Using Open Source Tools and the GCC Regression Test SuiteProcessor Verification Using Open Source Tools and the GCC Regression Test Suite
Processor Verification Using Open Source Tools and the GCC Regression Test SuiteDVClub
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.xWim Godden
 
Control hijacking
Control hijackingControl hijacking
Control hijackingG Prachi
 
Course lecture - An introduction to the Return Oriented Programming
Course lecture - An introduction to the Return Oriented ProgrammingCourse lecture - An introduction to the Return Oriented Programming
Course lecture - An introduction to the Return Oriented ProgrammingJonathan Salwan
 
Presentation buffer overflow attacks and theircountermeasures
Presentation buffer overflow attacks and theircountermeasuresPresentation buffer overflow attacks and theircountermeasures
Presentation buffer overflow attacks and theircountermeasurestharindunew
 
GCC Compiler as a Performance Testing tool for C programs
GCC Compiler as a Performance Testing tool for C programsGCC Compiler as a Performance Testing tool for C programs
GCC Compiler as a Performance Testing tool for C programsDaniel Ilunga
 

La actualidad más candente (20)

The why and how of moving to php 7
The why and how of moving to php 7The why and how of moving to php 7
The why and how of moving to php 7
 
不深不淺,帶你認識 LLVM (Found LLVM in your life)
不深不淺,帶你認識 LLVM (Found LLVM in your life)不深不淺,帶你認識 LLVM (Found LLVM in your life)
不深不淺,帶你認識 LLVM (Found LLVM in your life)
 
Top five reasons why every DV engineer will love the latest systemverilog 201...
Top five reasons why every DV engineer will love the latest systemverilog 201...Top five reasons why every DV engineer will love the latest systemverilog 201...
Top five reasons why every DV engineer will love the latest systemverilog 201...
 
08 - Return Oriented Programming, the chosen one
08 - Return Oriented Programming, the chosen one08 - Return Oriented Programming, the chosen one
08 - Return Oriented Programming, the chosen one
 
[COSCUP 2020] How to use llvm frontend library-libtooling
[COSCUP 2020] How to use llvm frontend library-libtooling[COSCUP 2020] How to use llvm frontend library-libtooling
[COSCUP 2020] How to use llvm frontend library-libtooling
 
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
 
Return oriented programming (ROP)
Return oriented programming (ROP)Return oriented programming (ROP)
Return oriented programming (ROP)
 
Part II: LLVM Intermediate Representation
Part II: LLVM Intermediate RepresentationPart II: LLVM Intermediate Representation
Part II: LLVM Intermediate Representation
 
Syntutic
SyntuticSyntutic
Syntutic
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.x
 
Symbolic Execution And KLEE
Symbolic Execution And KLEESymbolic Execution And KLEE
Symbolic Execution And KLEE
 
Android antipatterns
Android antipatternsAndroid antipatterns
Android antipatterns
 
Processor Verification Using Open Source Tools and the GCC Regression Test Suite
Processor Verification Using Open Source Tools and the GCC Regression Test SuiteProcessor Verification Using Open Source Tools and the GCC Regression Test Suite
Processor Verification Using Open Source Tools and the GCC Regression Test Suite
 
GCC
GCCGCC
GCC
 
The why and how of moving to php 7.x
The why and how of moving to php 7.xThe why and how of moving to php 7.x
The why and how of moving to php 7.x
 
Eval4j @ JVMLS 2014
Eval4j @ JVMLS 2014Eval4j @ JVMLS 2014
Eval4j @ JVMLS 2014
 
Control hijacking
Control hijackingControl hijacking
Control hijacking
 
Course lecture - An introduction to the Return Oriented Programming
Course lecture - An introduction to the Return Oriented ProgrammingCourse lecture - An introduction to the Return Oriented Programming
Course lecture - An introduction to the Return Oriented Programming
 
Presentation buffer overflow attacks and theircountermeasures
Presentation buffer overflow attacks and theircountermeasuresPresentation buffer overflow attacks and theircountermeasures
Presentation buffer overflow attacks and theircountermeasures
 
GCC Compiler as a Performance Testing tool for C programs
GCC Compiler as a Performance Testing tool for C programsGCC Compiler as a Performance Testing tool for C programs
GCC Compiler as a Performance Testing tool for C programs
 

Destacado

CppCheck - Static code analysis tool
CppCheck - Static code analysis toolCppCheck - Static code analysis tool
CppCheck - Static code analysis toolAvneet Kaur
 
Static Analysis and the FDA Guidance for Medical Device Software
Static Analysis and the FDA Guidance for Medical Device SoftwareStatic Analysis and the FDA Guidance for Medical Device Software
Static Analysis and the FDA Guidance for Medical Device SoftwareErika Barron
 
Static Code Analysis
Static Code AnalysisStatic Code Analysis
Static Code AnalysisAnnyce Davis
 
Verification at scale: Fitting static code analysis into continuous integration
Verification at scale: Fitting static code analysis into continuous integrationVerification at scale: Fitting static code analysis into continuous integration
Verification at scale: Fitting static code analysis into continuous integrationRogue Wave Software
 
Александр Сомов "C++: препроцессор, компилятор, компоновщик"
Александр Сомов "C++: препроцессор, компилятор, компоновщик"Александр Сомов "C++: препроцессор, компилятор, компоновщик"
Александр Сомов "C++: препроцессор, компилятор, компоновщик"Yandex
 
The Art of Writing Efficient Software
The Art of Writing Efficient SoftwareThe Art of Writing Efficient Software
The Art of Writing Efficient SoftwareRalf Holly
 
PVS-Studio and static code analysis technique
PVS-Studio and static code analysis techniquePVS-Studio and static code analysis technique
PVS-Studio and static code analysis techniqueAndrey Karpov
 
Static Analysis Techniques For Testing Application Security - Houston Tech Fest
Static Analysis Techniques For Testing Application Security - Houston Tech FestStatic Analysis Techniques For Testing Application Security - Houston Tech Fest
Static Analysis Techniques For Testing Application Security - Houston Tech FestDenim Group
 

Destacado (9)

CppCheck - Static code analysis tool
CppCheck - Static code analysis toolCppCheck - Static code analysis tool
CppCheck - Static code analysis tool
 
Static Analysis and the FDA Guidance for Medical Device Software
Static Analysis and the FDA Guidance for Medical Device SoftwareStatic Analysis and the FDA Guidance for Medical Device Software
Static Analysis and the FDA Guidance for Medical Device Software
 
Static Code Analysis
Static Code AnalysisStatic Code Analysis
Static Code Analysis
 
Verification at scale: Fitting static code analysis into continuous integration
Verification at scale: Fitting static code analysis into continuous integrationVerification at scale: Fitting static code analysis into continuous integration
Verification at scale: Fitting static code analysis into continuous integration
 
Александр Сомов "C++: препроцессор, компилятор, компоновщик"
Александр Сомов "C++: препроцессор, компилятор, компоновщик"Александр Сомов "C++: препроцессор, компилятор, компоновщик"
Александр Сомов "C++: препроцессор, компилятор, компоновщик"
 
The Art of Writing Efficient Software
The Art of Writing Efficient SoftwareThe Art of Writing Efficient Software
The Art of Writing Efficient Software
 
Static code analysis
Static code analysisStatic code analysis
Static code analysis
 
PVS-Studio and static code analysis technique
PVS-Studio and static code analysis techniquePVS-Studio and static code analysis technique
PVS-Studio and static code analysis technique
 
Static Analysis Techniques For Testing Application Security - Houston Tech Fest
Static Analysis Techniques For Testing Application Security - Houston Tech FestStatic Analysis Techniques For Testing Application Security - Houston Tech Fest
Static Analysis Techniques For Testing Application Security - Houston Tech Fest
 

Similar a Static Code Analysis and AutoLint

Code Review with Sonar
Code Review with SonarCode Review with Sonar
Code Review with SonarMax Kleiner
 
Code Quality - Security
Code Quality - SecurityCode Quality - Security
Code Quality - Securitysedukull
 
Metaprogramming by brandon
Metaprogramming by brandonMetaprogramming by brandon
Metaprogramming by brandonMaslowB
 
Thick Application Penetration Testing - A Crash Course
Thick Application Penetration Testing - A Crash CourseThick Application Penetration Testing - A Crash Course
Thick Application Penetration Testing - A Crash CourseNetSPI
 
Thick Application Penetration Testing: Crash Course
Thick Application Penetration Testing: Crash CourseThick Application Penetration Testing: Crash Course
Thick Application Penetration Testing: Crash CourseScott Sutherland
 
Lessons learned while building Omroep.nl
Lessons learned while building Omroep.nlLessons learned while building Omroep.nl
Lessons learned while building Omroep.nlbartzon
 
Lessons learned while building Omroep.nl
Lessons learned while building Omroep.nlLessons learned while building Omroep.nl
Lessons learned while building Omroep.nltieleman
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Henry S
 
"Hands Off! Best Practices for Code Hand Offs"
"Hands Off!  Best Practices for Code Hand Offs""Hands Off!  Best Practices for Code Hand Offs"
"Hands Off! Best Practices for Code Hand Offs"Naomi Dushay
 
What’s eating python performance
What’s eating python performanceWhat’s eating python performance
What’s eating python performancePiotr Przymus
 
Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...
Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...
Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...gree_tech
 
PAC 2019 virtual Christoph NEUMÜLLER
PAC 2019 virtual Christoph NEUMÜLLERPAC 2019 virtual Christoph NEUMÜLLER
PAC 2019 virtual Christoph NEUMÜLLERNeotys
 
Discovering Vulnerabilities For Fun and Profit
Discovering Vulnerabilities For Fun and ProfitDiscovering Vulnerabilities For Fun and Profit
Discovering Vulnerabilities For Fun and ProfitAbhisek Datta
 
OnAndroidConf 2013: Accelerating the Android Platform Build
OnAndroidConf 2013: Accelerating the Android Platform BuildOnAndroidConf 2013: Accelerating the Android Platform Build
OnAndroidConf 2013: Accelerating the Android Platform BuildDavid Rosen
 
An Introduction to Microservices
An Introduction to MicroservicesAn Introduction to Microservices
An Introduction to MicroservicesAd van der Veer
 
Code quality par Simone Civetta
Code quality par Simone CivettaCode quality par Simone Civetta
Code quality par Simone CivettaCocoaHeads France
 
Ship code like a keptn
Ship code like a keptnShip code like a keptn
Ship code like a keptnRob Jahn
 
Security research over Windows #defcon china
Security research over Windows #defcon chinaSecurity research over Windows #defcon china
Security research over Windows #defcon chinaPeter Hlavaty
 

Similar a Static Code Analysis and AutoLint (20)

Code Review with Sonar
Code Review with SonarCode Review with Sonar
Code Review with Sonar
 
Code Quality - Security
Code Quality - SecurityCode Quality - Security
Code Quality - Security
 
Metaprogramming by brandon
Metaprogramming by brandonMetaprogramming by brandon
Metaprogramming by brandon
 
Thick Application Penetration Testing - A Crash Course
Thick Application Penetration Testing - A Crash CourseThick Application Penetration Testing - A Crash Course
Thick Application Penetration Testing - A Crash Course
 
Thick Application Penetration Testing: Crash Course
Thick Application Penetration Testing: Crash CourseThick Application Penetration Testing: Crash Course
Thick Application Penetration Testing: Crash Course
 
Lessons learned while building Omroep.nl
Lessons learned while building Omroep.nlLessons learned while building Omroep.nl
Lessons learned while building Omroep.nl
 
Lessons learned while building Omroep.nl
Lessons learned while building Omroep.nlLessons learned while building Omroep.nl
Lessons learned while building Omroep.nl
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1
 
Effective C++
Effective C++Effective C++
Effective C++
 
"Hands Off! Best Practices for Code Hand Offs"
"Hands Off!  Best Practices for Code Hand Offs""Hands Off!  Best Practices for Code Hand Offs"
"Hands Off! Best Practices for Code Hand Offs"
 
What’s eating python performance
What’s eating python performanceWhat’s eating python performance
What’s eating python performance
 
Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...
Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...
Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...
 
Unix commands
Unix commandsUnix commands
Unix commands
 
PAC 2019 virtual Christoph NEUMÜLLER
PAC 2019 virtual Christoph NEUMÜLLERPAC 2019 virtual Christoph NEUMÜLLER
PAC 2019 virtual Christoph NEUMÜLLER
 
Discovering Vulnerabilities For Fun and Profit
Discovering Vulnerabilities For Fun and ProfitDiscovering Vulnerabilities For Fun and Profit
Discovering Vulnerabilities For Fun and Profit
 
OnAndroidConf 2013: Accelerating the Android Platform Build
OnAndroidConf 2013: Accelerating the Android Platform BuildOnAndroidConf 2013: Accelerating the Android Platform Build
OnAndroidConf 2013: Accelerating the Android Platform Build
 
An Introduction to Microservices
An Introduction to MicroservicesAn Introduction to Microservices
An Introduction to Microservices
 
Code quality par Simone Civetta
Code quality par Simone CivettaCode quality par Simone Civetta
Code quality par Simone Civetta
 
Ship code like a keptn
Ship code like a keptnShip code like a keptn
Ship code like a keptn
 
Security research over Windows #defcon china
Security research over Windows #defcon chinaSecurity research over Windows #defcon china
Security research over Windows #defcon china
 

Último

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Último (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Static Code Analysis and AutoLint

  • 1. Static Code Analysis (& AutoLint) Leander Hasty <leander at 1stplayable.com> “The more I push code through static analysis, the more I'm amazed that computers boot at all.” - Ryan C. Gordon (@icculus)
  • 2. Static Code Analysis Essentially, pre-runtime code checking. Identifies: syntax errors likely logic / semantic errors “code smells” and best practices violations style violations • • • •
  • 3. Benefits - Why should I care? “The most important thing I have done as a programmer in recent years is to aggressively pursue static code analysis. Even more valuable than the hundreds of serious bugs I have prevented with it is the change in mindset about the way I view software reliability and code quality.” - John Carmack •covers language weaknesses o often before the language can evolve o distilled experience of veteran devs •offsets human error •code quality •metrics (personal & organization) •canned expertise
  • 4. Problems and Annoyances • • • verbosity erroneous warnings (false positives), due to: o o misconfiguration  include paths  defines  language variants code style missed problems (false negatives) “[...] if you have a large enough codebase, any class of error that is syntactically legal probably exists there.” - Carmack
  • 5. Approaches and Solutions 1. Hyperlink to “what is this” and “how to fix”. o Helps with learning and burndown. 1. Keep a searchable, unfiltered history. 2. Promote important messages; hide (but don’t lose) less important ones. o If you must suppress, do so at narrowest level. 1. Try different lint tools. 2. Customize configuration: per project, per platform, and per team. 3. Annotate source as needed; “cooperate as much as possible” with lint.
  • 6. A Few Examples C/C++ Coverity ($$$$$) Insure++ ($$$$-dyn too) MS /analyze (free/$$$$) PVS Studio ($$$$) Gimpel PC-Lint ($$$) clang /analyze (free) Visual Assist ($$-IDE) C# Coverity, ReSharper, FxCop Obj-C OCLint • • • • • • • • Bash shellcheck Lua metalua, lualint, luachecker, SWELL* Perl Perl::Critic B::Lint Python pychecker, pyflakes, pylint, pep8 ...and many others... • • • • •
  • 7. Aside: Dynamic (Runtime) Checks • • • • BoundsChecker Insure++ IBM Rational valgrind o o • o cachegrind memcheck helgrind MS Application Verifier • • • • electricfence dmalloc dlmalloc glibc debug o o malloc stl Also, VMs and emulators!
  • 8. AutoLint AutoLint for rev 2635 of [URL] committed by [name] at 2012-08-28 17:11:28 -0400 (Tue, 28 Aug 2012) See [URL] for full lint results. Overall: Scanned at least 187 files. Total 3412 errors. (change: -25) By type: 37 Errors. 1595 Warnings. (change: -6) 1111 Infos. (change: -4) 669 Notes. (change: -15) By cluster: cluster cluster cluster "const correctness": 171 (change: -8) "missing in initializer list": 57 "uninitialized members": 3
  • 9. Mailout, continued... diff of lint-s-rev2609.txt versus lint-s-rev2635.txt ---------------------------------------------------------------------------NEW ENTRIES: --------------srcstatesSpotlightState.cpp(693): error 534: (Warning -- Ignoring return value of function 'game::ActorModelImpl::switchState(unsigned long)' (compare with line 72, file src3dActorModelImpl.h)) srcstatesSpotlightState.cpp(886): error 534: (Warning -- Ignoring return value of function 'game::ActorModelImpl::switchState(unsigned long)' (compare with line 72, file src3dActorModelImpl.h)) srcstatesSpotlightState.cpp(997): error 732: (Info -- Loss of sign (arg. no. 3) (long to unsigned long)) srcstatesSpotlightState.cpp(640): error 732: (Info -- Loss of sign (assignment) (long to unsigned long)) srcstatesSpotlightState.h(143): error 1762: (Info -- Member function 'game::SpotlightState::isTrinaBumped(void)' could be made const --- Eff. C++ 3rd Ed. item 3) srcstatesSpotlightState.cpp(646): error 641: (Warning -- Converting enum 'game::DanceStates' to 'int') srcstatesSpotlightState.cpp(886): error 641: (Warning -- Converting enum 'game::DanceStates' to 'int') ---------------------------------------------------------------------------OLD ENTRIES: --------------srcstatesSpotlightState.cpp(733): error 788: (Info -- enum constant 'game::SpotlightState::ActorStates::State::ENDWIN' not used within defaulted switch) srcstatesSpotlightState.cpp(323): error 534: (Warning -- Ignoring return value of function 'game::ActorModelImpl::switchState(unsigned long)' (compare with line 72, file src3dActorModelImpl.h)) [...]
  • 10. AutoLint Goals • • • • • • • Have a full history for mining. Filter and hide, don’t suppress. Push important data. o o Allow pull / query, but don’t wait for it. Clusters to emphasize important issues. Lint incrementally: o o decrease time to report, and provide tailored reports, covering a single commit. Try to keep maintenance cost low. Decouple tools - “unix philosophy”. Very few external dependencies.
  • 11. Structure Outputs are stats, diffstats, diff, and full report. Mail includes the full diff + diffstats header. Components: runner stats sort and dedupe diff (scrubbed) dep generation ldap lookup • • • • • • Additional: Makefile templates • •
  • 12. External Dependencies • Jenkins (CI) • GNU make • GNU diff • o o o o kick off jobs as needed why? complexity / code size / maintenance why? speed and memory (Algorithm::Diff etc didn’t cut it) svn, find, cygwin - these are problematic: o o o parsing “svn” and “svnversion” is error-prone File::Find is far better in Perl cygwin increases software stack depth, crashes
  • 13. Modules - a big part of “Why Perl?” • Template toolkit • IPC::Run3 o o o so much less code for output generation… subtools can return a lot of different ways tools use stdout and stderr • Mail::Sendmail • • • Net::LDAP XML / XSLT (prior versions) ...and others: Carp, English, Fcntl, File::Temp, IO::File, Readonly, ... o ...there’s probably a better choice here eventually...
  • 14. New Platforms and Problems • .lnt config “include” / hierarchy helps… o o o compilers libs / SDKs policies (site, platform, project) • • • local vs global analysis externals / submodules = pain “culprits” • manual recovery path o o if the lint run hasn’t succeeded in a few revs, who gets the mailout? “start again here”
  • 15. Future of AutoLint • HTML/CSS+JS and hyperlinks • • • database versus flatfile, if needed? return to global mode “learning” mode: • • • o o o search interface, reference pane watch this build, set yourself up based on the log perhaps gather deps from file open activity easier per-file / per-dir / per-lib customization per-user mailout customization integrate into local builds, pre-commit
  • 16. Select References • • • • • “Static Code Analysis”, John Carmack:http://www.altdevblogaday.com/2011/12/24/static-code-analysis/ various, Bruce Dawson:http://randomascii.wordpress.com/category/codereliability/ “Bugs Considered Harmful with Douglas Crockford” (Hanselminutes podcast)http://www.hanselminutes.com/396/bugsconsidered-harmful-with-douglas-crockford Gimpel PC-Lint:http://www.gimpel.com/html/index.htm Perl::Critic:http://search.cpan.org/dist/Perl-Critic/ Questions? Code may be available on request (we’ve given it out before, but it is a little specific to our use-case, and the CEO likes to know about interest).

Notas del editor

  1. Hello -- I’m Leander. I’ve worn a few hats for the last 8 years at 1st Playable Productions, a videogame developer around the corner. Previously I’ve been at Electronic Arts Los Angeles and Taldren in Costa Mesa. (Feel free to interrupt with questions as we go. I usually only bring talking points, but decided to script this out, so this format is a bit new to me; please excuse any rough edges.) We’ll start with a little bit on static code analysis in general, then dive into a perl tool I keep finding myself resurrecting for various projects and workplaces. Most of my static code analysis experience has been on largeish C-language-family codebases, but the bulk of this should be applicable to other languages and different project sizes. The quote here is from a fellow who ports a huge number of games to Linux. He’s a driving force behind the Simple DirectMedia Layer (SDL), which is a huge part of Valve’s linux efforts and hence the SteamBox launch, among other things.
  2. Static code analysis can appear as a standalone tool, or as part of the compiler or interpreter. (I’ll just say “compiler” from here out.) It can work on raw source code or machine code, and any level in-between -- for example, preprocessed source or IL. Even syntax highlighting and “IntelliSense” style systems in IDEs and editors can -- and perhaps should -- be viewed as a form of static code analysis. Many compilers are pulling in more SCA-style features over time, either directly as warnings, or indirectly in the form of plugin support of separate passes. Supporting this type of use case was a major force behind the development of LLVM and clang, from what I understand. Two points worth bringing up here: You’d expect the compiler to catch syntax errors, but not all of them do! Some will let flaky syntax pass, which can be a portability concern. It’s nice to have someone saying “the syntax is nonstandard, I do not think that means what you think it means” occasionally as well. Some of these systems can enforce custom rules, like local coding standards, if you choose.
  3. John Carmack, of id Software fame, wrote a detailed and eloquent article on static code analysis in general. It’s worth a read; there’s a link at the end. He covers many of these points in more detail. (As an aside, Carmack has left id Software, and is working with Oculus; if you haven’t played with an Oculus Rift VR development kit yet, you should seek out a demo.) Carmack makes a great point re code quality: at the end of the day, it’s less important than value. Both are nebulous terms, but I don’t think anyone here would disagree that code quality has an awful lot to do with value over the long run: it has a direct impact on maintenance costs, defect rates, and the like. Metrics may or may not be 100% accurate, but tracking something is the first step toward improvement. See CMU SEI’s Capability and Maturity Model and the Personal Software Process. I can’t emphasize the expertise part enough. It’s like having the brains of 10+year veteran developers in jars nearby. (Admittedly very chatty and slightly neurotic brains, but it’ll do.) Having the system around talking to you accelerates learning. I’ve heard many coops, interns, and coworkers praise it for these reasons. Regarding the chattiness: more verbose systems will sometimes generate spontaneous discussions. While these do occasionally devolve into bikeshedding, the majority of them have been beneficial; they seem to help the group become more introspective over time. As a side effect, someone occasionally creates an incredibly useful bit of code that makes it easier to avoid angering the Lint Gods.
  4. When we first started analysis at my latest job, on a ~300k-500k LOC codebase, we had over 120 megabytes of text output from PC-Lint. Ouch. (Carmack uses the phrase “reams of commentary” here.) A lot of the noise and false positives come down to fixing configuration issues -- things like include search paths, making sure all compiler-internal defines are known to the lint process, and importing defines from a platform-specific build process. Some types of lint can automatically configure themselves -- if they’re built into the compiler, they can often be turned on just by flipping a switch. Others are more manual, but sometimes make up for it in flexibility. “Your Mileage May Vary” per tool. False negatives tend to decrease over time as compilers and linters get smarter. Or you may be able to detect them with some configuration changes or source code annotation.
  5. Some of these aren’t as much of a problem for smaller projects or smaller teams. Regarding hyperlinks, having a reference nearby allows people to learn and turn around fixes a lot more quickly, especially if they’re new to lint. HTML+JavaScript can help here -- a description pane or popup or the like. This goes a long way to encourage spontaneous strafing runs at the issue list. Keeping the results of all prior runs is key. Even if you’re keeping these results mostly hidden, you enable many useful tricks. Being able to search through history after you fix a tough bug is amazing: you may find the five other instances of the bug lurking elsewhere in the codebase immediately. (I can’t count how many times I’ve done this.) That history can also be used for fun things like automatic #include / dependency reduction tools. Once the data is there, you’re only really limited by imagination. What’s “important” to draw attention to will vary per organization and per codebase. Find some way to emphasize that stuff, and ideally allow highlight rules to be changed easily over time. We’ll talk about AutoLint’s approach in a bit. Sometimes it is time to bite the bullet and suppress a message outright. Try to keep this obvious, and scoped as narrowly as possible: line of code, scope, or module… Plan on revisiting this list once or twice a year. Don’t give up if you have bad experiences with one tool. There are others, and they vary a lot. For example clang /analyze versus PC-Lint: the former may report on 2-3 issues in one of our games, the latter is still producing ~12 megabytes of text. But, hey: text is compressible! Annotations can get messy, but applied judiciously I think they’re a great thing. Sometimes minor refactoring can help both readability and lint; the “cooperate” quote there is from Carmack’s article.
  6. This is by no means a complete list. Groupings and ordering are not significant. Each of these do vary considerably in their “feel” and verbosity, as well as how they’re configured. Carmack discusses Coverity, MS /analyze, PVS Studio, and PC-Lint in his article. When creating this slide, I nearly forgot SWELL (which stands for SWELL Will Examine Lua Listings, in the great tradition of GNU and such acronyms). It is an internal tool that just uses Perl to parse the output of “luac -l”, which dumps a bytecode listing. It reports typos and other undeclared variable usage, after comparing against a whitelist. It’s a great example of an extremely tiny lint tool, and would never have been created if I hadn’t been influenced by prior tools.
  7. Just a quick divergence: if you haven’t tried runtime checking, you should! Of these, I can highly recommend valgrind (free) if you can use it; Application Verifier is also free and has been immensely useful in debugging Windows toolchain issues. The glibc debug switches (or equivalent for proprietary compilers) are worth turning on for at least one build of a project… Also, I still long for the days when we developed GameBoyAdvance games under VirtualBoyAdvance. Some of the nicest debugging and visualization tools out there in an ostensibly-for-homebrew-development project.
  8. AutoLint is a set of Perl programs and tools that runs lint incrementally, once per checkin, and mails out the results. You’re seeing a snapshot of a mailout generated by the system. A prior version was a prettier and better organized XHTML+JavaScript page, but I haven’t resurrected that yet. A few things to point out: Summary statistics are right up front. “Clusters” denote categories of error we found important -- things that “just won’t die” and keep coming back to plague us. More on the next slide...
  9. You can see some of PC-Lint’s verbosity here. Nevertheless, for a fairly significant commit, there are only ~7 new issues here. Most of these are probably OK, but could use double-checking. Some could disappear with minor style changes. Chances are most of this report will be ignored, but if it was a new file the author might tackle them a little more aggressively. This example doesn’t have anything seriously scary -- for example, “use after free” or “use uninitialized” -- but some do =)
  10. AutoLint filters the mail pretty heavily, deduping, dropping some issues, hiding things you’ve seen before, etc. They’re still there if needed in the full report. We push results to users ASAP; less time between commit and report is best. They can go pull full reports (per-module or overall), but the push is the first layer. We explicitly don’t make this optional; people forget to go looking in a pull model very quickly. The “Clusters” are lists of message numbers that we consider important, based mostly on painful past experience. They get pulled to the top of the stats and reports. Ideally we set up so it’s run automatically as a part of build, before commit; some systems are easier to do this with than others. I really like IDEs that do this sort of thing continuously in the background, which seems to be getting more feasible these days. We’re still getting there on the “low maintenance” front, but it’s not too bad once it has been established for a given platform and iterated on a bit. Let’s dive into the structure and dependencies a bit...
  11. All the “components” are perl, with some few supporting outside tools where appropriate. The runner coordinates everything, and is sort of the “main loop”, dealing with source control, calling the other modules as needed, actually running lint (currently via make which handles incremental lint a lot better; lint can produce .lob files or lint objects, making it very amenable to traditional incremental build tools). It also does user lookup and final mailout. Stats builds a few hash tables with counts: overall, per file, per error type, etc. Sort and dedupe pulls the error list down in size a bit; we get a lot of duplicates from local lint (and even some in global). No sense in reporting the same error on the same line more than once. This is all just little regexes and such. Diff is a bit special: we cheat to avoid noise from line number changes. Strip out anything that looks like a line number, diff using GNU diff (much faster than anything internal), then parse the diff and re-inject the line numbers. We don’t get it wrong often, and when we do we’re only off by lines in a file, rather than a whole file. (We do force PC-Lint to cooperate a bit by putting it in one-error-per-line mode, coincidentally in Visual Studio error message format. XML mode would also probably have been possible.) Dep generation just parses prior lint reports to give us a gcc -MD or -MMD style depfile, so make can do its job incrementally. Ldap lookup just converts svn usernames to mail addresses for us. Finally, we have Template::Toolkit templates for stats and mailout. In case you’re curious, line counts (approximate). This stuff is all pretty verbose and relatively high comment density. runner = 575 stats = 200 sort and dedupe = 35 (yay perl) diff (scrubbed) = 220 dep gen = 75 ldap = 30 Makefile = 110 templates = 40 (stats) and 30 (mail)
  12. Jenkins is great. It suffers a little from feature bloat and longstanding bugs (they need lint, hah), but it is greatly preferred to rolling your own. Eventually it might be able to take over mailout duties, and we could drop the LDAP requirement and just generate logs. It’s just not that great about single-rev-at-a-time bumps. For “build incrementally with deps”, make is very terse. All of this stuff works fairly well as a traditional Directed Acyclic Graph: lobs and logs from lint, deps from logs, combined log, sorted log, diffs, stats, diffstats... We use GNU diff because the perl diff solutions were just too slow and too memory intensive. It’s not that much trouble working with tempfiles and command-line diff, and it’s _much_ faster; also more amenable to parallelization via make -j. It’s a no-brainer to move to direct SVN API use, but the last time we tried was back in SVN 1.5 or earlier, and extern management was abysmal. There was a similar reason for falling back to GNU find, but that is just laziness; File::Find can do this easily, we just have to be careful about depth-first traversal. Cygwin is a love/hate relationship for me. It’s so nice to have the unix environment around, but for tools that need to be stable, it makes much more sense to use gnuwin32 or the like. cygwin just seems to trade one race condition for another, and it’s really easy to trigger these when you’re constantly running parallel makes. msys or GnuWin32 might be a better choice...
  13. I so love template toolkit… There are a few other similar packages out there, but TT has fit our needs. Even with the larger XHTML frontend. There was a tiny cygwin run0 bug that needed to be worked around even with IPC::Run3.
  14. PC-Lint has a lot of existing .lnt files for various compilers, libraries, and even policies (a whole “Scott Meyers” set corresponding to the Effective C++ series, for example, and another for MISRA). When we are missing something (e.g. Metrowerks) we can do a pretty good job of scraping together just the missing .lnt file. It does take a little iteration to get right, but isn’t too terrible. Many of the lint programs can operate in an all-seeing “global” mode which attempts to see everything across all modules at once (and sometimes crashes or runs very slowly). If global is too slow or breaks, consider local per-module runs; conversely, if local is too noisy global may work. With AutoLint’s dedupe the local output is not too different from global, we just miss some useful “unused symbol” warnings -- they get very spammy. If you have externals, be prepared for a little pain re people who e.g. check into project before checking in to external. We have a little logic for fudging timestamps around, or just ignoring a particularly bad run if it looks like the next run might fix it. (Although “culprits” gets a bit hard in that case; we’d like to mail only you with your messages, not two of you with both your messages…) There are “best practice” solutions for this on the source control system side, but we don’t always have the luxury of being able to implement those, especially when working with clients. It’s very nice if this is as low maintenance as possible, but there also has to be a way to say “this all went to hell; start again from scratch as of this new rev” easily. Honestly: the new platform does take a while to spin up. We haven’t had this stuff running since DS development (ouch), despite the new platforms arguably being _easier_ to set up (gcc/clang based). I’d estimate a solid day or two of setup for this tool at the moment, for a new platform, then 1-2 weeks of hand-holding of an hour or so each day. I’m confident we can get these numbers down with iteration...
  15. While having the text versions around is great (and nicely composable), having a nicer-looking frontend with color is very helpful. Easier to draw the eye to relevant info, and much easier to hyperlink off to “howto”s. A DB might provide more functionality, over time. Flatfiles are working pretty well at the moment, though. As touched on in the last slide: new platform setup costs are too high. Something that can learn from build logs would be a great step up, even if you had to sort through the autogenerated config. There’s still the issue of compiler-internal defines, but you can often coax those out. We’d like more facilities for suppressing or hiding at minimum scope. PC-Lint is actually pretty awesome at this -- wildcards for paths and symbols for specific suppressions, “scope” support for suppressions, etc. But we need to use it more, and come up with some best practices here. Ideally a user who knew what they were doing could alter some personal suppressions, which wouldn’t affect the master history but might keep them more sane; more than a few folks end up just not being able to deal with some of the verbosity.
  16. Read that first link, you won’t regret it. =) Also, Perl::Critic is a very good thing. I use it from inside Padre all the time… It took a little while to get used to, but I’m much happier with my newer code now that I’ve adapted.