static-analysis

Instrumenting C/C++ codes using LLVM

此生再无相见时 提交于 2019-11-28 16:28:55
问题 I just read about the LLVM project and that it could be used to do static analysis on C/C++ codes using the analyzer Clang which the front end of LLVM. I wanted to know if it is possible to extract all the accesses to memory(variables, local as well as global) in the source code using LLVM. Is there any inbuilt library present in LLVM which I could use to extract this information. If not please suggest me how to write functions to do the same.(existing source code, reference, tutorial,

Checkstyle vs. PMD

爱⌒轻易说出口 提交于 2019-11-28 15:17:19
We are introducing static analysis tools into the build system for our Java product. We are using Maven2 so Checkstyle and PMD integration come for free. However it looks like there is a large overlap in functionality between these two tools, in terms of enforcing basic style rules. Is there a benefit from utilizing both of these? I don't want to maintain 2 tools if one will work. If we choose one, which one should we use and why? We are also planning on using FindBugs. Are there other static analysis tools we should look at? Update: Consensus seems to be that PMD is preferred over CheckStyle.

Using Contract.ForAll in Code Contracts

对着背影说爱祢 提交于 2019-11-28 11:01:22
Okay, I have yet another Code Contracts question. I have a contract on an interface method that looks like this (other methods omitted for clarity): [ContractClassFor(typeof(IUnboundTagGroup))] public abstract class ContractForIUnboundTagGroup : IUnboundTagGroup { public IUnboundTagGroup[] GetAllGroups() { Contract.Ensures(Contract.Result<IUnboundTagGroup[]>() != null); Contract.Ensures(Contract.ForAll(Contract.Result<IUnboundTagGroup[]>(), g => g != null)); return null; } } I have code consuming the interface that looks like this: public void AddRequested(IUnboundTagGroup group) { foreach

How do I enforce null checking?

試著忘記壹切 提交于 2019-11-28 09:09:45
I'm working on a large project where, even with 10s of 1000s of automated tests and 100% code coverage, we're getting a ridiculous number of errors. About 95% of errors we get are NullReferenceExceptions. Is there any way to enforce null-checking at compile time? Barring that, is there any way to automagically enforce null-checking in unit tests without having to write the tests for null cases myself? You should look into Code Contracts . The static checker is only available for the higher-end VS editions, but that's basically what you're after. There are plenty of resources online, and <plug>

How to identify a missing method (Binary Compatibility) in a JAR statically

风格不统一 提交于 2019-11-28 05:27:22
I want to verify binary compatibility between 2 JARs. Following the suggestions in this answer I used jboss tattletale but it can find only missing classes. How can I find if there are missing methods? Is it possible at all? E.g. "Depends - on" class Foo depends on Bar (like many other middle class workers) import org.overlyusedclassnames.Bar public class Foo{ public void someMethod(){ Bar tender = new Bar(); tender.getJohnnyRedLabel(); tender.getJohnnyBlueLabel(); //this method is new in the Bar class } } "Compile time" class package org.overlyusedclassnames; /** * @Since 1992 * Changes:

How can I find Python methods without return statements?

泪湿孤枕 提交于 2019-11-28 03:54:41
问题 I really like it when methods of objects, which modify the objects property, return self so that you can chain method calls. For example: boundingBox.grow(0.05).shift(x=1.3) instead of boundingBox.grow(0.05) boundingBox.shift(x=1.3) I would like to search the code of my old projects to adjust this pattern. How can I find methods which don't have a return statement? Ideally, I would like to let a program run over a folder. The program searches Python files, looks for classes, examines their

Using Pylint with Django

放肆的年华 提交于 2019-11-28 02:47:59
I would very much like to integrate pylint into the build process for my python projects, but I have run into one show-stopper: One of the error types that I find extremely useful--: E1101: *%s %r has no %r member* --constantly reports errors when using common django fields, for example: E1101:125:get_user_tags: Class 'Tag' has no 'objects' member which is caused by this code: def get_user_tags(username): """ Gets all the tags that username has used. Returns a query set. """ return Tag.objects.filter( ## This line triggers the error. tagownership__users__username__exact=username).distinct() #

What code analysis tools do you use for your Java projects? [closed]

余生长醉 提交于 2019-11-28 02:37:28
What code analysis tools do you use on your Java projects? I am interested in all kinds static code analysis tools (FindBugs, PMD, and any others) code coverage tools (Cobertura, Emma, and any others) any other instrumentation-based tools anything else, if I'm missing something If applicable, also state what build tools you use and how well these tools integrate with both your IDEs and build tools. If a tool is only available a specific way (as an IDE plugin, or, say, a build tool plugin) that information is also worth noting. Greg Mattes For static analysis tools I often use CPD, PMD ,

How can I analyze Python code to identify problematic areas?

孤人 提交于 2019-11-28 02:37:10
I have a large source repository split across multiple projects. I would like to produce a report about the health of the source code, identifying problem areas that need to be addressed. Specifically, I'd like to call out routines with a high cyclomatic complexity, identify repetition, and perhaps run some lint-like static analysis to spot suspicious (and thus likely erroneous) constructs. How might I go about constructing such a report? For measuring cyclomatic complexity, there's a nice tool available at traceback.org . The page also gives a good overview of how to interpret the results. +1

Find uncaught exceptions in C# code

最后都变了- 提交于 2019-11-28 01:11:16
问题 I'm wondering if there is a tool to find uncaught exceptions in C# using static code analysis? Basically I want to select a methodA() and want a list of all exceptions thrown by methodA() and all methods called by methodA(). I tried ReSharper + Agent Johnson and AtomineerUtils, both fail this simple task. Here's my example code: public class Rectangle { public int Width { get; set; } public int Height { get; set; } public int Area() { CheckProperties(); long x = Width * Height; if (x > 10)