static-analysis

In C macros, should one prefer do { … } while(0,0) over do { … } while(0)?

对着背影说爱祢 提交于 2019-11-29 16:56:59
问题 A customer recently performed static analysis of my employer's C codebase and gave us the results. Among useful patches was the request to change the famous do { ... } while(0) macro to do { ... } while(0,0) . I understand what their patch is doing (using the sequence operator to return evaluate to the value of the second "0", so the effect is the same) but it's not clear why they'd favor the second form over the first form. Is there a legitimate reason why one should prefer the second form

dredge function error - R package MuMln

最后都变了- 提交于 2019-11-29 16:39:41
问题 I have to do statistical analyses on a data set. I would like to create all the possible models and to test them with the dredge function but it doesn't work. Indeed, when I type: glm1<-glm(presabs~dca1+dca2+se1+se2, family=binomial(logit)) dredge(glm1) I got this error: Erreur in dredge(glm1) : 'global.model''s 'na.action' argument is not set and options('na.action') is "na.omit" Can someone help me? 回答1: I know this has been solved, however I came across the same issue and think there is a

How to use cppcheck's inline suppression filter option for C++ code?

不想你离开。 提交于 2019-11-29 11:02:20
问题 I would like to use Cppcheck for static code analysis of my C++ code. I learned that I can suppress some kind of warnings with --inline-suppr command. However, I can't find what "suppressed_error_id" I should put in the comment: // cppcheck-suppress "suppressed_error_id" 回答1: According to the cppcheck help: The error id is the id that you want to suppress. The easiest way to get it is to use the --xml command line flag. Copy and paste the id string from the xml output. So run cppcheck against

How can I find Python methods without return statements?

十年热恋 提交于 2019-11-29 10:58:09
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 methods and searches return statements. If no return statement is there, it outputs the filename, the

Checking whether a cross-cast could possibly work?

 ̄綄美尐妖づ 提交于 2019-11-29 09:24:27
问题 I know that it's legal to use dynamic_cast to do a "cross-cast" across a class hierarchy. For example, if I have classes that look like this: A B \ / C If I have an A* pointer that's pointing at an object of type C , then I can use A* aPtr = /* ... something that produces a C* ... */ B* bPtr = dynamic_cast<B*>(aPtr); to get a pointer to the B base object of the C I'm pointing at. The reason I mention this is that at the time that I write the above code, it's possible that the compiler has not

Find uncaught exceptions in C# code

我们两清 提交于 2019-11-29 07:25:29
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) throw new ArgumentOutOfRangeException(); return (int) x; } private void CheckProperties() { if (Width <

Harmful C Source File Check?

好久不见. 提交于 2019-11-29 07:19:40
Is there a way to programmatically check if a single C source file is potentially harmful? I know that no check will yield 100% accuracy -- but am interested at least to do some basic checks that will raise a red flag if some expressions / keywords are found. Any ideas of what to look for? Note: the files I will be inspecting are relatively small in size (few 100s of lines at most), implementing numerical analysis functions that all operate in memory . No external libraries (except math.h) shall be used in the code. Also, no I/O should be used (functions will be run with in-memory arrays).

Static analysis of noexcept “violations” in C++

≡放荡痞女 提交于 2019-11-29 06:30:04
问题 I'm trying to write exception safe code. I find that using C++11's noexcept specifier makes this goal a whole lot more achievable. The general idea, of course, is that a function should be marked as 'noexcept' if, and only if all the functions that it calls are also marked as 'noexcept'. The problem is that in a large code base, where patches from different people are often merged together, it is hard to ensure that this consistency is maintained. So I would like to be able to run a static

What StyleCop like tools are there for VB.NET

不羁岁月 提交于 2019-11-29 05:28:17
see also VB.NET Static Code Anaylsis For better or for worst we now have a VB.NET coding standards document that is based on a C# coding standard as enforced by StyleCop. For example the number of spaces you should put in each side of a “+” sign etc all instance Members (fields and methods!) must be access as “me.fieldName” all shared members must be accessed as “className.fieldName” As I tend to think: If it’s in a requirements document it should be check for by an automatic system I am looking for (ideally free) tools that will check for that short of rules on VB.NET code, as these are style

Is there a static analysis tool for Python, Ruby, Sql, Cobol, Perl, and PL/SQL? [closed]

喜你入骨 提交于 2019-11-29 03:21:38
问题 I am looking for a static analysis tool for Python, Ruby, Sql, Cobol, Perl, PL/SQL, SQL similar to find bugs and check style. I am looking for calculating the line count, identify bugs during the development, and enforcing coding standard. 回答1: Perl has Perl::Critic (and perlcritic.com) 回答2: I use PyChecker and pylint as Python code checkers. However it seems that they get buggy when you use some modules (e.g., socket or pygame , IIRC). 回答3: For Ruby, you're probably best served looking at