code-analysis

CA1026 (all parameters should have default values) and extension methods

Premise When using code analysis (or fxCop) with C# optional parameters you can get a warning of CA1026. The short reason1 for this is not suppling all parameters with a default value. The declaration below rightly generates this warning public Color GetColor(bool red, bool blue = true, bool green = true) However there is a situatio...

Reasoning behind ArrayIsStoredDirectly rule of PMD

PMD has a rule called ArrayIsStoredDirectly in the Sun Security ruleset: Constructors and methods receiving arrays should clone objects and store the copy. This prevents that future changes from the user affect the internal functionality. Here is their example: public class Foo { private String [] x; public void foo (String [] ...

Code Analysis tool errors with "The given key was not present in the dictionary."

I get the following unhelpful error while building my .NET project when Code Analysis runs. It happens both in Visual Studio and building from the command line with MSBuild. * 1 total analysis engine exceptions. MSBUILD : error : CA0001 : The given key was not present in the dictionary. Any ideas on what is broken? Edit: Have fo...

VS2010 code analysis selecting types/namespaces

I'm working on a project and we have a huge assembly if hundreds of types. I would like to add some kind of code analysis, but only on new types. In FxCop I can chose the types and/or namespaces I want to have analyzed. I can't seem to find a way to do so in VS2010 code analysis. Is it just me or is this not possible? ...

Dereference of null pointer, but I am not using pointers

Hello, I did the "Build and analyze" in xCode and get "Dereference of null pointer" when setting a normal int to 0 in my init-method. I noted in my code below for which row I get the message. I'm developing for iPhone. Bric.m #import "Bric.h" @implementation Bric - (id)initWithImage:(UIImage *)img:(NSString*)clr{ if (self = [su...

Receiver in expresseion is a garbage value

Hello, I am developing an iPhone app and are using xCode to do "Build and analyze". I get the message "Receiver in expresseion is a garbage value" pointing to the line of the return-row in my bode below: -(UIColor*)getLevelColor{ UIColor* tempCol; if (level==4) { tempCol= [[UIColor alloc] initWithRed:0.39f green:0.82f blue:0.32f ...

Suggested thresholds for some software metrics

Hi everybody, I was searching the internet for some suggestions for thresholds for the following well-known software product metrics: Lack of Cohesion in Methods (for the Henderson-Sellers variant of the metric) Number of Inherited Methods in a Class Number of Overriden Methods in a Class Number of Newly Added Methods in a Class H...

Tools for generating Haskell function dependency (control flow) graph?

Note not "functional dependency". Are there tools available that allow me to build a static function dependency graph from source code? Something which indicates to me which functions depend on which other ones in a graphical manner. ...

Static code analysis methodology

What methodology would you use with a static code analysis tool? When and where would you run the analysis? How frequent? How would you integrate it to a continues build environment, on daily builds? only nightly? ...

What article discusses "Viewing code from 10000 feet"?

A few years ago I read an article about a neat way to analyze a large code-base. The idea was to zoom out so far that patterns of indentation and block length are all that is really visible. The author wrote about printing out code with very small fonts and looking at the results from 10 feet back. I believe the author also had some to...

Splint Code Analyzers for C

We are planning to use Splint as code analyzer for our C code base. But we never tried Splint tool before so we want your input on it's benifts, pros and cons. ...

Alternative to nested type of type Expression<Func<T>>

I have a function used when calling a service. Before it call the service, it will create a log entry: protected TResult CallService<TService, TResult>(TService service, Expression<Func<TService, TResult>> functionSelector) { Logger.LogServiceCall(service, functionSelector); return functionSelector.Compile()(service); } Th...

finding errors in a given c code

I am interested to know on what things I need to concentrate on debugging c code without a debugger. What are the things to look for? Generally I look for the following: Check whether correct value and type is being passed to a function. Look for unallocated and uninitialized variables Check for function syntax and function is used i...

How to create custom FXCop static analysis rule that checks a specific property value

Hi, I would like to use the FXCop introspection API to create a custom rule that verifies the following: in MethodA, the code sets a property B on a static class C to value D : void MethodA() { C.B=D; } what i would like is that inside override ProblemCollection Check(member m) I want to check: if m == MethodA { Assert: m assign...

.Net - Dispose correctly children object

From code analysis (Visual studio), I got this warning: Warning 2 CA2000 : Microsoft.Reliability : ... Call System.IDisposable.Dispose on object 'l' before all references to it are out of scope... So, I changed the code : Dim l As LiteralControl = New LiteralControl AddHandler l.DataBinding, AddressOf OnDataBinding container.Control...

static code analysis for assembly language

Are there any open-source tools or libraries for static code analysis of simple custom assembly-like languages (for automatically generated programs) and what are they capable of (detecting unused code/registers, giving high-level expressions for code segments, call graphs etc.)? Which algorithms do exist in this field? ...

Is it possible to verify custom code/architecture rules inside vs2010 without having a tfs server?

We have TFS. We are moving to TFS soon, but I'd like to know if it's possible to check code against a policy that is not attached to TFS. Especially, if you can do so without having a TFS server attached to VS at all. I'd like to have the policy already TFS capable, or very easily migrated. We are all on VS2010 ultimate. ...

Tell pydev to exclude an entire package from analysis?

Today I'm on a mission to remove little red X's from my django project in pydev. Mostly, this involves fixing import problems with pydev. I'm using South for database migrations. South (if you don't know) generates python modules, and pydev doesn't like them. I don't want to edit the south code since it's generated. Is there a way to...

Flex/Flash project analyzing tool wanted.

Hello everyone. I am looling for tool that can eat my Adobe Flex source code (written in Adobe Flex Builder 3.0.2, Eclipse plugin) or built SWF and produce call graph, class inheritance diagram and so on. Purpose - I've got a project with actually no time to dig in complicated calculations performed there (it's an interactive Flash game ...

How to dispose of an object that is iterated through via its Next property?

I have an object that uses some underlying native resources, and has a pointer to the next instance, which I iterate through similar to: MyObject begin = null; try { begin = GetFirst(); while (begin != null) { MyObject next = begin.Next(); // do something with begin begin.Dispose(); begin = ...